Postgres权限被拒绝在rake db:create:all上创建数据库 [英] Postgres permission denied to create database on rake db:create:all
问题描述
我正在尝试创建用于开发和测试的postgres数据库。
I am trying to create postgres databases for development and tests.
我正在使用...
- OSX优胜美地
- Rails版本:4.2.0
- git版本:2.2.2
- psql版本:9.4.0
- 红宝石版本:2.1.0p0
- HomeBrew版本:0.9.5
- OSX Yosemite
- Rails version: 4.2.0
- git version: 2.2.2
- psql version: 9.4.0
- ruby version: 2.1.0p0
- HomeBrew version: 0.9.5
Gemfile ...
Gemfile...
gem 'pg'
database.yml
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'已经存在,而且还告诉我
myapp_development`也已经存在。
EDIT
I just tried changing the username in the database.yml to my username that I'm using on my Mac. It worked. It also told me that not only maybe_test' already exists, but it also just told me that
myapp_development` already exists too.
- 为什么它不能使用我创建并为
CREATEDB分配角色的其他用户名
? - 为什么会说无法创建开发,然后告诉我它已经存在?
这一切似乎都太令人困惑了,让我想起了很早以前用apache进行的php安装。我不想每次创建一个新应用并尝试遵循heroku建议时也要在开发过程中使用postgres来解决问题。
This all seems way too confusing and reminds me of php setup with apache back in the very old days. I don't want to have to deal with problems every time I create a new app and try to follow the heroku recommendations to use postgres during development too.
推荐答案
在我的 postgresql
中运行 rake db:test:prepare
时遇到相同的问题 Ruby on Rails 项目。从错误消息中可以很清楚地看出,这是用户的权限问题。我在控制台中为 new_user
添加了 CREATEDB
权限,如下所示。
I have faced same issues when running rake db:test:prepare
in postgresql
on my Ruby on Rails project. This is pretty clear from the error message, that its a permission issue for the user. I added CREATEDB
permission for new_user
as following from the console.
要访问postgres控制台:
To access postgres console:
$ sudo -u postgres -i
postgres@host:~$ psql
其中:
postgres=# ALTER USER new_user CREATEDB;
目前,它的运行非常完美。您可能还存在数据库所有权的问题,为此,您可以按照以下命令更改数据库特权
和 owner
。
It's working perfect for now. You may have another issues with database ownership, for this you can change database privileges
and owner
as following command.
postgres=# GRANT ALL PRIVILEGES ON DATABASE database_name to new_user;
postgres=# ALTER DATABASE database_name owner to new_user;
这篇关于Postgres权限被拒绝在rake db:create:all上创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!