Skip to content

Commit 65d2b4b

Browse files
committed
Fix handling of OID wraparound while in standalone mode.
If OID wraparound should occur while in standalone mode (unlikely but possible), we want to advance the counter to FirstNormalObjectId not FirstBootstrapObjectId. Otherwise, user objects might be created with OIDs in the system-reserved range. That isn't immediately harmful but it poses a risk of conflicts during future pg_upgrade operations. Noted by Andres Freund. Back-patch to all supported branches, since all of them are supported sources for pg_upgrade operations.
1 parent 79e5d72 commit 65d2b4b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/backend/access/transam/varsup.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,18 @@ GetNewObjectId(void)
333333
* iterations in GetNewOid.) Note we are relying on unsigned comparison.
334334
*
335335
* During initdb, we start the OID generator at FirstBootstrapObjectId, so
336-
* we only enforce wrapping to that point when in bootstrap or standalone
337-
* mode. The first time through this routine after normal postmaster
338-
* start, the counter will be forced up to FirstNormalObjectId. This
339-
* mechanism leaves the OIDs between FirstBootstrapObjectId and
340-
* FirstNormalObjectId available for automatic assignment during initdb,
341-
* while ensuring they will never conflict with user-assigned OIDs.
336+
* we only wrap if before that point when in bootstrap or standalone mode.
337+
* The first time through this routine after normal postmaster start, the
338+
* counter will be forced up to FirstNormalObjectId. This mechanism
339+
* leaves the OIDs between FirstBootstrapObjectId and FirstNormalObjectId
340+
* available for automatic assignment during initdb, while ensuring they
341+
* will never conflict with user-assigned OIDs.
342342
*/
343343
if (ShmemVariableCache->nextOid < ((Oid) FirstNormalObjectId))
344344
{
345345
if (IsPostmasterEnvironment)
346346
{
347-
/* wraparound in normal environment */
347+
/* wraparound, or first post-initdb assignment, in normal mode */
348348
ShmemVariableCache->nextOid = FirstNormalObjectId;
349349
ShmemVariableCache->oidCount = 0;
350350
}
@@ -353,8 +353,8 @@ GetNewObjectId(void)
353353
/* we may be bootstrapping, so don't enforce the full range */
354354
if (ShmemVariableCache->nextOid < ((Oid) FirstBootstrapObjectId))
355355
{
356-
/* wraparound in standalone environment? */
357-
ShmemVariableCache->nextOid = FirstBootstrapObjectId;
356+
/* wraparound in standalone mode (unlikely but possible) */
357+
ShmemVariableCache->nextOid = FirstNormalObjectId;
358358
ShmemVariableCache->oidCount = 0;
359359
}
360360
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy