且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pg_dump对对象没有评论?

更新时间:2023-02-02 20:31:32

AFAIK, pg_dump pg_restore 都没有删除评论。但是,如果您使用二进制转储格式,例如:

AFAIK, neither pg_dump nor pg_restore have options to remove COMMENTs. But, if you use a binary dump format like:

 $ pg_dump -Fc <your connection> -f /path/to/backup.dump

您可以提取TOC条目并进行编辑:

you could extract the TOC entry and edit it:

 $ pg_restore -l -f /path/to/backup.toc /path/to/backup.dump

上面将提取一个TOC文件并将其保存在 /path/to/backup.toc ,那么您可以找到每个带有 COMMENT 条目的行并将其删除或添加注释。如果您不在对象上使用奇怪的名称,则简单的 sed 可以解决问题,并用 COMMENT $ c $注释行。 c> s您可以执行此操作(分号开始评论):

The above will extract a TOC file and save it at /path/to/backup.toc, then you could find each line with COMMENT entry and remove or comment it. If you don't use strange names on your objects, a simple sed would solve the problem, to comment the lines with COMMENTs you could do this (a semicolon starts a comment):

$ sed -i 's/^\(.* COMMENT .*\)/;\1/g' bar.toc

新的TOC文件,您现在可以使用 pg_restore 恢复转储(带有 -L 选项):

With this new TOC file, you can now use pg_restore to restore your dump (with -L option):

$ pg_restore -L /path/to/backup.toc -d <your database> /path/to/backup.dump