如何通过 keepalive postgreSQL 断开 TCP/IP 连接而不更改寄存器中的任何内容?
我有一个使用客户端-服务器结构和 PostgreSQL 8.4 的系统。 我的问题是,如果客户端正在编辑记录并失去与服务器的连接,则仍会考虑 TCPIP 连接!因此,记录在我的数据库中保留分配给客户端。 我需要在几分钟内免费编辑这些记录。因此,我在“postgresql.conf”中设置了 KEEPALIVE 配置:
tcp_keepalives_idle = 60 # TCP_KEEPIDLE, in seconds;
tcp_keepalives_interval = 60 # TCP_KEEPINTVL, in seconds;
tcp_keepalives_count = 5 # TCP_KEEPCNT
进行这些设置并重新启动服务器后,系统继续以相同的方式运行:仅在两个小时后断开 TCPIP 连接,然后释放 PostgreSQL 中的记录。我需要一种高效且安全的方式让 PostgreSQL 明白它必须按照配置断开这些连接!
I have a system working with the client-server structure and PostgreSQL 8.4.
My problem is that if a client is editing a record and lose his connection to the server, the TCPIP connection is still considered! So, the record stay allocated for the client in my database.
I need the records to be free for edit in a few minutes. Therefore I set the KEEPALIVE configuration in my "postgresql.conf":
tcp_keepalives_idle = 60 # TCP_KEEPIDLE, in seconds;
tcp_keepalives_interval = 60 # TCP_KEEPINTVL, in seconds;
tcp_keepalives_count = 5 # TCP_KEEPCNT
After making these settings and restart the server the system continues to function the same way: Just breaks the connection TCPIP after two hours and then deallocates the records in PostgreSQL. I need an efficient and safe way for the PostgreSQL to understand that it has to break these connections as configured!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 上的 PostgreSQL 不支持一个连接的 keepalive 设置。它使用的是
setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, ...)
,这是恕我直言 Linux 特定的。您可以为 Postgres 实施补丁,以便它使用
SIO_KEEPALIVE_VALS
。在StreamConnection
函数的src/backend/libpq/pqcomm.c
中,有类似的内容。或者,您可以使用 KeepAliveInterval 和 KeepAliveTime 设置(在 Windows Vista 及更高版本中计数始终为 10)。
PostgreSQL on Windows does not support keepalive settings for one connection. It is using
setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, ...)
which is IMHO Linux-specific.You can implement a patch for Postgres so it uses
SIO_KEEPALIVE_VALS
. Something like this insrc/backend/libpq/pqcomm.c
inStreamConnection
function.Or you can set system-wide settings in Windows registry
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
using KeepAliveInterval and KeepAliveTime settings (count is always 10 on Windows Vista and later).