How to backup & Restore PostgreSQL database in Windows7?

只谈情不闲聊 提交于 2019-12-03 16:56:34

To backup a database you can use pg_dump.exe:

  1. Open command line window
  2. Go to Postgres bin folder. For example:

    cd "C:\Program Files\PostgreSQL\9.6\bin"
    
  3. Enter the command to dump your database. For example:

    pg_dump.exe -U postgres -d MediaData -f D:\Backup\<backup-file-name>.sql
    
  4. Type password for your postgres user

To restore a database you can use psql.exe. (Note, the following is extracted from Alexandr Omelchenko's helpful answer which has been deleted for reasons not clear to me.)

  1. Open command line window
  2. Go to Postgres bin folder. For example:

    cd "C:\ProgramFiles\PostgreSQL\9.5\bin"
    
  3. Enter the command to restore your database. For example:

    psql.exe -U postgres -d MediaData -f D:\Backup\<backup-file-name>.sql
    
  4. Type password for your postgres user

I was stuck here when creating the database dump file due to version mismatch. So I follow the below command to get the backup and restore.

pg_dump -h localhost -U postgres -p 5432 YourDbName > BackupFileName.dump
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!