I am trying to create a postgresql database for my rubyonrails application and I followed the following steps post installation:
sudo -u postgres -i
psql
CREATE USER rohitrp
CREATE DATABASE library_development OWNER rohitrp
CREATE DATABASE library_test OWNER rohitrp
My database.yml looks like this:
development:
adapter: postgresql
encoding: unicode
database: library_development
username: rohitrp
password:
pool: 5
timeout: 5000
test:
adapter: postgresql
encoding: unicode
database: library_test
username: rohitrp
password:
pool: 5
timeout: 5000
When I run rake db:setup I get the following error:
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "library_development" ENCODING = 'unicode'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/rohitrp/.rbenv/versions/2.2.1/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"library_development", "username"=>"rohitrp", "password"=>nil, "pool"=>5, "timeout"=>5000}
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "library_test" ENCODING = 'unicode'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/rohitrp/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/rohitrp/.rbenv/versions/2.2.1/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"library_test", "username"=>"rohitrp", "password"=>nil, "pool"=>5, "timeout"=>5000}
-- create_table("books", {:force=>:cascade})
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "library_development" does not exist
/home/rohitrp/RubymineProjects/library/db/schema.rb:16:in `block in <top (required)>'
/home/rohitrp/RubymineProjects/library/db/schema.rb:14:in `<top (required)>'
PG::ConnectionBad: FATAL: database "library_development" does not exist
/home/rohitrp/RubymineProjects/library/db/schema.rb:16:in `block in <top (required)>'
/home/rohitrp/RubymineProjects/library/db/schema.rb:14:in `<top (required)>'
Tasks: TOP => db:schema:load
(See full trace by running task with --trace)
For resolving the permission issues I followed the answer on this link Postgres permission denied to create database on rake db:create:all
I am still facing the same error.
$ psql -U postgres
postgres=# ALTER USER username CREATEDB;
I was also facing this problem when I was doing setup of my Ruby on Rails app.Then,
sudo -u postgres psql
This will make you enter into psql shell.
Once you enter your shell type:
ALTER USER username CREATEDB;
In the place of username,you have to add your default system username in most of the cases.
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