【问题标题】:PostgreSQL advisory lock stays after user disconnect用户断开连接后 PostgreSQL 咨询锁仍然存在
【发布时间】:2016-12-07 13:26:51
【问题描述】:

我有一个实现会话级咨询锁定的后端应用程序。但是,如果客户端突然失去连接(例如在连接时强制重新启动),咨询锁将保持在那里并且不会消失。

有没有办法让锁在连接断开后总是过期?

谢谢。

【问题讨论】:

  • While a flag stored in a table could be used for the same purpose, advisory locks are faster, avoid table bloat, and are automatically cleaned up by the server at the end of the session. postgresql.org/docs/9.1/static/explicit-locking.html 所以只要你的连接超时就可以了。

标签: postgresql postgresql-9.4


【解决方案1】:

我假设锁仍然存在,因为后端进程仍然存在。

除非服务器尝试联系客户端,否则操作系统可能需要很长时间才能检测到客户端套接字不再存在,此时 PostgreSQL 后端将被终止。

您可以将 PostgreSQL 参数 tcp_keepalives_idle 设置为较小的值,以减少检测到死连接的时间。

【讨论】:

    猜你喜欢
    • 2021-05-31
    • 2016-12-15
    • 1970-01-01
    • 2017-11-06
    • 2017-05-04
    • 2015-06-04
    • 2015-08-27
    • 2020-12-31
    • 1970-01-01
    相关资源
    最近更新 更多