【问题标题】:Trying to get Postres and Postgis running in Rails app试图让 Postgres 和 Postgis 在 Rails 应用程序中运行
【发布时间】:2012-11-15 18:52:59
【问题描述】:

我对 Postgresql、Postgis 和 SQL 完全陌生,并且对 Rails 有一点了解。我正在尝试在本地运行现有应用程序,并且当前在运行 rake 任务以设置我的数据库时收到以下消息。

Blane-Cordess-MacBook:ajungo blanecordes$ rake postgres:create_postgis_template --trace
(in /Users/blanecordes/ajungo)
** Invoke postgres:create_postgis_template (first_time)
** Execute postgres:create_postgis_template
Enter your postgres username: blane
Password for user blane: 
psql (9.2.1, server 9.1.4)
WARNING: psql version 9.2, server version 9.1.
     Some psql features might not work.
You are now connected to database "template1" as user "blane".
psql:assets/sql/postgis_template_osx.sql:2: ERROR:  permission denied to create database
psql:assets/sql/postgis_template_osx.sql:6: ERROR:  permission denied for relation      pg_database
psql:assets/sql/postgis_template_osx.sql:7: \connect: FATAL:  database   "template_postgis" does not exist

我的 postgis_template_osx.sql 文件如下:

\c template1
CREATE DATABASE template_postgis WITH template = template1;

-- set the 'datistemplate' record in the 'pg_database' table for
-- 'template_postgis' to TRUE indicating its a template
  UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
\c template_postgis
CREATE LANGUAGE plpgsql ;
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/postgis.sql;
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/spatial_ref_sys.sql;
-- 1.5.2


-- in a production environment you may want to
-- give role based permissions, but granting all for now
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;

-- vacuum freeze: it will guarantee that all rows in the database are
-- "frozen" and will not be subject to transaction ID wraparound
-- problems.
VACUUM FREEZE;

【问题讨论】:

    标签: ruby-on-rails postgresql postgis postgresql-9.1 rails-postgresql


    【解决方案1】:

    PostgreSQL ROLE blane 没有创建数据库的权限。 ALTER blane 并添加 CREATEDB 选项或使用具有该功能的现有管理员角色。

    postgres=# ALTER ROLE blane WITH CREATEDB;
    

    【讨论】:

    • 非常感谢!您能否为我提供一个从命令行显示的示例?
    • 查看编辑。您需要以可以 CREATEROLE 的超级用户身份登录,通常是 postgres 或安装 PostgreSQL 的用户。
    • 啊,这很有帮助,谢谢。在我的 database.yml 文件中,我命名了开发数据库并指定了用户名,但是由于我无法创建数据库,所以我有点卡在从哪里开始。在我以超级用户身份进入并添加角色之前,我不需要创建数据库吗?或者有没有办法进入我的 postgres 控制台并创建这个角色,它将适用于我的所有应用程序?对不起这样的新手!
    猜你喜欢
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 2012-10-16
    相关资源
    最近更新 更多