Simplify initdb-time assignment of OIDs as I proposed yesterday, and

avoid encroaching on the 'user' range of OIDs by allowing automatic
OID assignment to use values below 16k until we reach normal operation.

initdb not forced since this doesn't make any incompatible change;
however a lot of stuff will have different OIDs after your next initdb.
This commit is contained in:
Tom Lane 2005-04-13 18:54:57 +00:00
parent 2fdf9e0be6
commit 2193a856a2
10 changed files with 69 additions and 94 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.14 2005/03/29 19:44:22 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.15 2005/04/13 18:54:55 tgl Exp $
--> -->
<chapter id="bki"> <chapter id="bki">
@ -167,8 +167,8 @@ $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.14 2005/03/29 19:44:22 tgl Exp $
values and <replaceable values and <replaceable
class="parameter">oid_value</replaceable> for its OID. If class="parameter">oid_value</replaceable> for its OID. If
<replaceable class="parameter">oid_value</replaceable> is zero <replaceable class="parameter">oid_value</replaceable> is zero
(0) or the clause is omitted, then the next available OID is (0) or the clause is omitted, and the table has OIDs, then the
used. next available OID is assigned.
</para> </para>
<para> <para>

View File

@ -6,7 +6,7 @@
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.62 2005/02/20 21:46:48 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/varsup.c,v 1.63 2005/04/13 18:54:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -265,14 +265,36 @@ GetNewObjectId(void)
/* /*
* Check for wraparound of the OID counter. We *must* not return 0 * Check for wraparound of the OID counter. We *must* not return 0
* (InvalidOid); and as long as we have to check that, it seems a good * (InvalidOid); and as long as we have to check that, it seems a good
* idea to skip over everything below BootstrapObjectIdData too. (This * idea to skip over everything below FirstNormalObjectId too. (This
* basically just reduces the odds of OID collision right after a wrap * basically just reduces the odds of OID collision right after a wrap
* occurs.) Note we are relying on unsigned comparison here. * occurs.) Note we are relying on unsigned comparison here.
*
* During initdb, we start the OID generator at FirstBootstrapObjectId,
* so we only enforce wrapping to 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 available for automatic assignment during initdb,
* while ensuring they will never conflict with user-assigned OIDs.
*/ */
if (ShmemVariableCache->nextOid < ((Oid) BootstrapObjectIdData)) if (ShmemVariableCache->nextOid < ((Oid) FirstNormalObjectId))
{ {
ShmemVariableCache->nextOid = BootstrapObjectIdData; if (IsPostmasterEnvironment)
ShmemVariableCache->oidCount = 0; {
/* wraparound in normal environment */
ShmemVariableCache->nextOid = FirstNormalObjectId;
ShmemVariableCache->oidCount = 0;
}
else
{
/* we may be bootstrapping, so don't enforce the full range */
if (ShmemVariableCache->nextOid < ((Oid) FirstBootstrapObjectId))
{
/* wraparound in standalone environment? */
ShmemVariableCache->nextOid = FirstBootstrapObjectId;
ShmemVariableCache->oidCount = 0;
}
}
} }
/* If we run out of logged for use oids then we must log more */ /* If we run out of logged for use oids then we must log more */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.183 2005/03/29 03:01:30 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.184 2005/04/13 18:54:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -3505,7 +3505,7 @@ BootStrapXLOG(void)
checkPoint.undo = checkPoint.redo; checkPoint.undo = checkPoint.redo;
checkPoint.ThisTimeLineID = ThisTimeLineID; checkPoint.ThisTimeLineID = ThisTimeLineID;
checkPoint.nextXid = FirstNormalTransactionId; checkPoint.nextXid = FirstNormalTransactionId;
checkPoint.nextOid = BootstrapObjectIdData; checkPoint.nextOid = FirstBootstrapObjectId;
checkPoint.time = time(NULL); checkPoint.time = time(NULL);
ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextXid = checkPoint.nextXid;

View File

@ -10,7 +10,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.33 2005/03/29 00:16:55 tgl Exp $ # $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.34 2005/04/13 18:54:56 tgl Exp $
# #
# NOTES # NOTES
# non-essential whitespace is removed from the generated file. # non-essential whitespace is removed from the generated file.
@ -121,15 +121,6 @@ for dir in $INCLUDE_DIRS; do
fi fi
done done
# Get FirstGenBKIObjectId from access/transam.h
for dir in $INCLUDE_DIRS; do
if [ -f "$dir/access/transam.h" ]; then
BKIOBJECTID=`grep '^#define[ ]*FirstGenBKIObjectId' $dir/access/transam.h | $AWK '{ print $3 }'`
break
fi
done
export BKIOBJECTID
touch ${OUTPUT_PREFIX}.description.$$ touch ${OUTPUT_PREFIX}.description.$$
# ---------------- # ----------------
@ -173,8 +164,7 @@ sed -e "s/;[ ]*$//g" \
# contents of a catalog definition. # contents of a catalog definition.
# reln_open is a flag indicating when we are processing DATA lines. # reln_open is a flag indicating when we are processing DATA lines.
# (i.e. have a relation open and need to close it) # (i.e. have a relation open and need to close it)
# nextbkioid is the next OID available for automatic assignment. # oid is the most recently seen oid, or 0 if none in the last DATA line.
# oid is the most recently seen or assigned oid.
# ---------------- # ----------------
BEGIN { BEGIN {
inside = 0; inside = 0;
@ -184,7 +174,6 @@ BEGIN {
nc = 0; nc = 0;
reln_open = 0; reln_open = 0;
comment_level = 0; comment_level = 0;
nextbkioid = ENVIRON["BKIOBJECTID"];
oid = 0; oid = 0;
} }
@ -202,9 +191,8 @@ comment_level > 0 { next; }
# ---------------- # ----------------
# DATA() statements are basically passed right through after # DATA() statements are basically passed right through after
# stripping off the DATA( and the ) on the end. However, # stripping off the DATA( and the ) on the end.
# if we see "OID = 0" then we should assign an oid from nextbkioid. # Remember any explicit OID for use by DESCR().
# Remember any explicit or assigned OID for use by DESCR().
# ---------------- # ----------------
/^DATA\(/ { /^DATA\(/ {
data = substr($0, 6, length($0) - 6); data = substr($0, 6, length($0) - 6);
@ -213,12 +201,6 @@ comment_level > 0 { next; }
if (nf >= 4 && datafields[1] == "insert" && datafields[2] == "OID" && datafields[3] == "=") if (nf >= 4 && datafields[1] == "insert" && datafields[2] == "OID" && datafields[3] == "=")
{ {
oid = datafields[4]; oid = datafields[4];
if (oid == 0)
{
oid = nextbkioid;
nextbkioid++;
sub("OID *= *0", "OID = " oid, data);
}
} }
print data; print data;
next; next;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.148 2005/03/11 03:52:06 neilc Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.149 2005/04/13 18:54:56 tgl Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
@ -97,7 +97,7 @@ static const char *const lock_mode_names[] =
* -------- * --------
*/ */
int Trace_lock_oidmin = BootstrapObjectIdData; int Trace_lock_oidmin = FirstNormalObjectId;
bool Trace_locks = false; bool Trace_locks = false;
bool Trace_userlocks = false; bool Trace_userlocks = false;
int Trace_lock_table = 0; int Trace_lock_table = 0;

View File

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.258 2005/04/08 00:59:59 neilc Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.259 2005/04/13 18:54:56 tgl Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
@ -1090,7 +1090,7 @@ static struct config_int ConfigureNamesInt[] =
GUC_NOT_IN_SAMPLE GUC_NOT_IN_SAMPLE
}, },
&Trace_lock_oidmin, &Trace_lock_oidmin,
BootstrapObjectIdData, 0, INT_MAX, NULL, NULL FirstNormalObjectId, 0, INT_MAX, NULL, NULL
}, },
{ {
{"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS, {"trace_lock_table", PGC_SUSET, DEVELOPER_OPTIONS,

View File

@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.30 2005/03/29 03:01:32 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.31 2005/04/13 18:54:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -404,7 +404,7 @@ GuessControlValues(void)
ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo; ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
ControlFile.checkPointCopy.ThisTimeLineID = 1; ControlFile.checkPointCopy.ThisTimeLineID = 1;
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */ ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData; ControlFile.checkPointCopy.nextOid = FirstBootstrapObjectId;
ControlFile.checkPointCopy.time = time(NULL); ControlFile.checkPointCopy.time = time(NULL);
ControlFile.state = DB_SHUTDOWNED; ControlFile.state = DB_SHUTDOWNED;

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.53 2005/02/20 21:46:50 tgl Exp $ * $PostgreSQL: pgsql/src/include/access/transam.h,v 1.54 2005/04/13 18:54:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -55,23 +55,24 @@
* OIDs 1-9999 are reserved for manual assignment (see the files * OIDs 1-9999 are reserved for manual assignment (see the files
* in src/include/catalog/). * in src/include/catalog/).
* *
* OIDS 10000-16383 are reserved for assignment by genbki.sh. * OIDS 10000-16383 are reserved for assignment during initdb
* using the OID generator. (We start the generator at 10000.)
* *
* OIDs beginning at 16384 are assigned at runtime from the OID * OIDs beginning at 16384 are assigned from the OID generator
* generator. (The first few of these will be assigned during initdb, * during normal multiuser operation. (We force the generator up to
* to objects created after the initial BKI script processing.) * 16384 as soon as we are in normal operation.)
* *
* The choices of 10000 and 16384 are completely arbitrary, and can be moved * The choices of 10000 and 16384 are completely arbitrary, and can be moved
* if we run low on OIDs in either category. Changing the macros below * if we run low on OIDs in either category. Changing the macros below
* should be sufficient to do this. * should be sufficient to do this.
* *
* NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383 * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
* and resume with 16384. This minimizes the odds of OID conflict, by not * and resume with 16384. This minimizes the odds of OID conflict, by not
* reassigning OIDs that might have been assigned during initdb. * reassigning OIDs that might have been assigned during initdb.
* ---------- * ----------
*/ */
#define FirstGenBKIObjectId 10000 #define FirstBootstrapObjectId 10000
#define BootstrapObjectIdData 16384 #define FirstNormalObjectId 16384
/* /*
* VariableCache is placed in shmem and used by * VariableCache is placed in shmem and used by

View File

@ -2,45 +2,18 @@
# #
# duplicate_oids # duplicate_oids
# #
# finds oids that are duplicated in the system tables. # $PostgreSQL: pgsql/src/include/catalog/duplicate_oids,v 1.6 2005/04/13 18:54:57 tgl Exp $
#
# finds manually-assigned oids that are duplicated in the system tables.
#
# run this script in src/include/catalog.
# #
FILES=`ls pg_*.h` FILES=`ls pg_*.h`
#
# The previous version did not use the -d option on uniq
# so check here that it is supported.
# Otherwise, use the old algorithm
#
if [ `uniq -d < /dev/null > /dev/null 2>&1` ]; then
echo "uniq -d is not supported on your platform."
echo "Please report this to pgsql-hackers@postgresql.org"
egrep '^DATA' $FILES | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
sort -n >/tmp/alloids.$$
uniq /tmp/alloids.$$ >/tmp/uniqoids.$$
diff -u /tmp/alloids.$$ /tmp/uniqoids.$$ | \
grep -v '/tmp/' | \
grep '^-' | \
sed -e 's/^-//' | \
grep -v '^0$' | \
uniq
rm /tmp/alloids.$$
rm /tmp/uniqoids.$$
else
# echo "uniq -d is supported on this platform."
# echo "Will omit the use of temporary files."
egrep '^DATA' $FILES | \ egrep '^DATA' $FILES | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \ sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
sort -n | uniq -d | \ sort -n | uniq -d | \
egrep -v '^[0]*$' egrep -v '^0*$'
fi exit 0
exit

View File

@ -1,20 +1,17 @@
#!/bin/sh #!/bin/sh
#
# unused_oids # unused_oids
# #
# $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.5 2003/11/29 19:52:08 pgsql Exp $ # $PostgreSQL: pgsql/src/include/catalog/unused_oids,v 1.6 2005/04/13 18:54:57 tgl Exp $
# #
# finds blocks of oids that have not already been claimed by # finds blocks of manually-assignable oids that have not already been
# post_hackers for internal purposes. primarily useful for # claimed by post_hackers. primarily useful for finding available
# finding valid oids for new internal function oids. the numbers # oids for new internal functions. the numbers printed are inclusive
# printed are inclusive ranges of valid (unused) oids. # ranges of unused oids.
# #
# before using a large empty block, make sure you aren't about # before using a large empty block, make sure you aren't about
# to take over what was intended as expansion space for something # to take over what was intended as expansion space for something
# else. also, before using a number, do a "grepsrc" to make sure # else.
# that someone isn't using a literal numeric constant somewhere..
#
# non-berkeley post_hackers should probably not try to use oids
# less than the highest one that comes with the distributed source.
# #
# run this script in src/include/catalog. # run this script in src/include/catalog.
# #
@ -22,9 +19,9 @@
AWK="awk" AWK="awk"
# Get FirstGenBKIObjectId from access/transam.h # Get FirstBootstrapObjectId from access/transam.h
BKIOBJECTID=`grep '#define[ ]*FirstGenBKIObjectId' ../access/transam.h | $AWK '{ print $3 }'` FIRSTOBJECTID=`grep '#define[ ]*FirstBootstrapObjectId' ../access/transam.h | $AWK '{ print $3 }'`
export BKIOBJECTID export FIRSTOBJECTID
egrep '^DATA' pg_*.h | \ egrep '^DATA' pg_*.h | \
sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \ sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
@ -45,5 +42,5 @@ BEGIN {
last = $1; last = $1;
} }
END { END {
print last + 1, "-", ENVIRON["BKIOBJECTID"]-1; print last + 1, "-", ENVIRON["FIRSTOBJECTID"]-1;
}' }'