I have created a fresh db dump from a production server with the --data-only
and --column-inserts
flags, so I only have a bunch of insert statements to insert data when performing a restore on a staging server.
pg_dump -h localhost -U adminuser --data-only --column-inserts maindb > maindb.sql
How do I delete all data in the staging server database first, before restoring the data from the production dump?
I want to delete all data only so I don't have to drop and create the database and all that stuff. I just want to remove data and insert new data that is all.
I don't have the option to drop and create the database for several reasons. I will have to remove all data and just insert only, so whatever it takes to find how to do this, am willing to go for it but need help obviously to start with.
I also need to automate this process. Will automate "dumping data from production db", then "deleting data on staging db", and then "restoring data to staging db". I just need help on the "deleting data on staging db" part.
I am running on PostgreSQL 9.5.2