Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm trying to create the database in Rails. In Postgres I see the development and test database, however, I'm getting a permissions error. I've tried to follow this link, didn't work for me.

Error: PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations : SELECT "schema_migrations".* FROM "schema_migrations"

Rails: permission denied for relation schema_migrations

default: &default   adapter: postgresql   encoding: unicode   pool: 5   host: localhost   username: root   password:  development:   <<: *default   database: svp-chicago_development 

I log into postgres and did these commands.

psql postgres CREATE USER root CREATE DATABASE svp-chicago_development GRANT ALL PRIVILEGES ON DATABASE svp-chicago_development to root ALTER DATABASE svp-chicago_development OWNER TO root 

When I do \list I see the database is there.

like image 904
khoamle Avatar asked Jul 08 '16 16:07

khoamle


2 Answers

I had same issue and I solved by adding "Superuser" to the role.

First, list users and their privileges. If you followed above commands, root user does not have "Superuser" Attributes.

postgres=# \du                                    List of roles  Role name |                         Attributes                         | Member of -----------+------------------------------------------------------------+-----------  other     | Superuser, Create role, Create DB, Replication, Bypass RLS | {}  root      |                                                            | {} 

Next, upgrade root to be a "Superuser".

postgres=# ALTER USER root WITH SUPERUSER; ALTER ROLE 

Again, list users and their privileges. Now root has "Superuser".

postgres=# \du                                List of roles  Role name |                         Attributes                         | Member of -----------+------------------------------------------------------------+-----------  other     | Superuser, Create role, Create DB, Replication, Bypass RLS | {}  root      | Superuser                                                  | {} 

Hope it helps.

like image 151
ohkts11 Avatar answered Oct 16 '22 18:10

ohkts11


I guess you missed create password for your user. Try to create password as following:

CREATE USER root WITH PASSWORD 'your_new_password'; CREATE DATABASE svp-chicago_development; GRANT ALL PRIVILEGES ON DATABASE svp-chicago_development to root; ALTER DATABASE svp-chicago_development OWNER TO root; 
like image 32
Khanh Pham Avatar answered Oct 16 '22 16:10

Khanh Pham