Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get pg_dump to exclude a specific sequence?

Tags:

I want to exclude a sequence from my pg_dump command which is putting the output into a plain file.

Command: /Library/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5433 --username xxx --format plain --clean --inserts --verbose --file /Users/xxx/documents/output/SYSTEM_admin_20131126015325.sql --exclude-table public.table1 --exclude-table public.table2 mydatabase 

I know there are switches for tables which i am using above and that you can enable/disable database objects in the tar format in combination with pg_restore as stated in the pg_dump documentation but I will not be using pg_restore.

Many Thanks

Graham

like image 418
Graham Avatar asked Nov 26 '13 12:11

Graham


People also ask

Is pg_dump consistent?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently.

Does pg_dump overwrite?

Restoring the data from pg_dump doesn't overwrite the data but it appends the data to the original database. Bookmark this question.

Does pg_dump include dead tuples?

“Dead tuples” are not visible. Since pg_dump gets its data by running a SELECT statement against the table to be dumped, it won't see those deat tuples either, so it won't dump them.

Does pg_dump affect performance?

The only impact of pg_dump are the increased I/O load and the long running transaction it creates. The long transaction will keep autovacuum from reclaimimg dead tuples for the duration of the dump. Normally that is no big problem unless you have very high write activity in the database.


1 Answers

There are two cases:

  1. The sequence to exclude is owned by a table you're also dumping (typical case: SERIAL column).
    See: Dump a table without sequence table in postgres
    Short answer: no, the sequence can't be left aside.

  2. The sequence is not owned by a dumped table. Then it can be excluded with the --exclude-table switch as if it was a table.

From pg_dump documentation:

-T table --exclude-table=table

Do not dump any tables matching the table pattern. 

The pattern is interpreted according to the same rules as for -t

And about -t:

-t table
--table=table

Dump only tables (or views or sequences or foreign tables) matching table 
like image 63
Daniel Vérité Avatar answered Sep 28 '22 14:09

Daniel Vérité