when we get a fatal error from postgres server, try killing then

recreating the connection.  This is untested, as fatal errors are
rare.
This commit is contained in:
Eric House 2013-07-03 07:36:15 -07:00
parent 3364dcbf46
commit 8e12a8ef84
2 changed files with 14 additions and 0 deletions

View file

@ -762,6 +762,7 @@ DBMgr::execSql( const char* const query )
logf( XW_LOGERROR, "%s: PQexec=>%s;%s", __func__,
PQresStatus(PQresultStatus(result)),
PQresultErrorMessage(result) );
clearThreadConn();
usleep( 20000 );
}
PQclear( result );
@ -1143,6 +1144,18 @@ destr_function( void* conn )
PQfinish( pgconn );
}
void
DBMgr::clearThreadConn()
{
logf( XW_LOGERROR, "%s called()", __func__ );
PGconn* conn = (PGconn*)pthread_getspecific( m_conn_key );
if ( NULL != conn ) {
PQfinish( conn );
int result = pthread_setspecific( m_conn_key, NULL );
assert( 0 == result );
}
}
PGconn*
DBMgr::getThreadConn( void )
{

View file

@ -135,6 +135,7 @@ class DBMgr {
int byteaIndex, unsigned char* buf, size_t* buflen );
PGconn* getThreadConn( void );
void clearThreadConn();
void conn_key_alloc();
pthread_key_t m_conn_key;