我正在尝试恢复我的Django应用程序的postgres数据转储。数据转储是从Heroku中提取的,pg_restore latest.dump -d mydb -U postgres
是在带有Linux的Azure VM上运行的。
Heroku上的用户名为uauv8b9v4
。 Azure上没有类似的用户。所以当我在Azure上运行pg_restore时,我遇到了大量的role does not exist
错误。 E.g:
pg_restore: [archiver (db)] Error from TOC entry 241; 1259 44416 TABLE links_grouptraffic uauv8b9v4
pg_restore: [archiver (db)] could not execute query: ERROR: role "uauv8b9v4" does not exist
Command was: ALTER TABLE public.links_grouptraffic OWNER TO uauv8b9v4;
现在在example.cloudapp.net上访问我的Django应用程序只显示以下错误:
Exception Type: DatabaseError Exception Value:
permission denied for relation links_link
Exception Location: /home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 54
请注意,如果我使用-Ox
运行pg_restore,我会得到完全相同的权限被拒绝错误;它没有帮助。
接下来,我删除了数据库,并运行了CREATE USER uauv8b9v4 with password 'password';
,CREATE DATABASE mydb;
和GRANT ALL PRIVILEGES ON DATABASE mydb to uauv8b9v4;
。我现在想,如果我跑pg_restore latest.dump -d MYDB -U uauv8b9v4
,我的问题就会解决。
相反,我遇到了3个错误:
1)必须是扩展程序plpgsql的所有者:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2584; 0 0 COMMENT EXTENSION plpgsql
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql
Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
2)允许拒绝创建扩展程序" pg_stat_statements" :
pg_restore: [archiver (db)] Error from TOC entry 249; 3079 16622 EXTENSION pg_stat_statements
pg_restore: [archiver (db)] could not execute query: ERROR: permission denied to create extension "pg_stat_statements"
HINT: Must be superuser to create this extension.
Command was: CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
3)扩展" pg_stat_statements"不存在:
pg_restore: [archiver (db)] Error from TOC entry 2585; 0 0 COMMENT EXTENSION pg_stat_statements
pg_restore: [archiver (db)] could not execute query: ERROR: extension "pg_stat_statements" does not exist
Command was: COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed';
尝试访问我的网站仍然会给我原始的permission denied
错误。
我该怎么做才能解决这个问题?其次,我也开始想知道在某个阶段我是否需要在这个过程中运行syncdb
?我尝试了this,但它还没有解决我的问题。我觉得我错过了一些基本的东西。
答案 0 :(得分:2)
我认为你应该尝试像这样恢复:pg_restore --verbose --clean --no-acl --no-owner -U myuser -d mydb latest.dump
其中myuser
是linux机器上的超级用户(你不必让一个名为uauv8b9v4
的用户来制作这项工作)如果做得好,则无需运行syncdb
。