How to backup & Restore PostgreSQL database in Windows7?

后端 未结 2 1948
别那么骄傲
别那么骄傲 2020-12-28 10:49

I am new to Postgres database. I have to get the backup from Production Server (pgAdmin Version is 9.2.4) & restore it on my local machine (I have pgAdmin Version 9.4).

相关标签:
2条回答
  • 2020-12-28 11:14

    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
    
    0 讨论(0)
  • 2020-12-28 11:15

    To backup a database you can use pg_dump.exe:

    1. Open Powershell

    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 my_database_name -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 Powershell

    2. Go to Postgres bin folder. For example:

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

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

    0 讨论(0)
提交回复
热议问题