Postgres无权创建用户

我无法使用带有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=> 

那怎么创建auth?

编辑更新审核http://www.postgresql.org/docs/9.2/static/tutorial-createdb.html和http://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 

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

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

gitlab_ci数据库设置期间添加此项。 我在Ubuntu 12.04上解决了@Audrius Meškauskas所描述的问题:

以管理员身份连接

 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