无法使用续集gem断开与postgres数据库的连接

时间:2012-10-18 21:41:59

标签: ruby postgresql sequel

我刚刚开始使用Sequel ruby​​gem,似乎'disconnect'方法无效。以下是我的IRB测试会议的输出:

1.9.3-p194 :002 > require 'sequel'
 => true 
1.9.3-p194 :003 > DB = Sequel.connect('postgres://postgres:mypassword@my_pg_host:5432/my_db')
 => #<Sequel::Postgres::Database: "postgres://postgres:mypassword@my_pg_host:5432/my_db"> 
1.9.3-p194 :004 > DB.test_connection
 => true 
1.9.3-p194 :005 > DB.disconnect
 => [] 
1.9.3-p194 :006 > DB.test_connection
 => true

我在Sequel文档中没有看到任何指示为什么这不起作用的内容:

http://sequel.rubyforge.org/rdoc/classes/Sequel/Database.html#method-i-disconnect

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

DB.disconnect断开当前连接池中的所有连接,并从池中删除连接。之后调用DB.test_connection将在连接池中查找连接,并且由于池为空,将导致创建新连接。

您发布的代码是完全预期的行为,但我猜您不知道DB不代表与数据库的单个连接。