@@ -325,7 +325,7 @@ repack_all_databases(const char *orderby)
325
325
}
326
326
}
327
327
328
- PQclear (result );
328
+ CLEARPGRES (result );
329
329
}
330
330
331
331
/* result is not copied */
@@ -435,7 +435,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
435
435
}
436
436
goto cleanup ;
437
437
}
438
- PQclear (res );
438
+ CLEARPGRES (res );
439
439
440
440
/* Disable statement timeout. */
441
441
command ("SET statement_timeout = 0" , 0 , NULL );
@@ -560,8 +560,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
560
560
ret = true;
561
561
562
562
cleanup :
563
- if (res )
564
- PQclear (res );
563
+ CLEARPGRES (res );
565
564
disconnect ();
566
565
termStringInfo (& sql );
567
566
return ret ;
@@ -586,7 +585,7 @@ apply_log(PGconn *conn, const repack_table *table, int count)
586
585
"SELECT repack.repack_apply($1, $2, $3, $4, $5, $6)" ,
587
586
6 , params );
588
587
result = atoi (PQgetvalue (res , 0 , 0 ));
589
- PQclear (res );
588
+ CLEARPGRES (res );
590
589
591
590
return result ;
592
591
}
@@ -683,7 +682,6 @@ rebuild_indexes(const repack_table *table)
683
682
elog (WARNING , "Error sending async query: %s\n%s" ,
684
683
index_jobs [i ].create_index ,
685
684
PQerrorMessage (workers .conns [i ]));
686
- PQclear (res );
687
685
have_error = true;
688
686
goto cleanup ;
689
687
}
@@ -692,15 +690,14 @@ rebuild_indexes(const repack_table *table)
692
690
* available. That's OK, we'll get to them later.
693
691
*/
694
692
}
695
- PQclear (res );
693
+ CLEARPGRES (res );
696
694
697
695
if (num_workers > 1 )
698
696
{
699
697
int freed_worker = -1 ;
700
698
int ret ;
701
699
702
700
/* Prefer poll() over select(), following PostgreSQL custom. */
703
- #undef HAVE_POLL
704
701
#ifdef HAVE_POLL
705
702
struct pollfd * input_fds ;
706
703
@@ -749,6 +746,8 @@ rebuild_indexes(const repack_table *table)
749
746
if (ret < 0 && errno != EINTR )
750
747
elog (ERROR , "poll() failed: %d, %d" , ret , errno );
751
748
749
+ elog (DEBUG2 , "Poll returned: %d" , ret );
750
+
752
751
for (i = 0 ; i < num_indexes ; i ++ )
753
752
{
754
753
if (index_jobs [i ].status == INPROGRESS )
@@ -774,11 +773,10 @@ rebuild_indexes(const repack_table *table)
774
773
{
775
774
elog (WARNING , "Error with create index: %s" ,
776
775
PQerrorMessage (workers .conns [index_jobs [i ].worker_idx ]));
777
- PQclear (res );
778
776
have_error = true;
779
777
goto cleanup ;
780
778
}
781
- PQclear (res );
779
+ CLEARPGRES (res );
782
780
}
783
781
784
782
/* We are only going to re-queue one worker, even
@@ -825,6 +823,7 @@ rebuild_indexes(const repack_table *table)
825
823
}
826
824
827
825
cleanup :
826
+ CLEARPGRES (res );
828
827
return (!have_error );
829
828
}
830
829
@@ -835,7 +834,7 @@ rebuild_indexes(const repack_table *table)
835
834
static void
836
835
repack_one_table (const repack_table * table , const char * orderby )
837
836
{
838
- PGresult * res ;
837
+ PGresult * res = NULL ;
839
838
const char * params [2 ];
840
839
int num ;
841
840
int num_waiting = 0 ;
@@ -900,11 +899,10 @@ repack_one_table(const repack_table *table, const char *orderby)
900
899
(errcode (E_PG_COMMAND ),
901
900
errmsg ("trigger %s conflicted for %s" ,
902
901
PQgetvalue (res , 0 , 0 ), table -> target_name )));
903
- PQclear (res );
904
902
have_error = true;
905
903
goto cleanup ;
906
904
}
907
- PQclear (res );
905
+ CLEARPGRES (res );
908
906
909
907
command (table -> create_pktype , 0 , NULL );
910
908
command (table -> create_log , 0 , NULL );
@@ -928,13 +926,12 @@ repack_one_table(const repack_table *table, const char *orderby)
928
926
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
929
927
{
930
928
printf ("%s" , PQerrorMessage (conn2 ));
931
- PQclear (res );
932
929
have_error = true;
933
930
goto cleanup ;
934
931
}
935
932
buffer [0 ] = '\0' ;
936
933
strncat (buffer , PQgetvalue (res , 0 , 0 ), sizeof (buffer ) - 1 );
937
- PQclear (res );
934
+ CLEARPGRES (res );
938
935
939
936
/*
940
937
* Not using lock_access_share() here since we know that
@@ -995,11 +992,10 @@ repack_one_table(const repack_table *table, const char *orderby)
995
992
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
996
993
{
997
994
elog (WARNING , "Error with LOCK TABLE: %s" , PQerrorMessage (conn2 ));
998
- PQclear (res );
999
995
have_error = true;
1000
996
goto cleanup ;
1001
997
}
1002
- PQclear (res );
998
+ CLEARPGRES (res );
1003
999
}
1004
1000
1005
1001
/* Turn conn2 back into blocking mode for further non-async use. */
@@ -1034,11 +1030,10 @@ repack_one_table(const repack_table *table, const char *orderby)
1034
1030
{
1035
1031
elog (WARNING , "Unable to allocate vxid, length: %d\n" ,
1036
1032
PQgetlength (res , 0 , 0 ));
1037
- PQclear (res );
1038
1033
have_error = true;
1039
1034
goto cleanup ;
1040
1035
}
1041
- PQclear (res );
1036
+ CLEARPGRES (res );
1042
1037
1043
1038
/* Delete any existing entries in the log table now, since we have not
1044
1039
* yet run the CREATE TABLE ... AS SELECT, which will take in all existing
@@ -1079,6 +1074,7 @@ repack_one_table(const repack_table *table, const char *orderby)
1079
1074
have_error = true;
1080
1075
goto cleanup ;
1081
1076
}
1077
+ CLEARPGRES (res );
1082
1078
1083
1079
/*
1084
1080
* 4. Apply log to temp table until no tuples are left in the log
@@ -1109,15 +1105,15 @@ repack_one_table(const repack_table *table, const char *orderby)
1109
1105
num_waiting = num ;
1110
1106
}
1111
1107
1112
- PQclear (res );
1108
+ CLEARPGRES (res );
1113
1109
sleep (1 );
1114
1110
continue ;
1115
1111
}
1116
1112
else
1117
1113
{
1118
1114
/* All old transactions are finished;
1119
1115
* go to next step. */
1120
- PQclear (res );
1116
+ CLEARPGRES (res );
1121
1117
break ;
1122
1118
}
1123
1119
}
@@ -1169,6 +1165,7 @@ repack_one_table(const repack_table *table, const char *orderby)
1169
1165
}
1170
1166
1171
1167
cleanup :
1168
+ CLEARPGRES (res );
1172
1169
termStringInfo (& sql );
1173
1170
if (vxid )
1174
1171
free (vxid );
@@ -1210,7 +1207,7 @@ kill_ddl(PGconn *conn, Oid relid, bool terminate)
1210
1207
"Canceled %d unsafe queries. Terminating any remaining PIDs." ,
1211
1208
PQntuples (res ));
1212
1209
1213
- PQclear (res );
1210
+ CLEARPGRES (res );
1214
1211
printfStringInfo (& sql , KILL_COMPETING_LOCKS , relid );
1215
1212
res = pgut_execute (conn , sql .data , 0 , NULL );
1216
1213
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -1225,7 +1222,7 @@ kill_ddl(PGconn *conn, Oid relid, bool terminate)
1225
1222
else
1226
1223
elog (DEBUG2 , "No competing DDL to cancel." );
1227
1224
1228
- PQclear (res );
1225
+ CLEARPGRES (res );
1229
1226
termStringInfo (& sql );
1230
1227
1231
1228
return ret ;
@@ -1285,21 +1282,21 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
1285
1282
res = pgut_execute_elevel (conn , sql .data , 0 , NULL , DEBUG2 );
1286
1283
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
1287
1284
{
1288
- PQclear (res );
1285
+ CLEARPGRES (res );
1289
1286
break ;
1290
1287
}
1291
1288
else if (sqlstate_equals (res , SQLSTATE_QUERY_CANCELED ))
1292
1289
{
1293
1290
/* retry if lock conflicted */
1294
- PQclear (res );
1291
+ CLEARPGRES (res );
1295
1292
pgut_rollback (conn );
1296
1293
continue ;
1297
1294
}
1298
1295
else
1299
1296
{
1300
1297
/* exit otherwise */
1301
1298
elog (WARNING , "%s" , PQerrorMessage (connection ));
1302
- PQclear (res );
1299
+ CLEARPGRES (res );
1303
1300
ret = false;
1304
1301
break ;
1305
1302
}
@@ -1371,21 +1368,21 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
1371
1368
res = pgut_execute_elevel (conn , lock_query , 0 , NULL , DEBUG2 );
1372
1369
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
1373
1370
{
1374
- PQclear (res );
1371
+ CLEARPGRES (res );
1375
1372
break ;
1376
1373
}
1377
1374
else if (sqlstate_equals (res , SQLSTATE_QUERY_CANCELED ))
1378
1375
{
1379
1376
/* retry if lock conflicted */
1380
- PQclear (res );
1377
+ CLEARPGRES (res );
1381
1378
pgut_rollback (conn );
1382
1379
continue ;
1383
1380
}
1384
1381
else
1385
1382
{
1386
1383
/* exit otherwise */
1387
1384
printf ("%s" , PQerrorMessage (connection ));
1388
- PQclear (res );
1385
+ CLEARPGRES (res );
1389
1386
ret = false;
1390
1387
break ;
1391
1388
}
0 commit comments