@ -23,6 +23,7 @@
# include "catalog/pg_class_d.h"
# include "common/logging.h"
# include "fe_utils/connect.h"
# include "libpq-fe.h"
# include "pg_getopt.h"
@ -109,8 +110,7 @@ vacuumlo(const char *database, const struct _param *param)
conn = PQconnectdbParams ( keywords , values , true ) ;
if ( ! conn )
{
fprintf ( stderr , " Connection to database \" %s \" failed \n " ,
database ) ;
pg_log_error ( " connection to database \" %s \" failed " , database ) ;
return - 1 ;
}
@ -129,8 +129,8 @@ vacuumlo(const char *database, const struct _param *param)
/* check to see that the backend connection was successfully made */
if ( PQstatus ( conn ) = = CONNECTION_BAD )
{
fprintf ( stderr , " C onnection to database \" %s \" failed: \n %s " ,
database , PQerrorMessage ( conn ) ) ;
pg_log_error ( " c onnection to database \" %s \" failed: %s " ,
database , PQerrorMessage ( conn ) ) ;
PQfinish ( conn ) ;
return - 1 ;
}
@ -145,8 +145,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , ALWAYS_SECURE_SEARCH_PATH_SQL ) ;
if ( PQresultStatus ( res ) ! = PGRES_TUPLES_OK )
{
fprintf ( stderr , " Failed to set search_path: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to set search_path: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -165,8 +164,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to create temp table: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to create temp table: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -182,8 +180,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to vacuum temp table: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to vacuum temp table: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -212,8 +209,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res ) ! = PGRES_TUPLES_OK )
{
fprintf ( stderr , " Failed to find OID columns: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to find OID columns: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -238,7 +234,7 @@ vacuumlo(const char *database, const struct _param *param)
if ( ! schema | | ! table | | ! field )
{
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
if ( schema ! = NULL )
@ -257,9 +253,8 @@ vacuumlo(const char *database, const struct _param *param)
res2 = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res2 ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to check %s in table %s.%s: \n " ,
field , schema , table ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to check %s in table %s.%s: %s " ,
field , schema , table , PQerrorMessage ( conn ) ) ;
PQclear ( res2 ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
@ -288,8 +283,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , " begin " ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to start transaction: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to start transaction: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -302,7 +296,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " DECLARE CURSOR failed: %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " DECLARE CURSOR failed: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -319,7 +313,7 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , buf ) ;
if ( PQresultStatus ( res ) ! = PGRES_TUPLES_OK )
{
fprintf ( stderr , " FETCH FORWARD failed: %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " FETCH FORWARD failed: %s " , PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -347,8 +341,8 @@ vacuumlo(const char *database, const struct _param *param)
{
if ( lo_unlink ( conn , lo ) < 0 )
{
fprintf ( stderr , " \n Failed to remove lo %u: " , lo ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to remove lo %u: %s " , lo ,
PQerrorMessage ( conn ) ) ;
if ( PQtransactionStatus ( conn ) = = PQTRANS_INERROR )
{
success = false ;
@ -367,8 +361,8 @@ vacuumlo(const char *database, const struct _param *param)
res2 = PQexec ( conn , " commit " ) ;
if ( PQresultStatus ( res2 ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to commit transaction: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to commit transaction: %s " ,
PQerrorMessage ( conn ) ) ;
PQclear ( res2 ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
@ -378,8 +372,8 @@ vacuumlo(const char *database, const struct _param *param)
res2 = PQexec ( conn , " begin " ) ;
if ( PQresultStatus ( res2 ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to start transaction: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to start transaction: %s " ,
PQerrorMessage ( conn ) ) ;
PQclear ( res2 ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
@ -398,8 +392,8 @@ vacuumlo(const char *database, const struct _param *param)
res = PQexec ( conn , " commit " ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
fprintf ( stderr , " Failed to commit transaction: \n " ) ;
fprintf ( stderr , " %s " , PQerrorMessage ( conn ) ) ;
pg_log_error ( " failed to commit transaction: %s " ,
PQerrorMessage ( conn ) ) ;
PQclear ( res ) ;
PQfinish ( conn ) ;
return - 1 ;
@ -471,6 +465,7 @@ main(int argc, char **argv)
const char * progname ;
int optindex ;
pg_logging_init ( argv [ 0 ] ) ;
progname = get_progname ( argv [ 0 ] ) ;
/* Set default parameter values */
@ -512,9 +507,7 @@ main(int argc, char **argv)
param . transaction_limit = strtol ( optarg , NULL , 10 ) ;
if ( param . transaction_limit < 0 )
{
fprintf ( stderr ,
" %s: transaction limit must not be negative (0 disables) \n " ,
progname ) ;
pg_log_error ( " transaction limit must not be negative (0 disables) " ) ;
exit ( 1 ) ;
}
break ;
@ -526,7 +519,7 @@ main(int argc, char **argv)
port = strtol ( optarg , NULL , 10 ) ;
if ( ( port < 1 ) | | ( port > 65535 ) )
{
fprintf ( stderr , " %s: invalid port number: %s\n " , progname , optarg ) ;
pg_log_error ( " invalid port number: %s " , optarg ) ;
exit ( 1 ) ;
}
param . pg_port = pg_strdup ( optarg ) ;
@ -552,7 +545,7 @@ main(int argc, char **argv)
/* No database given? Show usage */
if ( optind > = argc )
{
fprintf ( stderr , " vacuumlo: missing required argument: database name\n " ) ;
pg_log_error ( " missing required argument: database name " ) ;
fprintf ( stderr , _ ( " Try \" %s --help \" for more information. \n " ) , progname ) ;
exit ( 1 ) ;
}