Marek Peca <marek(at)duch(dot)cz> writes:
> The problem: most of time, everything works fine, hundreds of successful
> or even timed-out selects() get handled without any problem. But time to
> time (eg. after several hours), the select() call returns with a timeout
> and then, a request to the opened PQconn (simple query) gets stuck, the
> call hangs and never returns.
What that sounds like is a network-level problem. In particular, if
there's a NAT-capable router between your client and server machines,
it's probably dropping the connection after a certain period of
inactivity. You may be able to fix this within Postgres by adjusting
the server's tcp_keepalives_idle setting. If the server is on a
platform that doesn't support changing the keepalive interval, the
only recourse is to fix the router.
regards, tom lane