环境:
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/