]> granicus.if.org Git - postgresql/commitdiff
Avoid xid error from age() function when run on Hot Standby
authorSimon Riggs <simon@2ndQuadrant.com>
Wed, 9 May 2012 12:59:30 +0000 (13:59 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Wed, 9 May 2012 12:59:30 +0000 (13:59 +0100)
src/backend/utils/adt/xid.c

index 76d29ff2a379de01d0e895ccd3fc2601cfcadd13..229e8e43e69eedb8794bcbb821c4d9a5e4eceef0 100644 (file)
@@ -93,7 +93,10 @@ Datum
 xid_age(PG_FUNCTION_ARGS)
 {
        TransactionId xid = PG_GETARG_TRANSACTIONID(0);
-       TransactionId now = GetTopTransactionId();
+       TransactionId now = GetTopTransactionIdIfAny();
+
+       if (!TransactionIdIsValid(now))
+               now = ReadNewTransactionId();
 
        /* Permanent XIDs are always infinitely old */
        if (!TransactionIdIsNormal(xid))