[英]PostgreSQL : it is possible to restore only Large Object with PostgreSQL?
We have a simple table my_table
like :我们有一个简单的表
my_table
,例如:
id (int) -> primary key
object_id (Large Object)
Unfortunately, a contractor of us have run lo_unlink
on the IDs of the large objects from the column object_id
of the table my_table
.不幸的是,我们中的一个承包商对
my_table
的列object_id
中的大对象的 ID 运行lo_unlink
。
The Large Object ID are still in the table, but the associated Large Objects not exist anymore :大对象 ID 仍在表中,但关联的大对象不再存在:
ERROR: large object 10268782 does not exist
SQL state: 42704
We do backup with pg_dump
every night.我们每晚都使用
pg_dump
进行备份。
How we can restore only the Large Object with pg_restore
?我们如何使用
pg_restore
只恢复大对象?
Indeed, we don't need to restore all the tables, even not the table with LOB ID (because the ID are still defined), but reload only the Large Object into the database from the dump.实际上,我们不需要恢复所有表,甚至不需要恢复具有 LOB ID 的表(因为仍然定义了 ID),而只需将大对象从转储中重新加载到数据库中。
The pg_restore
has an option : pg_restore
有一个选项:
--data-only
Restore only the data, not the schema (data definitions). Table data, large objects, and sequence values are restored, if present in the archive.
but we don't want to restore table data or sequence values.但我们不想恢复表数据或序列值。 Just large objects.
只是大物体。
Thank you谢谢
To restore only the large objects from a dump that is not in plain text format, you can proceed as follows:要仅从非纯文本格式的转储中恢复大对象,您可以执行以下操作:
create a "table of contants" file from the dump:从转储中创建一个“目录表”文件:
pg_restore --list --file=tocfile dumpfile
edit tocfile
and remove all lines except the one that contains BLOBS
, for example编辑
tocfile
并删除除包含BLOBS
的行之外的所有行,例如
4353; 0 0 BLOBS - BLOBS
now you can restore only the large objects:现在您只能恢复大对象:
pg_restore --use-list=tocfile --dbname=proddb dumpfile
That will overwrite all large objects in the database.这将覆盖数据库中的所有大对象。 If you only want to restore certain large objects, there is no easy way.
如果你只想恢复某些大对象,没有简单的方法。 You can run the final
pg_restore
to write SQL statements to a file by using --file=lobs.sql
instead of --dbname=proddb
, which will create an SQL script with all large objects in it.您可以运行最终的
pg_restore
以使用--file=lobs.sql
而不是--dbname=proddb
将 SQL 语句写入文件,这将创建一个包含所有大对象的 SQL 脚本。 You'd have to edit that file manually to extract the objects you want :^/您必须手动编辑该文件以提取所需的对象:^/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.