views:

27

answers:

2

Hi everyone. I've setup a system to automatically download and store a db dump from my Heroku deployed rails app. Everything is working great but when I download the dump and restore it to my local postgres server then try and run my local app off that restored database I get this error

ActiveRecord::StatementInvalid in HomeController#index

PGError: ERROR:  permission denied for relation users : SELECT     "users".* FROM       "users"  WHERE     ("users"."id" = 1) LIMIT 1

Anyone have any suggestions on what that could be? I've checked my postgres permissions and all tables and the database itself belong to the postgres user. I've tried GRANT ALL as well with no success.

A: 

Most probably the PostgreSQL user you are using is different one that is owner of this table. I suppose you have different user on that database and on this one?

Simon
I only have one user in my postgres server setup: postgres. Do you mean that the user of the database that I'm getting the dump from has a different user? I'm not sure I'm following.
erskingardner
Are you sure that you connect to the proper database?
Simon
And what do you have in postgresql logs about this permission denied?
Simon
+1  A: 

Go through your pgdump.sql files and remove the lines after each CREATE TABLE statement that say something like:

ALTER TABLE public.users OWNER TO eqrunyvndu;

Then run your restore from that and it should work. Those lines change the owner of the tables to your heroku app's autogenerated db username, which is meaningless locally, so you can just remove them.

I'd also recommend greping for any other occurrences of that username and removing those too.

tfe
`$ grep -v "OWNER TO" pgdump.sql > pgdump-local.sql`
wuputah
Hmm, I don't have any occurances of `ALTER TABLE public.users OWNER TO eqrunyvndu;` or even a single occurance of `OWNER` in my dump file...
erskingardner
Sounds like a problem with your Postgres server setup then... You do know that `eqrunyvndu` is generated, right? It will be different for your app.
tfe