Postgres无权创建用户

时间:2013-08-17 13:29:56

标签: ruby-on-rails postgresql

我无法使用带有postgres的rails。数据库不会创建:

sayth@sayth-TravelMate-5740G:~/testapp2$ rake db:create:all
PG::InsufficientPrivilege: ERROR:  permission denied to create database
: CREATE DATABASE "testapp2_development" ENCODING = 'unicode'
....
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"testapp2_production", "pool"=>5, "username"=>"testapp2", "password"=>nil}

所以我在这里遵循解决方案https://stackoverflow.com/a/8639649

这些是我遇到的问题。

$ psql -d postgres
postgres=# create role app_name login createdb;
postgres=# \q

但是,当我在psql shell中为createb赋予create role时,它会失败。

sayth@sayth-TravelMate-5740G:~/testapp2$ psql -d postgres
psql (9.2.4)
Type "help" for help.

postgres=> create role sayth createdb;
ERROR:  permission denied to create role
postgres=> 

如何创建身份验证?

修改更新 正在审核http://www.postgresql.org/docs/9.2/static/tutorial-createdb.htmlhttp://www.postgresql.org/docs/9.2/static/database-roles.html

但是不能使用root来创建帐户,因为它不存在,我需要root才能创建它。

sayth@sayth-TravelMate-5740G:~$ sudo psql -d postgres
[sudo] password for sayth: 
Sorry, try again.
[sudo] password for sayth: 
psql: FATAL:  role "root" does not exist

2 个答案:

答案 0 :(得分:34)

gitlab_ci DB setup期间使用此功能。我按@Audrius Meškauskas上的Ubuntu 12.04所述解决了问题:

以管理员身份

sudo -u postgres psql -d template1

改变角色

ALTER ROLE gitlab_ci WITH CREATEDB;

重新运行任务

sudo -u gitlab_ci -H bundle exec rake db:setup RAILS_ENV=production

答案 1 :(得分:7)

您使用的用户名/密码缺少创建用户和数据库所需的管理员权限。

以管理员身份登录并修复权限。如果您拥有管理员登录凭据,请登录并使用ALTER ROLE来修复该帐户的权限。