我无法使用带有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.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
答案 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来修复该帐户的权限。