I want to dump a database.
I have three tables:
table1 table2 table3
From table1 i want the schema plus data.
From table2 and table3 i just want the schema.
How do i do that?
To backup a specific table, use the –table TABLENAME option in the pg_dump command. If there are same table names in different schema then use the –schema SCHEMANAME option. This is an example of backing up a specific Postgres database.
Export schema structure using SQLYogFrom the Tools menu, choose Backup Database as SQL dump. At the top pane, choose Export as SQL: structure only. On the left side, choose the database to export. On the left side, uncheck all Object types except Tables.
PostgreSQL supports having multiple schemas in a single database there by letting you namespace different features into different schemas. For example, you can have a database named postgres and have multiple schemas based on your application like ecommerce , auth etc.
To get data from just a few tables:
pg_dump myDatabase --inserts -a -t table1 -t table2 > backup.sql;
pg_dump myDatabase --inserts -a -t seq1 -t seq2 > backupSequences.sql;
Parameters descriptions:
-a, --data-only dump only the data, not the schema
-t, --table=TABLE dump the named table(s) only
--inserts dump data as INSERT commands, rather than COPY
This is what i wanted :)
Thanks all!
Use pg_dump, which has both schema-only and schema + data output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With