On Tue, Jun 7, 2016 at 10:40 AM, Robert Haas <robertmh...@gmail.com> wrote: > On Sat, Jun 4, 2016 at 4:21 PM, Kevin Grittner <kgri...@gmail.com> wrote:
>> the minimal patch to fix behavior in this area would be: >> >> diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c >> index 31a1438..6c379da 100644 >> --- a/src/backend/catalog/index.c >> +++ b/src/backend/catalog/index.c >> @@ -2268,6 +2268,9 @@ IndexBuildHeapRangeScan(Relation heapRelation, >> Assert(numblocks == InvalidBlockNumber); >> } >> >> + if (old_snapshot_threshold >= 0) >> + indexInfo->ii_BrokenHotChain = true; >> + >> reltuples = 0; >> >> /* >> >> Of course, ii_BrokenHotChain should be renamed to something like >> ii_UnsafeForOldSnapshots, and some comments need to be updated; but >> the above is the substance of it. > > I don't know why we'd want to rename it like that... If we made the above change, the old name would be misleading, but I've thought better of that and attach a slightly different approach (tested but not yet with comment adjustments); attached. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 31a1438..945f55c 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2060,7 +2060,8 @@ index_build(Relation heapRelation, * about any concurrent readers of the tuple; no other transaction can see * it yet. */ - if (indexInfo->ii_BrokenHotChain && !isreindex && + if ((indexInfo->ii_BrokenHotChain || EarlyVacuumEnabled(indexRelation)) && + !isreindex && !indexInfo->ii_Concurrent) { Oid indexId = RelationGetRelid(indexRelation); @@ -3409,9 +3410,10 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, !indexForm->indisready || !indexForm->indislive); if (index_bad || - (indexForm->indcheckxmin && !indexInfo->ii_BrokenHotChain)) + (indexForm->indcheckxmin && + !(indexInfo->ii_BrokenHotChain || EarlyVacuumEnabled(iRel)))) { - if (!indexInfo->ii_BrokenHotChain) + if (!(indexInfo->ii_BrokenHotChain || EarlyVacuumEnabled(iRel))) indexForm->indcheckxmin = false; else if (index_bad) indexForm->indcheckxmin = true; diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 8a830d4..4e50b19 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -4290,8 +4290,7 @@ IssuePendingWritebacks(WritebackContext *context) void TestForOldSnapshot_impl(Snapshot snapshot, Relation relation) { - if (!IsCatalogRelation(relation) - && !RelationIsAccessibleInLogicalDecoding(relation) + if (RelationAllowsEarlyVacuum(relation) && (snapshot)->whenTaken < GetOldSnapshotThresholdTimestamp()) ereport(ERROR, (errcode(ERRCODE_SNAPSHOT_TOO_OLD), diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index f8a2a83..2eabd1c 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1597,10 +1597,7 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, { if (TransactionIdIsNormal(recentXmin) && old_snapshot_threshold >= 0 - && RelationNeedsWAL(relation) - && !IsCatalogRelation(relation) - && !RelationIsAccessibleInLogicalDecoding(relation) - && !RelationHasUnloggedIndex(relation)) + && RelationAllowsEarlyVacuum(relation)) { int64 ts = GetSnapshotCurrentTimestamp(); TransactionId xlimit = recentXmin; diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h index 4270696..effdb0c 100644 --- a/src/include/utils/snapmgr.h +++ b/src/include/utils/snapmgr.h @@ -31,6 +31,19 @@ #define OLD_SNAPSHOT_PADDING_ENTRIES 10 #define OLD_SNAPSHOT_TIME_MAP_ENTRIES (old_snapshot_threshold + OLD_SNAPSHOT_PADDING_ENTRIES) +/* + * Common definition of relation properties that allow early pruning/vacuuming + * when old_snapshot_threshold >= 0. + */ +#define RelationAllowsEarlyVacuum(rel) \ +( \ + RelationNeedsWAL(rel) \ + && !IsCatalogRelation(rel) \ + && !RelationIsAccessibleInLogicalDecoding(rel) \ + && !RelationHasUnloggedIndex(rel) \ +) + +#define EarlyVacuumEnabled(rel) (old_snapshot_threshold >= 0 && RelationAllowsEarlyVacuum(rel)) /* GUC variables */ extern PGDLLIMPORT int old_snapshot_threshold;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers