ruby-on-rails – Rails + Postgres drop error:其他用户正在访问数据库
问题:
我有一个在Postgres上运行的rails应用程序。
我有两台服务器:一台用于测试,另一台用于生产。
我经常需要在测试服务器上克隆生产数据库。
我通过弗拉德跑的命令是:
rake RAILS_ENV='test_server' db:drop db:create
我遇到的问题是我收到以下错误:
ActiveRecord::StatementInvalid: PGError: ERROR: database <database_name> is being accessed by other users DROP DATABASE IF EXISTS <database_name>
如果有人最近通过网络访问了该应用程序(postgres保持“会话”打开),就会发生这种情况
有什么方法可以终止postgres DB上的会话吗?
谢谢。
编辑
我可以使用phppgadmin的界面删除数据库,但不能使用rake任务删除数据库。
如何使用rake任务复制phppgadmin的drop?
I have a rails application running over Postgres.I have two servers: one for testing and the other for production.Very often I need to clone the production DB on the test server.The command I’m runnig via Vlad is:The problem I’m having is that I receive the following error:This happens if someone has accessed the application via web recently (postgres keeps a “session” opened)Is there any way that I can terminate the sessions on the postgres DB?Thank you.EditI can delete the database using phppgadmin’s interface but not with the rake task.How can I replicate phppgadmin’s drop with a rake task?