Re: libpq - prevent automatic reconnect

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: icholy <ilia(dot)choly(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: libpq - prevent automatic reconnect
Date: 2012-12-05 18:56:22
Message-ID: 10057.1354733782@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

icholy <ilia(dot)choly(at)gmail(dot)com> writes:
> libpq will automatically reconnect if the connection is dropped.

No it won't. You'd have to do a PQreset() to make that happen.

> auto con = PQconnectdb("info"); while (true) { PQclear(PQexec(con,
> "SELECT * FROM foo LIMIT 1"));
> std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "here
> " << i++ << std::endl; }

This test case doesn't prove much of anything, since it's not examining
the PGresult to see if it was OK or an error.

> $ sudo ifconfig eth0 down
> output stops

I suspect this action isn't dropping the TCP connection. It's only
equivalent to a momentary glitch in your network connectivity --- and
you'd be very unhappy if that caused TCP connections to go down, because
networks have glitches all the time. Generally, the operating system
tries hard to prevent applications from even knowing that a glitch
happened. (Connections will time out eventually if connectivity doesn't
come back, but typically such timeouts are many minutes. Possibly
whatever your real complaint is could be addressed by twiddling the TCP
timeout parameters for the socket.)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message akp geek 2012-12-05 20:12:00 wal archiving question
Previous Message James Cowell 2012-12-05 18:56:06 Re: Corrupt indexes on slave when using pg_bulkload on master