师 我需要备份和恢复一个PostgreSQL数据库。 我的os版本是Ubuntu-14.04 64bit,PostgreSQL是:
gid: ~/works $ pg_config --version
PostgreSQL 9.3.15
我使用pg_dump来备份数据库:
gid: ~/works $ pg_dump -U db_name_user -F t db_name > db_name.tar
我尝试使用pg_restore恢复数据库并失败:
gid: ~/works $ pg_restore -U db_name_user -F t -d db_name db_name.tar
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3621; 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';
pg_restore: WARNING: no privileges could be revoked for "public"
pg_restore: WARNING: no privileges could be revoked for "public"
pg_restore: WARNING: no privileges were granted for "public"
pg_restore: WARNING: no privileges were granted for "public"
WARNING: errors ignored on restore: 1
我不知道这意味着什么? 我如何备份和恢复PostgreSQL数据库?
非常感谢。
------------------------ update 1 --------------------- ---
即使我添加了#34; - 没有所有者"使用pg_dump和pg_restore的选项,我仍然得到相同的错误消息:
gid:~/works $ pg_restore -U db_name_user -O -Ft -d db_name db_name.tar
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3621; 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';
pg_restore: WARNING: no privileges could be revoked for "public"
pg_restore: WARNING: no privileges could be revoked for "public"
pg_restore: WARNING: no privileges were granted for "public"
pg_restore: WARNING: no privileges were granted for "public"
WARNING: errors ignored on restore: 1
答案 0 :(得分:0)
您可以忽略评论语言时出错 - 它不会影响您的代码。 还要考虑不使用所有者来避免此类警告。但请记住,所有者将是您在pg_restore上连接的用户,而不是原始用户。请阅读文档: https://www.postgresql.org/docs/current/static/app-pgrestore.html:
-O
- no-owner 不输出命令来设置对象的所有权以匹配原始数据库。默认情况下,pg_restore会发出ALTER OWNER或 SET SESSION AUTHORIZATION语句用于设置已创建的所有权 架构元素。除非是最初的,否则这些陈述将失败 与超级用户(或同一用户)建立数据库连接 拥有脚本中的所有对象)。使用-O,任何用户名 可用于初始连接,此用户将拥有所有 创造了对象。