Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 315
sayth Avatar asked Aug 17 '13 13:08

sayth


People also ask

How do I fix Postgres permission denied?

Grant privileges to a new user We resolve this permission denied error using the command. GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user; The new_user was then able to read data from the table. Similarly, we can also resolve the permission denied error by setting DEFAULT privileges to the user.

Can we create user table in Postgres?

Use the CREATE TABLE statement to create a new table. Use the IF NOT EXISTS option to create the new table only if it does not exist. Apply the primary key, foreign key, not null, unique, and check constraints to columns of a table.


1 Answers

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
like image 119
Édouard Lopez Avatar answered Nov 14 '22 11:11

Édouard Lopez