I have a production server (ec2) with a Django App and Postgresql Database. I make a DB backup everynight with pg_dump which backs up the tables data.
sudo -u postgres pg_dump --column-inserts --data-only mydb > mybackup.sql
Postgres provides the possibility of ignoring some tables to be backed up (tables schema + data: --exclude-table=TABLE)
However I have some tables, that I would like backup their schema but not their data, I just want to dump the table with empty data, the old data are not important at all, but they make the backup file huge if dumped.
There is a patch "exclude-table-data=TABLE" that allows a user to have pg_dump exclude data but not DDL for a table. One use case for this is a very large table that changes infrequently, and for which dumping data frequently would be wasteful and unnecessary.
I would like to know how to apply this patch without losing anything on my database on my production server.
I found a better solution, upgrade PostgreSQL to a version 9.2 or higher, and I found a safe way to do so: (Upgrade PostgreSQL 9.1 to 9.3 on Ubuntu 12.04)
Note: This will install both PostgreSQL 9.3 and 9.4, so whether remove PostgreSQL 9.4 when finished or change the above code to upgrade to version 9.4.
Reference.
Later I realized that, since I'm using --data-only, --exclude-table and --exclude-table-data would have the same effect since I'm ignoring the schema !