2017-05-11 54 views
1

大师 我需要备份和恢复一个PostgreSQL数据库。 我的操作系统版本是Ubuntu的14.04 64位,而PostgreSQL是:如何备份和恢复一个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 -------------------- ----

即使我补充说:“--no所有者”选项时的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 
+1

您可以放心地忽略此错误。缺乏对plpgsql的评论不会影响你的代码。如果你想以超级用户的身份运行pg_restore,你不应该看到这样的警告 –

回答

0

您可以发表评论的语言忽略错误 - 它不会影响你的代码。 也可以考虑不使用所有者来避免这种警告。但请记住,所有者将成为您在pg_restore上连接的用户,而不是原来的用户。请阅读文档: https://www.postgresql.org/docs/current/static/app-pgrestore.html

-O

--no-owner Do not output commands to set ownership of objects to match the original database. By default, pg_restore issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created schema elements. These statements will fail unless the initial connection to the database is made by a superuser (or the same user that owns all of the objects in the script). With -O, any user name can be used for the initial connection, and this user will own all the created objects.

+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: [存档器(db)]处理目录时出错: pg_restore:[存档器(db)]来自TOC条目3621的错误; 0 0 COMMENT EXTENSION plpgsql pg_restore:[archiver(db)]无法执行查询:ERROR:必须是扩展的所有者plpgsql 命令是:COMMENT ON EXTENSION plpgsql是'PL/pgSQL过程语言'; – zhengfish

+0

当然 - 不用客气 –