python - 有时我的 pg_restore 或 mongorestore 会卡住

标签 python postgresql mongodb popen

print 'restore db1'
run_command('pg_restore -i -h localhost -p 5432 -U postgres -d db1 -v "/var/lib/project/backup/db1.backup" -c')
print '--- wait 3 seconds'
time.sleep(3)

print 'restore db2'
run_command('pg_restore -i -h localhost -p 5432 -U postgres -d db2 -v "/var/lib/project/backup/db2.backup" -c')
print '--- wait 3 seconds'
time.sleep(3)

print 'restoring mongodb'
run_command('/var/lib/project/bbds/mongodb-linux/bin/mongorestore /var/lib/project/backup/dump --drop')
print '--- wait 3 seconds'
time.sleep(3)

我的run_command基本上取自this .

在我的控制台上:

python ignition.py --load-fixtures
For safety, this process will run for about one minute.
setup LDAP
restore db1
['pg_restore', '-i', '-h', 'localhost', '-p', '5432', '-U', 'postgres', '-d', 'db1', '-v', '/var/lib/project/backup/db1.backup', '-c']
Password: 

输入密码后就卡住了。之后什么也没有发生。我不确定资源是否繁忙。 pg_restore 仍在根据 ps au|grep pg_restore 运行,而 mongorestore 则未运行。所以一定要坚持第一次恢复。我也不认为内存已满,因为我的虚拟机只有 512mb,而且它总是满的,并且总是使用交换内存。

我们如何知道它在做什么?有时它会卡在恢复 mongo 上。所以所有这些操作都会导致问题。 我应该如何解决这个问题?

谢谢。


当我杀死进程时,我得到了这个回溯:http://pastebin.com/Cnv9P6HW 重新启动将“解决”问题。它将允许我毫无问题地运行脚本。但这并不稳定。有时我们最终会陷入困境。

最佳答案

您对 pg_restoremongorestore 的使用似乎是独立的。我会尝试:

  • 直接从命令行运行每个命令(即不通过 Python do_command())
  • 将它们放入单独的脚本中,以便您可以找出哪个命令挂起

您提到的只有 512MB RAM 并且始终使用交换表明此虚拟机上没有足够的可用内存。 “卡住”到底是什么意思?如果虚拟机实际上被卡住并需要重新启动,那么它很可能已经耗尽了 RAM 和交换空间。如果您仍然可以登录,但恢复脚本的运行时间似乎比预期的时间长,我会尝试使用 performance monitoring tools 了解资源使用情况例如 iostatvmstat

关于python - 有时我的 pg_restore 或 mongorestore 会卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11196175/

相关文章:

python - 使用 Python 读取 YAML 文件会导致 yaml.composer.ComposerError : expected a single document in the stream

mongodb - mongodb 如何决定查询时使用哪个索引?

python - PySpark:从另一个 Notebook 导入变量时,如何抑制 PySpark 单元中的 %run 输出?

sql - PostgreSQL 查询未按预期返回结果

sql - PostgreSQL 错误 : column "qty" is of type integer but expression is of type text

sql - 慢 WHERE IN 查询结束

javascript - 如何访问meteor.js中集合的元素?

javascript - node.js/express 路由中的 Mongoose 组查询

python - 当其中一个元素是 Python 字典时,向 MySQL 表中插入一行

Python:以读写模式打开 Outlook 电子邮件 (.msg) 文件