环境:
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 方法。有这样的功能吗?
.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