pg_dump and pg_restore (DROP IF EXISTS)
If you want to restore the database to a consistent state, I recommend you to drop and recreate it before restoring the dump:
dropdb -h domain.edu -U me mydatabase
createdb -h domain.edu -U me -T template0 mydatabase # adjust encoding/locale if necessary
pg_restore -h domain.edu -p 5432 -U me -d mydatabase -W mydump.sql
You could use --clean
in pg_dump to first drop objects:
pg_dump --clean
Backup
pg_dump --clean -U user database > database.sql
Restore
psql -U user -d database -f database.sql