Skip site navigation (1) Skip section navigation (2)

Re: Keep alive in libpq

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Keep alive in libpq
Date: 2009-05-27 13:27:44
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Pavel Golub wrote:
> Hello, postgresmen.
> I found solution how to implement keep alive through sockets in
> archive:
> However, it is dated 2006 year and I am wonder if this is for real? 

setsockopt has been around since at least the early 90s.  It is for real.

> At least in Windows environment?
> If not are there any solutions?

Windows 2000 and later.
Search the page for "SIO_KEEPALIVE_VALS".

Make sure to test the below because I didn't :)

#include <Winsock2.h>
#include <Mstcpip.h> /* struct tcp_keepalive */

int r;
struct tcp_keepalive ka;

/* enable or disable (same as SO_KEEPALIVE) */
ka.onoff = 1;

/* milliseconds (same as TCP_KEEPIDLE) */
ka.keepalivetime = 60000;

/* milliseconds (same as TCP_KEEPINTVL) */
ka.keepaliveinterval = 3000;

/* configure keep-alives for 'conn' */
r = WSAIoctl((SOCKET) PQsocket(conn), SIO_KEEPALIVE_VALS,
   &ka, (DWORD) sizeof(ka), NULL, 0, &dw, NULL, NULL);

if (r == SOCKET_ERROR)
   // failed, check WSAGetLastError()

Apparently, you can also enable keep-alives using the standard 
setsockopt(...SO_KEEPALIVE...);  Although, the other knobs are only 
exposed through WSAIoctl.  When using SO_KEEPALIVE, the default 
keep-alive settings are used ... keep-alive timeout of 2 hours followed 
by a 1 second probe.  They can still be adjusted via WSAIoctl.

Andrew Chernow
eSilo, LLC
every bit counts

In response to

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2009-05-27 13:33:28
Subject: Re: PostgreSQL Developer meeting minutes up
Previous:From: Bruce MomjianDate: 2009-05-27 13:16:18
Subject: Re: A couple of gripes about the gettext plurals patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group