10

I'm currently running my Django 1.1.1 site with PostgreSQL 8.4.2 both on the live server and locally. When I try to restore one of my backup from the live server on my local box, I get the following error while accessing my site locally(http://localhost:8000):

Exception Type: ProgrammingError at /
Exception Value: permission denied for relation django_session

I also get a similar error while accessing all the contents of one of my models:

$ python manage.py shell
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myapp.models import MyModel
>>> MyModel.objects.all()
...
ProgrammingError: permission denied for relation myapp_mymodel

I used pg_dump for backup on the live server and dropping my local db followed by psql dbname < infile for restore. Does anyone know what's wrong?

Thierry Lam
  • 45,304
  • 42
  • 117
  • 144

3 Answers3

13

Do you get the same error when connecting with psql as the same user (the user Django connects as)? Or do you have the same PostgreSQL users on your live site and your local machine? If not, you should dump/reload with the -Ox (or --no-owner) option to skip the ownership commands.

copelco
  • 216
  • 2
  • 6
  • 1
    I don't have the same PostgreSQL users on my live site as my local machine. I tried the dump/reload with -Ox, but now I get a different error: relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si..." Any ideas on what might be happening here? Thank you! – mkelley33 Oct 22 '11 at 18:08
  • @mkelley33: did you find out why you were getting this new error, and how to solve it? Does it have something to do with running `syncdb`? Any hint would be appreciated since I'm now in the same boat. – Hassan Baig Dec 26 '15 at 13:35
1

I try with all you role for user with attribute SUPERUSER. It works.

ALTER ROLE your_role SUPERUSER;
Komang Suryadana
  • 677
  • 1
  • 7
  • 17
0

1) Create dump database

$ pg_dump -Fc mydb > db.dump

2) Delete database

$ dropdb mydb

3) Recreate it from the dump

$ pg_restore -C -d postgres db.dump