psql在某些地方告诉我“数据库不存在”,在其他地方认识到它

时间:2013-09-10 15:22:42

标签: postgresql psql

我正在尝试从本教程(http://jamiecook.wordpress.com/2011/11/24/setting-up-postgresql-postgis-for-rails-on-ubuntu/

运行这些命令
sudo su - postgres
createdb -E UTF8 template_postgis # Create the template spatial database.
createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql -d osm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
cat <<EOS | psql -d template_postgis
UPDATE sample_postgis_db SET datistemplate = TRUE WHERE datname = 'template_postgis';
REVOKE ALL ON SCHEMA public FROM public;
GRANT USAGE ON SCHEMA public TO public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.geometry_columns TO PUBLIC;
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE public.spatial_ref_sys TO PUBLIC;
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON geography_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;
VACUUM FULL FREEZE;
EOS

我收到了错误:

ERROR:  relation "sample_postgis_db" does not exist
LINE 1: UPDATE sample_postgis_db SET datistemplate=TRUE WHERE datnam...

但它确实存在:

psql -d postgres
\list
#=>
...
sample_postgis_db | postgres     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
...

我可以登录:

psql -d sample_postgis_db

但即使我在db的psql中运行UPDATE行(当然是无意义的,但我认为这是一个很好的测试),仍然无法识别本身

sample_postgis_db=# UPDATE sample_postgis_db SET datistemplate=TRUE WHERE datname = "template_postgis";
ERROR:  relation "sample_postgis_db" does not exist
LINE 1: UPDATE sample_postgis_db SET datistemplate=TRUE WHERE datnam...

2 个答案:

答案 0 :(得分:1)

教程有:

UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';

你替换为:

UPDATE sample_postgis_db SET datistemplate = TRUE WHERE datname = 'template_postgis';

此替换是不必要的,因为这里更新的是系统表,而不是数据库名称。

答案 1 :(得分:0)

我讨厌这是多么神秘......也许只是因为我将sample_postgis_db的角色改为SUPERUSER(出于绝望),但它刚刚开始工作......