PGconn.connect .... 断开连接在哪里?

问题描述 投票:0回答:2

环境:

psql(PostgreSQL)9.6.3 轨道 5.1.1 红宝石 2.4.1p111

问题:

我可能有一大群(Devise)用户,每个用户都是一个单独的 Postgres 用户,例如SomePostgresRole01、SomePostgresRole02 等

我可以成功做到:

conn = PGconn.connect("localhost", 5432,"","","db_development","SomePostgresRole01","SomePassword")

我找不到 conn.disconnect 方法。有这样的功能吗?

ruby postgresql
2个回答
3
投票

.close()
可用于关闭连接。使用
ensure
确保即使在发生异常后它也会关闭数据库连接。

begin
   conn = PGconn.connect("localhost", 5432,"","","db_development","SomePostgresRole01","SomePassword")
rescue PG::Error => e
    puts e.message     
ensure
    conn.close if conn
end

1
投票

您可以使用

#finish
#close
,它们只是同一事物的别名。

© www.soinside.com 2019 - 2024. All rights reserved.