Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dumping psql tables with specific prefixes

Im currently using the tool pg_dump to dump tables from my database. I would like to automate this process, however, i have not found a way to specify pg_dump to dump multiple databases that have the same prefix.

Any help in this matter would be greatly appreciated

like image 220
Redconnection Avatar asked Jan 18 '11 04:01

Redconnection


2 Answers

Examples from the manual:

To dump all tables whose names start with emp in the detroit schema, except for the table named employee_log:

$ pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb > db.sql

To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:

$ pg_dump -n 'east*gsm' -n 'west*gsm' -N 'test' mydb > db.sql

The same, using regular expression notation to consolidate the switches:

$ pg_dump -n '(east|west)*gsm' -N 'test' mydb > db.sql

To dump all database objects except for tables whose names begin with ts_:

$ pg_dump -T 'ts_*' mydb > db.sql

like image 53
Frank Heikens Avatar answered Oct 02 '22 01:10

Frank Heikens


You can use parameter "-t" multiple times if you want to dump more than one table.

$ pg_dump -t table1 -t table2 mydb > dump.sql

-t table --table=table

Dump only tables (or views or sequences) matching table. Multiple

tables can be selected by writing multiple -t switches.

like image 31
Mamad Asgari Avatar answered Oct 01 '22 23:10

Mamad Asgari