specify server's port in conf file since at least on one of my

machines it's not what libpq expects.  (Required by upgrade from 8.4
to 9.1.)
This commit is contained in:
Eric House 2013-07-02 05:46:48 -07:00
parent 9ceb1615b3
commit 3d18e5832e
2 changed files with 16 additions and 5 deletions

View file

@ -757,7 +757,9 @@ DBMgr::execSql( const char* const query )
PGresult* result = PQexec( getThreadConn(), query ); PGresult* result = PQexec( getThreadConn(), query );
bool ok = PGRES_COMMAND_OK == PQresultStatus(result); bool ok = PGRES_COMMAND_OK == PQresultStatus(result);
if ( !ok ) { if ( !ok ) {
logf( XW_LOGERROR, "PQexec=>%s;%s", PQresStatus(PQresultStatus(result)), PQresultErrorMessage(result) ); logf( XW_LOGERROR, "PQexec=>%s;%s", PQresStatus(PQresultStatus(result)),
PQresultErrorMessage(result) );
assert( 0 );
} }
PQclear( result ); PQclear( result );
return ok; return ok;
@ -1143,12 +1145,19 @@ DBMgr::getThreadConn( void )
if ( NULL == conn ) { if ( NULL == conn ) {
char buf[128]; char buf[128];
int len = snprintf( buf, sizeof(buf), "dbname = " ); int port;
if ( !RelayConfigs::GetConfigs()-> if ( !RelayConfigs::GetConfigs()->GetValueFor( "DB_NAME", buf,
GetValueFor( "DB_NAME", &buf[len], sizeof(buf)-len ) ) { sizeof(buf) ) ) {
assert( 0 ); assert( 0 );
} }
conn = PQconnectdb( buf ); if ( !RelayConfigs::GetConfigs()->GetValueFor( "DB_PORT", &port ) ) {
assert( 0 );
}
string params;
string_printf( params, "dbname = %s ", buf );
string_printf( params, "port = %d ", port );
conn = PQconnectdb( params.c_str() );
pthread_setspecific( m_conn_key, conn ); pthread_setspecific( m_conn_key, conn );
} }
return conn; return conn;

View file

@ -56,6 +56,8 @@ SERVERNAME=eehouse.org
# name of the database. (Table names are hard-coded.) # name of the database. (Table names are hard-coded.)
DB_NAME=xwgames DB_NAME=xwgames
# UDP port postgres server is listening on
DB_PORT=5433
# Initial level of logging. See xwrelay_priv.h for values. Currently # Initial level of logging. See xwrelay_priv.h for values. Currently
# 0 means errors only, 1 info, 2 verbose and 3 very verbose. # 0 means errors only, 1 info, 2 verbose and 3 very verbose.