How to back up some tables with data and tables only PostgreSQL schemas

I want to reset the database.

I have three tables:

table1 table 2 table3

From table 1, I need a circuit plus data.

From table2 and table3 I just need a schema.

How can I do it?

+6
source share
2 answers

To retrieve data from multiple tables:

pg_dump myDatabase --inserts -a -t table1 -t table2> backup.sql;

pg_dump myDatabase --inserts -a -t seq1 -t seq2> backupSequences.sql;

Description of parameters:

-a, --data-only only returns data, not a schema

-t, --table = TABLE deletes only named table (s)

- inserts dump data as INSERT commands, not COPY

This is what I wanted :)

Thanks everyone!

+21
source

Use pg_dump , which has both a circuit and a circuit + data output.

+3
source

Source: https://habr.com/ru/post/893780/


All Articles