pg_dump对对象没有评论? [英] pg_dump without comments on objects?
问题描述
是否可以执行pg_dump并排除对表/视图和列的COMMENT ON?
Is there a way to perform a pg_dump and exclude the COMMENT ON for tables/views and columns ?
我广泛使用COMMENT ON命令来描述所有对象,并经常在其中包含换行符以获得更清晰的描述,例如:
I use extensively the COMMENT ON command to describe all objects, and often include newlines in them for clearer descriptions, e.g.:
COMMENT ON TABLE mytable1 IS 'MAIN TABLE...
NOTES:
1. ...
2. ...
3. ...
';
但是,由于转储中也有换行符,所以我不能简单地用grep删除注释-v'COMMENT ON'命令。
However, since there are newlines in the dump as well, I cannot simply remove the comments with a grep -v 'COMMENT ON' command.
以其他方式从转储中快速删除这些COMMENT ON吗?
Any other way to quickly remove these COMMENT ON from the dump ?
推荐答案
AFAIK, pg_dump
和 pg_restore
都没有删除<$ c的选项$ c>评论。但是,如果您使用二进制转储格式,例如:
AFAIK, neither pg_dump
nor pg_restore
have options to remove COMMENT
s. 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 COMMENT
s 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
这篇关于pg_dump对对象没有评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!