Newtang
Newtang

Reputation: 6544

Using pg_dump, export entire schema for all tables and data for one table

I'd like to export the entire schema using pg_dump as well as the data within a single table. I know I can do something like this:

pg_dump -s mydatabase > db.sql; pg_dump -a -t some_table mydatabase >> db.sql

However, it's somewhat inelegant, and the output of the second half repeats a lot of settings and comments that the first half already provides such as:

-- Dumped from database version 9.6.8
-- Dumped by pg_dump version 9.6.8

SET statement_timeout = 0;
SET lock_timeout = 0;
...

Is there a better way to do this?

Upvotes: 2

Views: 2946

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51406

using both is restricted

t=# \! pg_dump -d t -h localhost -p 5400 -s -a -t so12
pg_dump: options -s/--schema-only and -a/--data-only cannot be used together

so obviously - no. you have to do them sequentially...

SET SESSION statements just set the session "parameters" - they won't duplicated data or such - why you want to avoid them?..

I can't imagine any faster commands executed, e./g. compared to select now():

t=# \timing on
Timing is on.
t=# SET statement_timeout = 0;
SET
Time: 0.312 ms
t=# select now();
             now
------------------------------
 2018-04-01 17:40:37.52727+01
(1 row)

Time: 17.182 ms

Upvotes: 2

Related Questions