我需要备份和恢复一个PostgreSQL数据库。我的操作系统版本是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数据库?
多谢了。
- ----------------------更新1--------------------
即使我在pg_dump和pg_restore中添加了"--no-owner"选项,我仍然得到了相同的错误消息:
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
2条答案
按热度按时间dy1byipe1#
你可以忽略注解语言的错误--它不会影响你的代码。还可以考虑使用无所有者来避免此类警告。但请记住,所有者将是您在pg_restore上连接的用户,而不是原始用户。请阅读docs:https://www.postgresql.org/docs/current/static/app-pgrestore.html:
--no-owner不输出设置对象所有权匹配原数据库的命令。默认情况下,pg_restore发出ALTER OWNER或SET SESSION AUTHORIZATION语句来设置创建的架构元素的所有权。除非超级用户(或拥有脚本中所有对象的同一个用户)与数据库进行初始连接,否则这些语句将失败。使用-O,任何用户名都可以用于初始连接,并且该用户将拥有所有创建的对象。
8oomwypt2#