Question

Do I always have to delete and then create a database to restore it from a pg_dump file? If I don't delete the database, the data being restore is added to the current data in the DB even if some register already are in the database (so the data is duplicated).

Was it helpful?

Solution

You can use -c (--clean) option while running pg_dump, so the dump will contain proper DROP ... commands.

But generally, I would suggest to go the "hard way":

dropdb ...
createdb ...
psql -d ... -f dump.file

In this way you are sure that there are no "left overs" from whatever was previously in the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top