sayth
sayth

Reputation: 7048

Postgres No permission to create user

I am unable to use rails with postgres. The database wont create:

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}

So I am following the solution here https://stackoverflow.com/a/8639649

These are the steps i am having issue with.

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

However when I am in the psql shell to give the create role with createdb ability it fails auth.

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=> 

How then do I create the auth?

Edit Update Reviewing http://www.postgresql.org/docs/9.2/static/tutorial-createdb.html And http://www.postgresql.org/docs/9.2/static/database-roles.html

But cannot use root to create accounts as it doesn't exist and I need to be root to create it.

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

Upvotes: 10

Views: 24546

Answers (3)

Galuoises
Galuoises

Reputation: 3293

Open the interface with psql postgres and try creating the user now.

Upvotes: 0

Édouard Lopez
Édouard Lopez

Reputation: 43419

Add this using during gitlab_ci DB setup. I solve the problem as described by @Audrius Meškauskas on Ubuntu 12.04:

Connect as Admin

sudo -u postgres psql -d template1

Alter role

ALTER ROLE gitlab_ci WITH CREATEDB;

Re-run the task

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

Upvotes: 39

Audrius Meškauskas
Audrius Meškauskas

Reputation: 21778

The username / password you use lack the administrator rights that are necessary for creation users and databases.

Login as administrator and fix the permissions. If you have administrator login credentials, login and use ALTER ROLE to fix the rights on that account.

Upvotes: 7

Related Questions