@@ -186,6 +186,7 @@ static bool kill_ddl(PGconn *conn, Oid relid, bool terminate);
186
186
static bool lock_access_share (PGconn * conn , Oid relid , const char * target_name );
187
187
188
188
#define SQLSTATE_INVALID_SCHEMA_NAME "3F000"
189
+ #define SQLSTATE_UNDEFINED_FUNCTION "42883"
189
190
#define SQLSTATE_QUERY_CANCELED "57014"
190
191
191
192
static bool sqlstate_equals (PGresult * res , const char * state )
@@ -364,22 +365,10 @@ repack_all_databases(const char *orderby)
364
365
365
366
dbname = PQgetvalue (result , i , 0 );
366
367
367
- if (pgut_log_level >= INFO )
368
- {
369
- printf ("%s: repack database \"%s\"\n" , PROGRAM_NAME , dbname );
370
- fflush (stdout );
371
- }
372
-
368
+ elog (INFO , "repacking database \"%s\"" , dbname );
373
369
ret = repack_one_database (orderby , errbuf , sizeof (errbuf ));
374
-
375
- if (pgut_log_level >= INFO )
376
- {
377
- if (ret )
378
- printf ("\n" );
379
- else
380
- printf (" ... skipped: %s\n" , errbuf );
381
- fflush (stdout );
382
- }
370
+ if (!ret )
371
+ elog (INFO , "database \"%s\" skipped: %s" , dbname , errbuf );
383
372
}
384
373
385
374
CLEARPGRES (result );
@@ -477,12 +466,16 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
477
466
}
478
467
else
479
468
{
480
- if (sqlstate_equals (res , SQLSTATE_INVALID_SCHEMA_NAME ))
469
+ if (sqlstate_equals (res , SQLSTATE_INVALID_SCHEMA_NAME )
470
+ || sqlstate_equals (res , SQLSTATE_UNDEFINED_FUNCTION ))
481
471
{
482
- /* Schema repack does not exist. Skip the database. */
472
+ /* Schema repack does not exist, or version too old (version
473
+ * functions not found). Skip the database.
474
+ */
483
475
if (errbuf )
484
476
snprintf (errbuf , errsize ,
485
- "%s is not installed in the database" , PROGRAM_NAME );
477
+ "%s %s is not installed in the database" ,
478
+ PROGRAM_NAME , PROGRAM_VERSION );
486
479
}
487
480
else
488
481
{
@@ -547,19 +540,9 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
547
540
/* on error skip the database */
548
541
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
549
542
{
550
- if (sqlstate_equals (res , SQLSTATE_INVALID_SCHEMA_NAME ))
551
- {
552
- /* Schema repack does not exist. Skip the database. */
553
- if (errbuf )
554
- snprintf (errbuf , errsize ,
555
- "%s is not installed in the database" , PROGRAM_NAME );
556
- }
557
- else
558
- {
559
- /* Return the error message otherwise */
560
- if (errbuf )
561
- snprintf (errbuf , errsize , "%s" , PQerrorMessage (connection ));
562
- }
543
+ /* Return the error message otherwise */
544
+ if (errbuf )
545
+ snprintf (errbuf , errsize , "%s" , PQerrorMessage (connection ));
563
546
goto cleanup ;
564
547
}
565
548
@@ -935,6 +918,8 @@ repack_one_table(const repack_table *table, const char *orderby)
935
918
936
919
initStringInfo (& sql );
937
920
921
+ elog (INFO , "repacking table \"%s\"" , table -> target_name );
922
+
938
923
elog (DEBUG2 , "---- repack_one_table ----" );
939
924
elog (DEBUG2 , "target_name : %s" , table -> target_name );
940
925
elog (DEBUG2 , "target_oid : %u" , table -> target_oid );
@@ -1029,12 +1014,6 @@ repack_one_table(const repack_table *table, const char *orderby)
1029
1014
* pg_locks momentarily.
1030
1015
*/
1031
1016
res = pgut_execute (conn2 , "SELECT pg_backend_pid()" , 0 , NULL );
1032
- if (PQresultStatus (res ) != PGRES_TUPLES_OK )
1033
- {
1034
- printf ("%s" , PQerrorMessage (conn2 ));
1035
- have_error = true;
1036
- goto cleanup ;
1037
- }
1038
1017
buffer [0 ] = '\0' ;
1039
1018
strncat (buffer , PQgetvalue (res , 0 , 0 ), sizeof (buffer ) - 1 );
1040
1019
CLEARPGRES (res );
0 commit comments