pg_dump: How to Export only Table Scheme or Data


pg_dump with -s , -a option is used on exporting only table scheme or data.

Export table scheme and data separately.

Export Table Scheme

You can use this when you want to create the database similar to another.

If you want to all table schemes remove -t TABLE_NAME.

Export Table Data

Commands may also change, so please refer to the PostgreSQL documentation for the most up-to-date information.

To import the exported data, execute psql with the -f file_name option.

I use above commands when I add a new column to existing table.

Add Column

PostgreSQL allows us to add new column only after existing columns. On the other hand, MySQL allows us to add new column wherever position.

So I add column in PostgreSQL in the following procedure.

  1. Export table scheme and data separately. (You can also export both data and schema together.)

  2. Change the exported table scheme, add table deletion sql on the top.

  3. Create backup.

  4. Change table and data.