How to break connections TCP/IP by keepalive postgreSQL without changing anything in the register?

心已入冬 提交于 2019-12-04 20:47:12

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 in src/backend/libpq/pqcomm.c in StreamConnection function.

{
    DWORD bytesReturned = 0;
    tcp_keepalive vals;
    vals.keepalivetime = 60*1000; /* milliseconds */
    vals.keepaliveinterval = 60*1000; /* milliseconds */
    vals.onoff = 1;
    err = WSAIoctl(
        port->sock,
        SIO_KEEPALIVE_VALS,
        (char *)&vals, sizeof(vals), NULL, 0,
        &bytesReturned, NULL, NULL);
    if (err == -1) {
        elog(LOG, "WSAIoctl(SIO_KEEPALIVE_VALS) failed: %m");
    }
}

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!