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
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.
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.
Add this using during gitlab_ci
DB setup. I solve the problem as described by @Audrius Meškauskas
on 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With