Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Table during pg_restore

UPDATE: Was able to exclude the data in the table durning the pg_dump command. Makes it even faster than trying to not load the data because you don't have to wait for that data to be dumped.

--exclude-table-data=event_logs

(PostgreSQL) 9.4.4

Anyone know how to exclude a table when doing a pg_restore? I can find how to do it when doing a pg_dump. However I am not the one doing the dump and can't exclude them.

There are 2 tables in the dump that are really big and take forever when I do a restore so I want to skip them.

like image 885
covard Avatar asked May 04 '16 21:05

covard


1 Answers

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:

Run

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.

like image 184
Jesper Grann Laursen Avatar answered Sep 27 '22 23:09

Jesper Grann Laursen