@@ -34,11 +34,11 @@ const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org";
34
34
" WHERE locktype = 'transactionid' AND pid <> pg_backend_pid()"
35
35
36
36
#define SQL_XID_ALIVE_80300 \
37
- "SELECT 1 FROM pg_locks WHERE locktype = 'virtualxid'"\
38
- " AND pid <> pg_backend_pid() AND virtualtransaction = ANY($1) LIMIT 1 "
37
+ "SELECT pid FROM pg_locks WHERE locktype = 'virtualxid'"\
38
+ " AND pid <> pg_backend_pid() AND virtualtransaction = ANY($1)"
39
39
#define SQL_XID_ALIVE_80200 \
40
- "SELECT 1 FROM pg_locks WHERE locktype = 'transactionid'"\
41
- " AND pid <> pg_backend_pid() AND transactionid = ANY($1) LIMIT 1 "
40
+ "SELECT pid FROM pg_locks WHERE locktype = 'transactionid'"\
41
+ " AND pid <> pg_backend_pid() AND transactionid = ANY($1)"
42
42
43
43
#define SQL_XID_SNAPSHOT \
44
44
(PQserverVersion(connection) >= 80300 \
@@ -383,6 +383,7 @@ reorg_one_table(const reorg_table *table, const char *orderby)
383
383
const char * params [1 ];
384
384
int num ;
385
385
int i ;
386
+ int num_waiting = 0 ;
386
387
char * vxid ;
387
388
char buffer [12 ];
388
389
StringInfoData sql ;
@@ -509,16 +510,32 @@ reorg_one_table(const reorg_table *table, const char *orderby)
509
510
params [0 ] = vxid ;
510
511
res = execute (SQL_XID_ALIVE , 1 , params );
511
512
num = PQntuples (res );
512
- PQclear (res );
513
513
514
514
if (num > 0 )
515
515
{
516
+ /* Wait for old transactions.
517
+ * Only display the message below when the number of
518
+ * transactions we are waiting on changes (presumably,
519
+ * num_waiting should only go down), so as not to
520
+ * be too noisy.
521
+ */
522
+ if (num != num_waiting )
523
+ {
524
+ elog (NOTICE , "Waiting for %d transactions to finish. First PID: %s" , num , PQgetvalue (res , 0 , 0 ));
525
+ num_waiting = num ;
526
+ }
527
+
528
+ PQclear (res );
516
529
sleep (1 );
517
- continue ; /* wait for old transactions */
530
+ continue ;
531
+ }
532
+ else
533
+ {
534
+ /* All old transactions are finished;
535
+ * go to next step. */
536
+ PQclear (res );
537
+ break ;
518
538
}
519
-
520
- /* ok, go to next step. */
521
- break ;
522
539
}
523
540
524
541
/*
0 commit comments