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
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
Assuming you're talking about restoring from a
pg_dump backup the answer is "it depends on how the backup was made", but typically yes: You must empty the database before restoring the backup.
The fastest way to empty out a database in Postgres is to drop and re-create the database (you'll probably need superuser privileges for that), otherwise you have to manually drop each table and any stored procedures you may have (
CASCADE is your friend here).