Postgresql – psql empty database before restore

postgresqlpsql

I want to restore a database of postgreSQL, but before do it i need to empty the restore target database.

Is there an option of psql to do it ?

Now i use a command line as the following :

psql -U postgres db_test < testdb.sql

Best Answer

There are two options here - if your backup is plain text then you add the -c option to pg_dump - ie

pg_dump -c mydb > mydb.sql

Otherwise if your using -Fc or -Ft on pg_dump then you use the -c flag on pg_restore

pg_dump -Ft -b mydb > db.tar

pg_restore -c -d newdb db.tar