Exclude Table during pg_restore

I had the same problem. A long table list, and I want exclude the data from a few of the tables.

What I did was the following:


pg_restore -l $pgdump_file > restore.pgdump.list

Open that restore.pgdump.list file in an editor, and insert an ; in front of the line saying

;2429; 0 27550 TABLE DATA public <table_to_explore> <database>

After saving the that file, it can now be used for importing, where all lines starting with ; are ignored.

pg_restore -L restore.pgdump.list | psql

You could make an one-liner to add ; in front of lines having a specific table name, if you completely want to ignore a specific table.

man pg_restore is also telling about this in an example in the end of the documentation.

Leave a Comment