Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dump a postgres db excluding one specific table?

Tags:

postgresql

I'd like to use pg_dump to backup postgres database content. I only want to ignore one specific table containing cached data of several hundred GB.

How could I achieve this with pg_dump?

like image 869
membersound Avatar asked Jul 28 '15 08:07

membersound


People also ask

How do I delete a specific table in PostgreSQL?

PostgreSQL has a DROP TABLE statement that is used to remove an existing table or tables from the database. Syntax: DROP TABLE [IF EXISTS] table_name [CASCADE | RESTRICT]; Let's analyze the above syntax: We specify the table name after the DROP TABLE keyword to remove the table permanently from the database.

Does pg_dump lock database?

pg_dump doesn't lock the entire database, it does get an explicit lock on all the tables it is going to dump, though.

How can I dump all tables to CSV for a PostgreSQL schema?

The easiest but the most efficient way to export data from a Postgres table to a CSV file is by using the COPY command. COPY command generates a CSV file on the Database Server. You can export the entire table or the results of a query to a CSV file with the COPY TO command.


1 Answers

According to the docs, there is an option to --exclude-table which excludes tables from the dump by matching on a pattern (i.e. it allows wildcards):

-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. -T can be given more than once to exclude tables matching any of several patterns.

When both -t and -T are given, the behavior is to dump just the tables that match at least one -t switch but no -T switches. If -T appears without -t, then tables matching -T are excluded from what is otherwise a normal dump.

There are a few examples here.

like image 115
LondonRob Avatar answered Oct 20 '22 20:10

LondonRob