Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql: backup all table structures but only a few data table

Tags:

I have a database with some tables for the application settings, lists like users, departments, cities. I want the structure and the data for those tables. So if i get a new user the backup will save it.

But also have some data for historic and calculated data, that data came from another sources and only work for some time and then expire, so backup that data will be a waste. But will need have the structure so the restore will create the tables need it for the application.

right now I'm using this command but this save all table and all data.

pg_dump -U "postgres" -h "local" -p "5432"          -d dbName -F c -b -v -f c:\uti\backup.dmp 

I have 2 additional questions regarding pg_dump.

A) docs say option -b is for blob data. I have very big tables, but i guess this options is for only tables with a BLOB field, so shouldn't make any difference in my backup because i don't have those fields ?.

B) I see pg_dump options are for tables and schemas. How you specify if want save the functions code?

like image 757
Juan Carlos Oropeza Avatar asked Jul 01 '14 18:07

Juan Carlos Oropeza


People also ask

How do I backup all tables in a schema?

Run the db_backup command to back up an entire database, or just a schema. In addition to restoring data by using the db_restore command, you can use the web console for data restore. Run the db_restore command to restore a database, a schema, or a table that was backed up using the db_backup command.

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.

How big is too big for a PostgreSQL table?

PostgreSQL normally stores its table data in chunks of 8KB. The number of these blocks is limited to a 32-bit signed integer (just over two billion), giving a maximum table size of 16TB.


1 Answers

Exclude the tables you do not want to backup

pg_dump -U "postgres" -h "local" -p "5432"          -d dbName -F c -b -v -f c:\uti\backup.dmp         --exclude-table-data '*.table_name_pattern_*'         --exclude-table-data 'some_schema.another_*_pattern_*' 

The function creation code is part of the schema.

like image 128
Clodoaldo Neto Avatar answered Sep 26 '22 01:09

Clodoaldo Neto