Python 有时我的PGU恢复或mongorestore会被卡住

Python 有时我的PGU恢复或mongorestore会被卡住,python,postgresql,mongodb,popen,Python,Postgresql,Mongodb,Popen,我的run_命令基本上取自 在我的控制台上: 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 loc

我的
run_命令
基本上取自

在我的控制台上:

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)
输入密码后就卡住了。之后什么也没发生。我不确定它是否资源繁忙
pg_restore
仍在根据
ps au | grep pg_restore
运行,而
mongorestore
未运行。因此,它必须在第一次恢复时停止。我也不认为它的内存已满,因为我的虚拟机只有512mb,而且总是满的,而且总是使用交换内存

我们怎么知道它在做什么?有时它会阻碍恢复mongo。所以所有这些操作都可能导致问题。 我应该如何对此进行故障排除

谢谢


当我终止进程时,我得到以下回溯:
重新启动将“解决”问题。它将允许我毫无问题地运行脚本。但这并不稳定。我们有时会在以后陷入困境。

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

  • 直接从命令行运行每个命令(即不通过Python
    do_command()
  • 将这些脚本放在单独的脚本中,以便确定挂起的是哪个命令

您提到的只有512MB RAM并且总是使用交换,这表明这个虚拟机上没有足够的可用内存。“卡住”到底是什么意思?如果虚拟机实际上被楔入并需要重新启动,那么它很可能已经耗尽了RAM和交换空间。如果您仍然可以登录,但还原脚本的运行时间似乎比预期的要长,我会尝试使用诸如
iostat
vmstat
之类的工具来了解资源使用情况,谢谢。在我进一步调查这个问题之前,我会先做出回应,然后再提出你提出的其他建议。我已经检查了
free-m
,交换未满,所以它似乎没有做什么奇怪的事情。可能是数据库被另一个进程锁定了吗?我尝试了
strace
pg\u还原。它挂在那里。看这里()它没有说
Poll
或任何东西。刚刚挂在所附的
process32305-中断以退出
谢谢。@CppLearner:您试过在PostgreSQL邮件列表上问这个问题吗?一些更详细的信息会有所帮助,例如:您的操作系统、特定版本的pg_还原/pg_转储(即
pg_还原--version
pg_转储--version
),以及使用的pg_转储选项。我没有遇到与您相同的问题,pg_restore显然神秘地挂起。@cpprearner:另一个尝试的建议。。。在pg_restore运行(或“挂起”)时查看是否可以。请耐心等待。我今天有点忙,因为我需要推出一个演示机。我会再检查一遍!谢谢你的大力帮助。
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: