After a PostgreSQL restore, I get "permission denied for relation django_session"
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 开发者_Go百科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?
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.
I try with all you role for user with attribute SUPERUSER. It works.
ALTER ROLE your_role SUPERUSER;
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
精彩评论