aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-07-15 11:41:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-07-15 11:41:47 -0400
commita49d081235997c67e8aab7a523b17e8d1cb93184 (patch)
tree4bf81347757488fc1ab5c651dc4f3ab0eb1b8a87 /src/backend/access/transam
parente529b2dc37ac80ccebd76cdbb14966d3b40819c9 (diff)
downloadpostgresql-a49d081235997c67e8aab7a523b17e8d1cb93184.tar.gz
postgresql-a49d081235997c67e8aab7a523b17e8d1cb93184.zip
Replace explicit PIN entries in pg_depend with an OID range test.
As of v14, pg_depend contains almost 7000 "pin" entries recording the OIDs of built-in objects. This is a fair amount of bloat for every database, and it adds time to pg_depend lookups as well as initdb. We can get rid of all of those entries in favor of an OID range check, i.e. "OIDs below FirstUnpinnedObjectId are pinned". (template1 and the public schema are exceptions. Those exceptions are now wired into IsPinnedObject() instead of initdb's code for filling pg_depend, but it's the same amount of cruft either way.) The contents of pg_shdepend are modified likewise. Discussion: https://postgr.es/m/3737988.1618451008@sss.pgh.pa.us
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r--src/backend/access/transam/varsup.c49
-rw-r--r--src/backend/access/transam/xlog.c2
2 files changed, 46 insertions, 5 deletions
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index a22bf375f85..5b4898bb786 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -541,11 +541,11 @@ GetNewObjectId(void)
* FirstNormalObjectId since that range is reserved for initdb (see
* IsCatalogRelationOid()). Note we are relying on unsigned comparison.
*
- * During initdb, we start the OID generator at FirstBootstrapObjectId, so
- * we only wrap if before that point when in bootstrap or standalone mode.
+ * During initdb, we start the OID generator at FirstGenbkiObjectId, so we
+ * only wrap if before that point when in bootstrap or standalone mode.
* The first time through this routine after normal postmaster start, the
* counter will be forced up to FirstNormalObjectId. This mechanism
- * leaves the OIDs between FirstBootstrapObjectId and FirstNormalObjectId
+ * leaves the OIDs between FirstGenbkiObjectId and FirstNormalObjectId
* available for automatic assignment during initdb, while ensuring they
* will never conflict with user-assigned OIDs.
*/
@@ -560,7 +560,7 @@ GetNewObjectId(void)
else
{
/* we may be bootstrapping, so don't enforce the full range */
- if (ShmemVariableCache->nextOid < ((Oid) FirstBootstrapObjectId))
+ if (ShmemVariableCache->nextOid < ((Oid) FirstGenbkiObjectId))
{
/* wraparound in standalone mode (unlikely but possible) */
ShmemVariableCache->nextOid = FirstNormalObjectId;
@@ -586,6 +586,47 @@ GetNewObjectId(void)
return result;
}
+/*
+ * SetNextObjectId
+ *
+ * This may only be called during initdb; it advances the OID counter
+ * to the specified value.
+ */
+static void
+SetNextObjectId(Oid nextOid)
+{
+ /* Safety check, this is only allowable during initdb */
+ if (IsPostmasterEnvironment)
+ elog(ERROR, "cannot advance OID counter anymore");
+
+ /* Taking the lock is, therefore, just pro forma; but do it anyway */
+ LWLockAcquire(OidGenLock, LW_EXCLUSIVE);
+
+ if (ShmemVariableCache->nextOid > nextOid)
+ elog(ERROR, "too late to advance OID counter to %u, it is now %u",
+ nextOid, ShmemVariableCache->nextOid);
+
+ ShmemVariableCache->nextOid = nextOid;
+ ShmemVariableCache->oidCount = 0;
+
+ LWLockRelease(OidGenLock);
+}
+
+/*
+ * StopGeneratingPinnedObjectIds
+ *
+ * This is called once during initdb to force the OID counter up to
+ * FirstUnpinnedObjectId. This supports letting initdb's post-bootstrap
+ * processing create some pinned objects early on. Once it's done doing
+ * so, it calls this (via pg_stop_making_pinned_objects()) so that the
+ * remaining objects it makes will be considered un-pinned.
+ */
+void
+StopGeneratingPinnedObjectIds(void)
+{
+ SetNextObjectId(FirstUnpinnedObjectId);
+}
+
#ifdef USE_ASSERT_CHECKING
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index c7c928f50bd..edb15fe58d2 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -5318,7 +5318,7 @@ BootStrapXLOG(void)
checkPoint.fullPageWrites = fullPageWrites;
checkPoint.nextXid =
FullTransactionIdFromEpochAndXid(0, FirstNormalTransactionId);
- checkPoint.nextOid = FirstBootstrapObjectId;
+ checkPoint.nextOid = FirstGenbkiObjectId;
checkPoint.nextMulti = FirstMultiXactId;
checkPoint.nextMultiOffset = 0;
checkPoint.oldestXid = FirstNormalTransactionId;