pg_restore toc 错误

32
我曾使用以下语法进行pg_dump和还原操作。
pg_dump eval --inserts -b -c --encoding UTF8 -Fc -f eval.sql.tar.gz -x -U postgres
createdb -T template0 test -U postgres
pg_restore -d test eval.sql.tar.gz -e -U postgres

备份成功,没有错误,但还原时出现了一些错误。我在同一台机器上使用相同的用户和权限进行备份和还原,尝试使用其他格式(纯文本、tar、压缩),但仍然出现相同的错误。我的pg版本是8.4.11,psql版本也是8.4.11。我不确定是什么原因导致这些错误,有人可以帮助我吗?

 pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 4965; 0 138871 TABLE DATA ir_act_report_xml insigni
pg_restore: [archiver (db)] could not execute query: ERROR:  invalid input syntax for integer: "purchase.order"
LINE 1: ...st for Quotation', 'ir.actions.report.xml', NULL, 'purchase....
                                                             ^
    Command was: INSERT INTO ir_act_report_xml VALUES (350, 'Request for Quotation', 'ir.actions.report.xml', NULL, 'purchase.order', 'purcha...

2
看起来你的转储文件是一个 SQL 脚本,需要使用 psql 运行,而不是 pg_restore。 - user330315
3个回答

35

这样就搞定了。

pg_dump database_name -c -Ft -f file_name.tar 

pg_restore -d database_name -c file_name.tar

在此之前,我试图在不包括-c(clean)的情况下进行还原。

即使在pg_dump中包含了-c选项,在pg_restore中也不会使用它,除非我们明确指定使用...


10
使用“clean”标志也会导致很多问题,因为在使用全新的数据库时它会抱怨缺少对象。 - cslotty
4
-c 标志没有起作用。仍然出现相同的错误:<br/><code> $ pg_restore -d development -t integrations -c b7c5 pg_restore: [archiver (db)] 在处理 TOC 时发生错误: pg_restore: [archiver (db)] 来自 TOC 条目 210;1259 的错误 TABLE integrations u5j7 pg_restore: [archiver (db)] 无法执行查询:ERROR: 角色 "u5j7" 不存在 Command was: ALTER TABLE public.integrations OWNER TO u5j7;警告:恢复过程中忽略了错误:1 - IamLearning

28

在我的情况下的解决方案:

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U username -d database_name dump_name.dump

5
如果你想摆脱无用的错误信息,--if-exists 选项是很方便的。参考链接:https://www.postgresql.org/docs/current/app-pgrestore.html - Naramsim
冗长的输出很有用。 - Andrew

1

这个 对我有用:

postgresql.conf 中增加 max_wal_size postgresql 设置(max_wal_size = 2GB)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接