[英]Rails: Postgres permission denied to create database on rake db:create:all
I am trying to create postgres databases for development and tests.我正在尝试为开发和测试创建 postgres 数据库。 I'm using:
我正在使用:
Gemfile:宝石档案:
gem 'pg'
database.yml:数据库.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
returns 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
What is wrong?怎么了?
EDIT I just tried changing the username in the database.yml to my username that I'm using on my Mac.编辑我只是尝试将 database.yml 中的用户名更改为我在 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.它还告诉我不仅
maybe_test
已经存在,而且还告诉我myapp_development
已经存在。
CREATEDB
?CREATEDB
? This all seems way too confusing and reminds me of PHP setup with Apache back in the very old days.这一切似乎太混乱了,让我想起了过去使用 Apache 进行 PHP 设置。 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 PostgreSQL during development too.
我不想每次创建新应用程序时都必须处理问题,并尝试遵循 Heroku 建议在开发过程中使用 PostgreSQL。
I have faced same issues when running rake db:test:prepare
in postgresql
on my Ruby on Rails project.在我的Ruby on Rails项目上在
postgresql
运行rake db:test:prepare
时,我遇到了同样的问题。 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.我从控制台为
new_user
添加了CREATEDB
权限,如下所示。
To access postgres console:要访问 postgres 控制台:
$ sudo -u postgres -i
postgres@host:~$ psql
In there:在那里:
postgres=# ALTER USER new_user CREATEDB;
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.您可能有数据库所有权的另一个问题,为此您可以按照以下命令更改数据库
privileges
和owner
。
postgres=# GRANT ALL PRIVILEGES ON DATABASE database_name to new_user;
postgres=# ALTER DATABASE database_name owner to new_user;
Looking at your schema your credentials for development and test are different.查看您的架构,您的开发和测试凭据是不同的。
Perhaps remove username and password from the schema, seeing that your test database did get created.也许从架构中删除用户名和密码,看到您的测试数据库确实已创建。
create database demo;
create user demotest with password '123';
grant all privileges on database demo to demotest;
commit;
This is script for creation of database. But any existing database having password '123' then change your password for new database to password '1234'. This procedure working for me.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.