Postgres.app:pg_restore挂起

20
我正在尝试解决我系统上 pg_restore 命令的问题。我已经安装了Postgresapp,并且已经将其二进制文件包含在我的PATH中。像psqlpg_dump这样的命令似乎工作正常,而运行which pg_restore会给出预期结果。
$ which pg_restore
/Applications/Postgres.app/Contents/MacOS/bin/pg_restore

问题在于pg_restore似乎没有任何作用。当我在终端中运行它时,没有任何输出被打印到控制台或日志中。无论我传递什么参数(包括 --verbose 开关),情况都是如此。运行会导致一个pg_restore进程出现在我的活动监视器中,但是这个进程不使用任何CPU。除此之外,什么也没发生。

有其他人遇到过这个问题吗?你们有没有什么建议可以让pg_restore工作呢?


4
你需要恢复多少数据?通常情况下,除非出现错误或警告,否则pg_restore不会在完成之前输出任何内容,除非你指定了--verbose模式。 - Jonathan Hall
4个回答

21

我想我解决了问题。

我运行的命令在用户名后面包含了一个额外的换行符。

就像这样,我试图执行这个命令

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myusername
-d mydb latest.dump

改为这样

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myusername -d mydb latest.dump

由于某种原因,多余的换行符使事情变得混乱。一旦我将其删除,pg_restore就正常工作了。


17

我从另一个问题的答案中得到了提示:即使您正在使用“自定义”格式转储(即不是使用shell重定向(如|>)提供的格式转储),-f选项也不会执行您可能认为它执行的操作(或者至少不是我认为的那样)。

  • 错误 ❌: pg_restore -f filename.dump – 等待一系列来自STDIN的命令,将其还原到名为filename.dump的数据库中
  • 正确 ✅: pg_restore -d database filename.dump – 将filename.dump还原到database

出于某种原因,我认为自定义转储包括数据库名称,因此根本不需要提供它。


1
现在感觉好蠢啊。我等了整整四个小时,还以为垃圾堆变大了,所以才需要这么长的时间。 - Nikhil Badyal

1

我也遇到了无法解决的困境。我将命令从pg_restore -U seed -h localhost -p 5432 -f dump.backup -C --verbose更改为pg_restore -d seed -U seed -h localhost -p 5432 < dump.backup,然后它就成功了。

如果这可以帮助到某个人..


0
有时候,如果您有长时间运行的查询,您需要停止它,以便pg_restore不会卡住。
运行此脚本:
SELECT pg_cancel_backend(pid) FROM pg_stat_activity WHERE state = 'active' and pid <> pg_backend_pid();

https://www.sqlprostudio.com/blog/8-killing-cancelling-a-long-running-postgres-query#:~:text=Terminate%20all%20queries,be%20used%20in%20special%20situations

本文是关于编程的,介绍了如何取消正在运行的Postgres查询。通过使用“Terminate all queries”命令可以轻松地中止长时间运行的查询,但在特殊情况下需要小心使用该命令。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接