2012-06-25 86 views
2
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有时我的pg_restore或mongorestore卡住了

在我的控制台:

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 重新启动电脑将“解决”问题。它将允许我毫无问题地运行脚本。但这并不稳定。有时候我们会迟到。

回答

2

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

  • 直接在命令行中运行的每个命令(即不通过Python do_command()
  • 将这些成单独的脚本中,这样就可以计算出该命令是挂

你提只有512MB内存,并始终使用交换表明此虚拟机上没有足够的可用内存。 “卡住”究竟意味着什么?如果虚拟机实际上被楔住并需要重新启动,那么很可能已经用完了RAM和交换。如果您仍然可以登录,但恢复脚本似乎运行时间超过预期时间,我会尝试使用performance monitoring tools(如iostatvmstat)了解资源使用情况。

+0

谢谢。在进一步调查您提供的其他建议之前,我会先做出回应。我已经检查过'free -m'并且swap没有满,所以它看起来好像不是很奇怪。它可能是数据库被另一个进程锁定?我试图'strace' pg_restore。它挂在那里。看到这里(http://blog.kimiensoftware.com/2011/06/pg_restore-hanging-on-remote-create-index-344)它没有说'投票'或任何东西。只要挂在'过程32305附加 - 中断退出'行谢谢。 – CppLearner

+0

@CppLearner:你有没有试过在PostgreSQL邮件列表上提问?一些更多的细节会有帮助,例如:你的O/S,pg_restore/pg_dump的特定版本(即'pg_restore --version','pg_dump --version')和使用的pg_dump选项。我还没有遇到同样的问题,pg_restore显然神秘地挂起。 – Stennie

+0

@CppLearner:另一个建议尝试...查看您是否可以在pg_restore运行时查看正在执行的查询(http://chrismiles.info/systemsadmin/databases/articles/viewing-current-postgresql-queries/)(或“挂起”)。 – Stennie