gpt4 book ai didi

ruby-on-rails - PGconn.connect ....断开连接在哪里?

转载 作者:太空宇宙 更新时间:2023-11-03 18:05:55 24 4
gpt4 key购买 nike

环境:

psql (PostgreSQL) 9.6.3 rails 5.1.1 ruby 2.4.1p111

问题:

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

我能成功做到:

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

我找不到 conn.disconnect 方法。是否存在这样的功能?

最佳答案

.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

关于ruby-on-rails - PGconn.connect ....断开连接在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45716506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com