Postgres权限被拒绝在rake db:create:all上创建数据库
我正在尝试为开发和测试创建postgres数据库。
我正在使用…
- OSX Yosemite
- Rails版本:4.2.0
- git版本:2.2.2
- psql版本:9.4.0
- ruby版本:2.1.0p0
- HomeBrew版本:0.9.5
的Gemfile …
gem 'pg'
database.yml的
default: &default adapter: postgresql encoding: unicode pool: 5 development: <<: *default database: myapp_development username: username password: test: <<: *default database: myapp_test
rake db:create:all
返回
PG::InsufficientPrivilege: ERROR: permission denied to create database : CREATE DATABASE "myapp_development" ENCODING = 'unicode' .... (lots of tracing) Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"myapp_development", "username"=>"username", "password"=>nil} myapp_test already exists
怎么了?
编辑我只是尝试将database.yml中的用户名更改为我在Mac上使用的用户名。 有效。 它还告诉我,不仅maybe_test' already exists, but it also just told me that
myapp_development`已经存在。
- 为什么它不能使用我创建的其他用户名并为
CREATEDB
分配角色? - 为什么说不能创建开发然后告诉我它已经存在?
这一切似乎太令人困惑,让我想起了在过去的日子里使用apache进行php设置。 我不想每次创建新应用程序时都要处理问题,并且在开发期间尝试遵循heroku建议使用postgres。
运行rake db:test:prepare
时我遇到了同样的问题rake db:test:prepare
在我的Ruby on Rails项目中的postgresql
rake db:test:prepare
。 从错误消息中可以清楚地看出,这是用户的权限问题。 我从控制台添加了new_user
CREATEDB
权限。
要访问postgres控制台:
$ sudo -u postgres -i postgres@host:~$ psql
在那里:
postgres=# ALTER USER new_user CREATEDB;
它现在完美无缺。 您可能还有另一个数据库所有权问题,为此您可以按照以下命令更改数据库privileges
和owner
。
postgres=# GRANT ALL PRIVILEGES ON DATABASE database_name to new_user; postgres=# ALTER DATABASE database_name owner to new_user;
查看您的架构,您的开发和测试凭据是不同的。
也许从架构中删除用户名和密码,看到您的测试数据库确实已创建。