small medium large xlarge

04 Jan 2017, 10:22
Michiel Schukking (3 posts)

Postgres works on my system, but in the past I didn’t set up a user with password.

Now I get: PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations

What I did was:

createuser --createdb --login -P shine (in the terminal)


bundle exec rails db:create which seems to work, my database exists, when I do \list in psql:

shine_development              | shine       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/shine                  +
                                |             |          |             |             | shine=CTc/shine
 shine_test                     | shine       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/shine                  +
                                |             |          |             |             | shine=CTc/shine

but when I do bundle exec rails db:migrate I keep on getting:

rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied for relation schema_migrations
: SELECT "schema_migrations".* FROM "schema_migrations"

PG::InsufficientPrivilege: ERROR:  permission denied for relation schema_migrations

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

My yml looks like this:

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  username: shine
  password: shine
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

  <<: *default
  database: shine_development

I also tried the solution:

CREATE USER username WITH PASSWORD 'password';
ALTER DATABASE appname OWNER TO username;

Doesn’t make a change.

Any idea how to solve this so I can move on with the book? Thanks!

04 Jan 2017, 14:11
David Copeland (511 posts)

After the last step, did you alter your database.yml to use that new user? And did you make the changes to that user for both databases? That should be sufficient, but the createuser command is all I had to run. Granted, I’m on OS X. If you are on Linux, my understanding is that Postgres has different default configuration that makes this problem happen. There might be some posts in the first edition forum about this, too.

05 Jan 2017, 11:20
Michiel Schukking (3 posts)

That’s strange I repeated the steps in psql above for a database with the name shiner… instead of shine…, altered the database.yml, and it works. Also on Mac OS X btw. The \list in psql look roughly the same. Whatever, it works, I can proceed working, I’m happy.

05 Feb 2017, 14:34
LIN SHIH HUNG (2 posts)

I encountered the same problem as Schukking did. After I did following steps then I can continue coding . There must be something wrong in front.

$ bundle exec rake db:drop

$ rake db:create db:migrate

$ bundle exec rake

It works…YA!

05 Feb 2017, 15:12
David Copeland (511 posts)

Cool. I wonder if something went wrong initially creating the database and it got into a weird state such that you had to drop it and start over.

You must be logged in to comment