5

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).

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Another good thing about your solution is that you do not need to make a VACUUM FULL to reclaim the space of deleted records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.