Re: Making a Persistent Postgres Connection

Поиск
Список
Период
Сортировка
От David Stanaway
Тема Re: Making a Persistent Postgres Connection
Дата
Msg-id 1095873463.2101.38.camel@david.dialmex.net
обсуждение исходный текст
Ответ на Making a Persistent Postgres Connection  (Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>)
Список pgsql-admin
Check out the
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
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 = 1, idle = 500, intvl = 500, cnt = 3;

conn = 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
>
> 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 <pgsql/libpq-fe.h>
>
> 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.
>
> I hope someone to help me to solve this, please.
>
> My best regards.
>
>
> _________________________________________________________
> Do You Yahoo!?
> Información de Estados Unidos y América Latina, en Yahoo! Noticias.
> Visítanos en http://noticias.espanol.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
David Stanaway <david@stanaway.net>

В списке pgsql-admin по дате отправления:

Предыдущее
От: G u i d o B a r o s i o
Дата:
Сообщение: Re: Important Question.
Следующее
От: Michael Adler
Дата:
Сообщение: Re: analytics