Print a status message while waiting on old transactions to finish, including a backend PID we are waiting on, so that the user knows pg_reorg is hung and can do something about it.
This commit is contained in:
parent
2ba1a575ac
commit
612495ecd6
@ -34,11 +34,11 @@ const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org";
|
|||||||
" WHERE locktype = 'transactionid' AND pid <> pg_backend_pid()"
|
" WHERE locktype = 'transactionid' AND pid <> pg_backend_pid()"
|
||||||
|
|
||||||
#define SQL_XID_ALIVE_80300 \
|
#define SQL_XID_ALIVE_80300 \
|
||||||
"SELECT 1 FROM pg_locks WHERE locktype = 'virtualxid'"\
|
"SELECT pid FROM pg_locks WHERE locktype = 'virtualxid'"\
|
||||||
" AND pid <> pg_backend_pid() AND virtualtransaction = ANY($1) LIMIT 1"
|
" AND pid <> pg_backend_pid() AND virtualtransaction = ANY($1)"
|
||||||
#define SQL_XID_ALIVE_80200 \
|
#define SQL_XID_ALIVE_80200 \
|
||||||
"SELECT 1 FROM pg_locks WHERE locktype = 'transactionid'"\
|
"SELECT pid FROM pg_locks WHERE locktype = 'transactionid'"\
|
||||||
" AND pid <> pg_backend_pid() AND transactionid = ANY($1) LIMIT 1"
|
" AND pid <> pg_backend_pid() AND transactionid = ANY($1)"
|
||||||
|
|
||||||
#define SQL_XID_SNAPSHOT \
|
#define SQL_XID_SNAPSHOT \
|
||||||
(PQserverVersion(connection) >= 80300 \
|
(PQserverVersion(connection) >= 80300 \
|
||||||
@ -383,6 +383,7 @@ reorg_one_table(const reorg_table *table, const char *orderby)
|
|||||||
const char *params[1];
|
const char *params[1];
|
||||||
int num;
|
int num;
|
||||||
int i;
|
int i;
|
||||||
|
int num_waiting = 0;
|
||||||
char *vxid;
|
char *vxid;
|
||||||
char buffer[12];
|
char buffer[12];
|
||||||
StringInfoData sql;
|
StringInfoData sql;
|
||||||
@ -509,17 +510,33 @@ reorg_one_table(const reorg_table *table, const char *orderby)
|
|||||||
params[0] = vxid;
|
params[0] = vxid;
|
||||||
res = execute(SQL_XID_ALIVE, 1, params);
|
res = execute(SQL_XID_ALIVE, 1, params);
|
||||||
num = PQntuples(res);
|
num = PQntuples(res);
|
||||||
PQclear(res);
|
|
||||||
|
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
{
|
{
|
||||||
sleep(1);
|
/* Wait for old transactions.
|
||||||
continue; /* wait for old transactions */
|
* Only display the message below when the number of
|
||||||
|
* transactions we are waiting on changes (presumably,
|
||||||
|
* num_waiting should only go down), so as not to
|
||||||
|
* be too noisy.
|
||||||
|
*/
|
||||||
|
if (num != num_waiting)
|
||||||
|
{
|
||||||
|
elog(NOTICE, "Waiting for %d transactions to finish. First PID: %s", num, PQgetvalue(res, 0, 0));
|
||||||
|
num_waiting = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ok, go to next step. */
|
PQclear(res);
|
||||||
|
sleep(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* All old transactions are finished;
|
||||||
|
* go to next step. */
|
||||||
|
PQclear(res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 5. Swap.
|
* 5. Swap.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user