diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 9498cbb..ccce409 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -1309,6 +1309,9 @@ heap_beginscan_internal(Relation relation, Snapshot snapshot, { HeapScanDesc scan; + if (mvcc_catalog_access && snapshot == SnapshotNow) + snapshot = GetLatestSnapshot(); + /* * increment relation ref count while scanning relation * diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index b878155..67c0cff 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -242,6 +242,9 @@ index_beginscan(Relation heapRelation, { IndexScanDesc scan; + if (mvcc_catalog_access && snapshot == SnapshotNow) + snapshot = GetLatestSnapshot(); + scan = index_beginscan_internal(indexRelation, nkeys, norderbys, snapshot); /* diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 22ba35f..fb3c295 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -76,6 +76,7 @@ #include "utils/portal.h" #include "utils/ps_status.h" #include "utils/snapmgr.h" +#include "utils/tqual.h" #include "utils/tzparser.h" #include "utils/xml.h" @@ -1455,6 +1456,16 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"mvcc_catalog_access", PGC_USERSET, DEVELOPER_OPTIONS, + gettext_noop("Use MVCC catalog access."), + NULL, + }, + &mvcc_catalog_access, + false, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 24384b4..b7a636b 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -73,6 +73,9 @@ SnapshotData SnapshotSelfData = {HeapTupleSatisfiesSelf}; SnapshotData SnapshotAnyData = {HeapTupleSatisfiesAny}; SnapshotData SnapshotToastData = {HeapTupleSatisfiesToast}; +/* Use MVCC catalog access. */ +bool mvcc_catalog_access; + /* local functions */ static bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot); diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index 465231c..16b67a3 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -29,6 +29,9 @@ extern PGDLLIMPORT SnapshotData SnapshotToastData; #define SnapshotAny (&SnapshotAnyData) #define SnapshotToast (&SnapshotToastData) +/* Use MVCC catalog access. */ +extern bool mvcc_catalog_access; + /* * We don't provide a static SnapshotDirty variable because it would be * non-reentrant. Instead, users of that snapshot type should declare a