1.空闲长事务连接
使用idle_in_transaction_session_timeout参数,默认值是0,不开启,例如配置为5分钟。
idle_in_transaction_session_timeout = 5min
注意:该参数对idle正常连接无影响。
2.空闲连接
可使用扩展插件pg_timeout插件,配置postgresql.conf
shared_preload_libraries = 'pg_timeout'
pg_timeout.naptime=60 #单位为秒
pg_timeout.idle_session_timeout=60 #单位为秒
3.异常连接
客户端异常断开的连接,可配置postgresql.conf
tcp_keepalives_idle = 60
tcp_keepalives_interval = 20
tcp_keepalives_count = 3
注意:不配置会使用操作系统默认值。
本文介绍了如何通过idle_in_transaction_session_timeout配置来管理空闲长事务连接,使用pg_timeout插件处理空闲连接,以及设置tcp_keepalives参数应对异常断开。重点讲解了postgresql配置以提升数据库连接效率和稳定性。

1016

被折叠的 条评论
为什么被折叠?



