[tpop3d-discuss]Database connection

Daniel Tiefnig tpop3d at inode.at
Wed, 30 Nov 2005 11:36:09 +0100

ohp@pyrenet.fr wrote:
> Would  it be hard to add kindda ping to see if connection is alive et
>  reconnect to it in case not?

Sure not.

> Where should I look to add such a beast?

auth_pgsql.c would be the place to implement this. There are three calls
to PQexec in this file. (one in each of auth_pgsql_new_apop,
auth_pgsql_new_user_pass and auth_pgsql_onlogin) You could call
PQstatus() after a query failed, followed by PQreset() if status is not
"CONNECTION_OK". After that you may want to retry your query, so this
could be put into a loop, but take care to don't loop forever. Kind of 3
retries should be sufficient, with a little sleep between them.
Maybe it would be the best to put the calls to PQexec() inside a
function (like "do_PQexec" or something) so this hasn't to be
implemented three times.

If you need help to implement this, feel free to ask. I don't have much
spare time at the moment, but I'll do what I can.

The pgsql C API is explained at
It has lots of usefull information and also some sample programs.