|
6 | 6 | * Copyright (c) 2000-2005, PostgreSQL Global Development Group |
7 | 7 | * |
8 | 8 | * IDENTIFICATION |
9 | | - * $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.62 2005/02/20 21:46:48 tgl Exp $ |
| 9 | + * $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.63 2005/04/13 18:54:56 tgl Exp $ |
10 | 10 | * |
11 | 11 | *------------------------------------------------------------------------- |
12 | 12 | */ |
@@ -265,14 +265,36 @@ GetNewObjectId(void) |
265 | 265 | /* |
266 | 266 | * Check for wraparound of the OID counter. We *must* not return 0 |
267 | 267 | * (InvalidOid); and as long as we have to check that, it seems a good |
268 | | - * idea to skip over everything belowBootstrapObjectIdData too. (This |
| 268 | + * idea to skip over everything belowFirstNormalObjectId too. (This |
269 | 269 | * basically just reduces the odds of OID collision right after a wrap |
270 | 270 | * occurs.) Note we are relying on unsigned comparison here. |
| 271 | + * |
| 272 | + * During initdb, we start the OID generator at FirstBootstrapObjectId, |
| 273 | + * so we only enforce wrapping to that point when in bootstrap or |
| 274 | + * standalone mode. The first time through this routine after normal |
| 275 | + * postmaster start, the counter will be forced up to FirstNormalObjectId. |
| 276 | + * This mechanism leaves the OIDs between FirstBootstrapObjectId and |
| 277 | + * FirstNormalObjectId available for automatic assignment during initdb, |
| 278 | + * while ensuring they will never conflict with user-assigned OIDs. |
271 | 279 | */ |
272 | | -if (ShmemVariableCache->nextOid< ((Oid)BootstrapObjectIdData)) |
| 280 | +if (ShmemVariableCache->nextOid< ((Oid)FirstNormalObjectId)) |
273 | 281 | { |
274 | | -ShmemVariableCache->nextOid=BootstrapObjectIdData; |
275 | | -ShmemVariableCache->oidCount=0; |
| 282 | +if (IsPostmasterEnvironment) |
| 283 | +{ |
| 284 | +/* wraparound in normal environment */ |
| 285 | +ShmemVariableCache->nextOid=FirstNormalObjectId; |
| 286 | +ShmemVariableCache->oidCount=0; |
| 287 | +} |
| 288 | +else |
| 289 | +{ |
| 290 | +/* we may be bootstrapping, so don't enforce the full range */ |
| 291 | +if (ShmemVariableCache->nextOid< ((Oid)FirstBootstrapObjectId)) |
| 292 | +{ |
| 293 | +/* wraparound in standalone environment? */ |
| 294 | +ShmemVariableCache->nextOid=FirstBootstrapObjectId; |
| 295 | +ShmemVariableCache->oidCount=0; |
| 296 | +} |
| 297 | +} |
276 | 298 | } |
277 | 299 |
|
278 | 300 | /* If we run out of logged for use oids then we must log more */ |
|