Is there a way to perform a pg_dump and exclude the COMMENT ON for tables/views and columns ?
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. ...
';
However, since there are newlines in the dump as well, I cannot simply remove the comments with a grep -v 'COMMENT ON' command.
Any other way to quickly remove these COMMENT ON from the dump ?
AFAIK, neither
pg_dump
norpg_restore
have options to removeCOMMENT
s. But, if you use a binary dump format like:you could extract the TOC entry and edit it:
The above will extract a TOC file and save it at
/path/to/backup.toc
, then you could find each line withCOMMENT
entry and remove or comment it. If you don't use strange names on your objects, a simplesed
would solve the problem, to comment the lines withCOMMENT
s you could do this (a semicolon starts a comment):With this new TOC file, you can now use
pg_restore
to restore your dump (with-L
option):I would actually do this with a two-stage dump and restore.
Dump and restore the db as is or create a new db from the old one with
createdb -T
orCREATE DATABASE WITH TEMPLATE
Run the following command