Skip to content

Instantly share code, notes, and snippets.

@radinreth
Created October 12, 2017 16:28
Show Gist options
  • Save radinreth/f034b994259f00b2194fc7ccf135faf8 to your computer and use it in GitHub Desktop.
Save radinreth/f034b994259f00b2194fc7ccf135faf8 to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/questions/28116927/postgres-permission-denied-to-create-database-on-rake-dbcreateall
I have faced same issues when running rake db:test:prepare in postgresql on my Ruby on Rails project. This is pretty clear from the error message, that its a permission issue for the user. I added CREATEDB permission for new_user as following from the console.
To access postgres console:
$ sudo -u postgres -i
postgres@host:~$ psql
In there:
postgres=# ALTER USER new_user CREATEDB;
It's working perfect for now. You may have another issues with database ownership, for this you can change database privileges and owner as following command.
postgres=# GRANT ALL PRIVILEGES ON DATABASE database_name to new_user;
postgres=# ALTER DATABASE database_name owner to new_user;
then
sudo service postgresql restart
then
rake db:reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment