且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何备份和备份在Windows7中还原PostgreSQL数据库?

更新时间:2022-11-02 22:26:46

要备份数据库,可以使用pg_dump.exe:

  1. 打开命令行窗口
  2. 转到Postgres bin文件夹.例如:

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

cd "C:\Program Files\PostgreSQL\9.6\bin"

  • 输入命令以转储数据库.例如:

  • Enter the command to dump your database. For example:

    pg_dump.exe -U postgres -d MediaData -f D:\Backup\<backup-file-name>.sql
    

  • 为您的postgres用户输入密码

  • Type password for your postgres user

    要还原数据库,可以使用psql.exe. (请注意,以下摘录自Alexandr Omelchenko的有用答案,由于我不清楚的原因,该答案已被删除.)

    1. 打开命令行窗口
    2. 转到Postgres bin文件夹.例如:

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

    cd "C:\ProgramFiles\PostgreSQL\9.5\bin"
    

  • 输入命令以还原数据库.例如:

  • Enter the command to restore your database. For example:

    psql.exe -U postgres -d MediaData -f D:\Backup\<backup-file-name>.sql
    

  • 为您的postgres用户输入密码

  • Type password for your postgres user