pg_restore 9.4 失败并出现错误 'could not execute query'

pg_restore for 9.4 fails with error 'could not execute query'

我要恢复的 PostgreSQL 版本是 9.4.10。我从同一版本备份了一个数据库。我用于恢复的命令是:

/opt/PostgreSQL/9.4/bin/pg_restore -U postgres --port=5432 -v --dbname=mydb < /backups/309646/WAL/pipe_309646

我得到的错误是:

pg_restore: executing BLOB 71197
pg_restore: [archiver (db)] Error from TOC entry 3822; 2613 71197 BLOB 71197 user
pg_restore: [archiver (db)] could not execute query: ERROR:  duplicate key value violates unique constraint "pg_largeobject_metadata_oid_index"
DETAIL:  Key (oid)=(71197) already exists.
    Command was: SELECT pg_catalog.lo_create('71197');

这在 pg 错误中重复了大约 112 次。我需要恢复到同一个数据库。这是我用于转储的命令:

/opt/PostgreSQL/9.4/bin/pg_dump" -U postgres -Fc -b  --port=5432  'mydb' -t public.users > /backups/309646/WAL/pipe_309646

关于为什么会发生这种情况的任何迹象?我怎样才能减轻这个错误?

您正在尝试将一个大对象恢复到一个已经包含具有相同 oid 的大对象的数据库中。

使用不包含任何大对象的新数据库作为还原目标。

或者,先使用

删除大对象
SELECT lo_unlink(oid) FROM pg_largeobject_metadata;