如何在 PostgreSQL 中通过 cmd 使用 pg_restore 命令恢复 .bak 文件?

How to restore .bak file using pg_restore command through cmd in PostgreSQL?

我有一个用 pg_dump 命令创建的 test.bak 文件,它有一个超表,我在 postgreSQL 中创建了一个新数据库 Performance_Test。

使用以下命令转储数据库:

pg_dump -h localhost -U postgres -p 5432 -Fc -f "D:\Database Backup\temp.bak" Performace_Test

我想在 Performance_Test 中恢复那个 test.bak 文件。

我该怎么做?

     psql Performance_Test < test.bak

您可以恢复执行以下操作(注意事项在后面进一步说明):

pg_restore -h localhost -d Performace_Test -U postgres -p 5432 "D:\Database Backup\temp.bak"

注意事项是:

  1. 如果 Performace_Test 是通过引用创建为混合大小写的,您需要引用上面的名称,例如“Performace_Test”

  2. 如果Performace_Test不为空那么你会得到一堆错误。

  3. 还假定 Performace_Test 与您在 pg_dump 命令中指定的群集相同。