X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 98738329C82 for ; Wed, 22 Sep 2004 18:17:57 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58159-07 for ; Wed, 22 Sep 2004 17:17:51 +0000 (GMT) Received: from mail.dialmex.net (67.107.77.98.ptr.us.xo.net [67.107.77.98]) by svr1.postgresql.org (Postfix) with ESMTP id 0AA05329E8D for ; Wed, 22 Sep 2004 18:17:50 +0100 (BST) Received: from david.dialmex.net (dmxnocws13.dialmex.net [67.107.77.78]) by mail.dialmex.net (Postfix) with ESMTP id 72067EE997; Wed, 22 Sep 2004 12:17:47 -0500 (CDT) Received: by david.dialmex.net (Postfix, from userid 4001) id 3C92C14465E3; Wed, 22 Sep 2004 12:17:43 -0500 (CDT) Subject: Re: Making a Persistent Postgres Connection From: David Stanaway To: Aryan Ariel Rodriguez Chalas Cc: pgsql-admin@postgresql.org In-Reply-To: <20040922135939.86779.qmail@web41015.mail.yahoo.com> References: <20040922135939.86779.qmail@web41015.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: Wed, 22 Sep 2004 12:17:43 -0500 Message-Id: <1095873463.2101.38.camel@david.dialmex.net> Mime-Version: 1.0 X-Mailer: Evolution 2.0.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/217 X-Sequence-Number: 14920 Check out the=20 SO_KEEPALIVE option for the socket. I am not sure there is a safe way to do this with the PGconn handle, but looking at the header there is an internal struct=20 pg_conn you can look at include/postgresql/internal/libpq-int.h And the socket file handle is the sock member. By default, keepalive only kicks in after 2 hours, but you can change it to some time less than you firewall times out. Check out the man pages for: setsockopt(2) tcp(7) You might end up with something like this: PGconn *conn; int one =3D 1, idle =3D 500, intvl =3D 500, cnt =3D 3; conn =3D PQconnectdb(conninfo); setsockopt(conn->sock, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)); setsockopt(conn->sock, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); setsockopt(conn->sock, SOL_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); setsockopt(conn->sock, SOL_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); The code will not be particularly portable. You would be better off increasing the timeout on the firewall, or ensuring there was some activity before the timeout. On Wed, 2004-09-22 at 08:59 -0500, Aryan Ariel Rodriguez Chalas wrote: > Hi everybody >=20 > I really would apreciate if somebody could help me on > how to make a persistent connection to a Remote > Database using "C Language". I work in "Linux" > Operating System and use the header >=20 > I have any problems when I make a connection to the > Local Database, but every time I make a postgres > connection (via Internet) to a Remote Database, I find > the problem that the connections falls down every 10 > minutes more or less. >=20 > I hope someone to help me to solve this, please. >=20 > My best regards. >=20 >=20 > _________________________________________________________ > Do You Yahoo!? > Informaci=F3n de Estados Unidos y Am=E9rica Latina, en Yahoo! Noticias. > Vis=EDtanos en http://noticias.espanol.yahoo.com >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >=20 --=20 David Stanaway