【问题标题】:How to restore .bak file using pg_restore command through cmd in PostgreSQL?如何在 PostgreSQL 中通过 cmd 使用 pg_restore 命令恢复 .bak 文件?
【发布时间】:2020-10-26 17:48:47
【问题描述】:

我有一个使用 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 文件。

我该怎么做?

【问题讨论】:

  • 这取决于test.bak 的创建方式。那么你使用的命令是什么?
  • 我已经使用以下命令创建了 test.bak 文件:pg_dump -h localhost -U postgres -p 5432 -Fc -f "D:\Database Backup\temp.bak" Performace_Test。
  • @Akanksha :您应该将该详细信息添加到问题中,而不是评论。
  • Timescale 有说明如何恢复备份:docs.timescale.com/latest/using-timescaledb/backup

标签: postgresql timescaledb pg-restore


【解决方案1】:

您可以恢复执行以下操作(请注意进一步说明):

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

注意事项是:

  1. 如果通过引用将 Performace_Test 创建为混合大小写,则需要引用上面的名称,例如“性能测试”

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

  3. 还假设 Performace_Test 与您在 pg_dump 命令中指定的集群位于同一集群中。

【讨论】:

  • 这给了我一个错误:pg_restore: 错误:输入文件似乎不是一个有效的存档。
  • 那么temp.bak 文件不是使用您提供的pg_dump 命令创建的,或者它已损坏。你能打开文件看看它是否是纯文本转储吗?我想到了另一个想法,目录名称中的空格可能有问题。尝试将文件从“数据库备份”复制/移动到名称中没有空格的目录。
【解决方案2】:
     psql Performance_Test < test.bak

【讨论】:

  • 这不起作用,因为转储文件是自定义格式,需要pg_restore
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-07
  • 1970-01-01
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
相关资源
最近更新 更多