pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Making a Persistent Postgres Connection
3+ messages / 3 participants
[nested] [flat]

* Making a Persistent Postgres Connection
@ 2004-09-22 13:59 Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>
  2004-09-22 15:08 ` Re: Making a Persistent Postgres Connection Tom Lane <tgl@sss.pgh.pa.us>
  2004-09-22 17:17 ` Re: Making a Persistent Postgres Connection David Stanaway <david@stanaway.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Aryan Ariel Rodriguez Chalas @ 2004-09-22 13:59 UTC (permalink / raw)
  To: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Making a Persistent Postgres Connection
  2004-09-22 13:59 Making a Persistent Postgres Connection Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>
@ 2004-09-22 15:08 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2004-09-22 15:08 UTC (permalink / raw)
  To: Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>; +Cc: pgsql-admin

Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com> writes:
> 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'm betting there is a firewall with a short idle-connection timeout
between you and the database.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Making a Persistent Postgres Connection
  2004-09-22 13:59 Making a Persistent Postgres Connection Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>
@ 2004-09-22 17:17 ` David Stanaway <david@stanaway.net>
  1 sibling, 0 replies; 3+ messages in thread

From: David Stanaway @ 2004-09-22 17:17 UTC (permalink / raw)
  To: Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>; +Cc: 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>



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-09-22 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 13:59 Making a Persistent Postgres Connection Aryan Ariel Rodriguez Chalas <wimogan@yahoo.com>
2004-09-22 15:08 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-09-22 17:17 ` David Stanaway <david@stanaway.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox