PostgreSQL 恢复后,我收到“关系 django_session 的权限被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2302593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After a PostgreSQL restore, I get "permission denied for relation django_session"
提问by Thierry Lam
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):
我目前正在实时服务器和本地使用 PostgreSQL 8.4.2 运行我的 Django 1.1.1 站点。当我尝试从本地机器上的实时服务器恢复我的备份之一时,在本地访问我的站点(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?
我用于pg_dump
在实时服务器上进行备份并删除我的本地数据库,然后psql dbname < infile
进行还原。有谁知道出了什么问题?
回答by copelco
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.
以同一用户(Django 连接的用户)身份连接 psql 时是否遇到相同的错误?或者您的实时站点和本地机器上是否有相同的 PostgreSQL 用户?如果没有,您应该使用-Ox(或 --no-owner)选项转储/重新加载以跳过所有权命令。
回答by Komang Suryadana
I try with all you role for user with attribute SUPERUSER. It works.
我尝试为具有 SUPERUSER 属性的用户扮演所有角色。有用。
ALTER ROLE your_role SUPERUSER;
回答by Сергей Зеленчук
1) Create dump database
1) 创建转储数据库
$ pg_dump -Fc mydb > db.dump
2) Delete database
2) 删除数据库
$ dropdb mydb
3) Recreate it from the dump
3)从转储中重新创建它
$ pg_restore -C -d postgres db.dump