Backup Data of Specific Tables in PostgreSQL

To use pg_dump to export data of specific tables only, you can use the -t option followed by the table name. For example:

pg_dump -U [username] -t [table_name] [database_name] > [dump_file].sql

If you want to export multiple tables, you can specify multiple -t options followed by the table names. For example:

pg_dump -U [username] -t [table_name1] -t [table_name2] [database_name] > [dump_file].sql

You can also use wildcard to dump multiple tables

pg_dump -U [username] -t [table_name_prefix]* [database_name] > [dump_file].sql

This will export the data of the specified tables only and save it in the specified dump file.

Die Meester Avatar

0 responses to “Backup Data of Specific Tables in PostgreSQL”