简体   繁体   中英

How to restore database in PostgreSQL with pgadmin3?

I'm using pgAdmin to restore PostgreSQL database. To restore the database I need to delete, drop and remake it. How to restore the database without deleting and remaking it?

This cannot be done in pgAdmin or with any database tools . Regular backup files cannot be restored without deleting the data first because they consist of normal COPY statements which will fail if you have rows in the database (primary keys collide etc).

For a simple way to get back to an earlier snapshot in a testing environment take a look at PostgreSQL documentation - 24.2. File System Level Backup :

For backup:

  • Shut down your database
  • copy all the files from your data directory

For restore:

  • Shut down your database
  • replace your data directory with the backup directory

Note:

  • the size of the data might be significantly larger than with a regular backup especially if you have a lot of indexes
  • this is a server wide backup so you can't do this on individual databases
  • don't attempt to use it on a different version of PostgreSQL
  • this really deletes the data too - by replacing it with the backup

Also with regular backups you don't have to do a DROP TABLE if you do a data-only restore with pg_restore --data-only for example. You still have to delete the data though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM