Skip to content

Commit a4390ab

Browse files
committed
Reduce the range of OIDs reserved for genbki.pl.
Commit ab59610 increased FirstBootstrapObjectId from 12000 to 13000, but we've had some push-back about that. It's worrisome to reduce the daylight between there and FirstNormalObjectId, because the number of OIDs consumed during initdb for collation objects is hard to predict. We can improve the situation by abandoning the assumption that these OIDs must be globally unique. It should be sufficient for them to be unique per-catalog. (Any code that's unhappy about that is broken anyway, since no more than per-catalog uniqueness can be guaranteed once the OID counter wraps around.) With that change, the largest OID assigned during genbki.pl (starting from a base of 10000) is a bit under 11000. This allows reverting FirstBootstrapObjectId to 12000 with reasonable confidence that that will be sufficient for many years to come. We are not, at this time, abandoning the expectation that hand-assigned OIDs (below 10000) are globally unique. Someday that'll likely be necessary, but the need seems years away still. This is late for v14, but it seems worth doing it now so that downstream software doesn't have to deal with the consequences of a change in FirstBootstrapObjectId. In any case, we already bought into forcing an initdb for beta2, so another catversion bump won't hurt. Discussion: https://postgr.es/m/1665197.1622065382@sss.pgh.pa.us
1 parent e6241d8 commit a4390ab

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

doc/src/sgml/bki.sgml

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@
418418
<para>
419419
If <filename>genbki.pl</filename> needs to assign an OID to a catalog
420420
entry that does not have a manually-assigned OID, it will use a value in
421-
the range 10000&mdash;12999. The server's OID counter is set to 13000
421+
the range 10000&mdash;11999. The server's OID counter is set to 12000
422422
at the start of a bootstrap run. Thus objects created by regular SQL
423423
commands during the later phases of bootstrap, such as objects created
424424
while running the <filename>information_schema.sql</filename> script,
425-
receive OIDs of 13000 or above.
425+
receive OIDs of 12000 or above.
426426
</para>
427427

428428
<para>

src/backend/catalog/genbki.pl

+24-9
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,17 @@
167167
die "found $found duplicate OID(s) in catalog data\n" if $found;
168168

169169

170-
# Oids not specified in the input files are automatically assigned,
170+
# OIDs not specified in the input files are automatically assigned,
171171
# starting at FirstGenbkiObjectId, extending up to FirstBootstrapObjectId.
172+
# We allow such OIDs to be assigned independently within each catalog.
172173
my $FirstGenbkiObjectId =
173174
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
174175
'FirstGenbkiObjectId');
175176
my $FirstBootstrapObjectId =
176177
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
177178
'FirstBootstrapObjectId');
178-
my $GenbkiNextOid = $FirstGenbkiObjectId;
179+
# Hash of next available OID, indexed by catalog name.
180+
my %GenbkiNextOids;
179181

180182

181183
# Fetch some special data that we will substitute into the output file.
@@ -563,8 +565,7 @@
563565
# Assign oid if oid column exists and no explicit assignment in row
564566
if ($attname eq "oid" and not defined $bki_values{$attname})
565567
{
566-
$bki_values{$attname} = $GenbkiNextOid;
567-
$GenbkiNextOid++;
568+
$bki_values{$attname} = assign_next_oid($catname);
568569
}
569570
570571
# Replace OID synonyms with OIDs per the appropriate lookup rule.
@@ -669,11 +670,6 @@
669670
# last command in the BKI file: build the indexes declared above
670671
print $bki "build indices\n";
671672

672-
# check that we didn't overrun available OIDs
673-
die
674-
"genbki OID counter reached $GenbkiNextOid, overrunning FirstBootstrapObjectId\n"
675-
if $GenbkiNextOid > $FirstBootstrapObjectId;
676-
677673
# Now generate system_constraints.sql
678674

679675
foreach my $c (@system_constraints)
@@ -1079,6 +1075,25 @@ sub form_pg_type_symbol
10791075
return $name . $arraystr . 'OID';
10801076
}
10811077

1078+
# Assign an unused OID within the specified catalog.
1079+
sub assign_next_oid
1080+
{
1081+
my $catname = shift;
1082+
1083+
# Initialize, if no previous request for this catalog.
1084+
$GenbkiNextOids{$catname} = $FirstGenbkiObjectId
1085+
if !defined($GenbkiNextOids{$catname});
1086+
1087+
my $result = $GenbkiNextOids{$catname}++;
1088+
1089+
# Check that we didn't overrun available OIDs
1090+
die
1091+
"genbki OID counter for $catname reached $result, overrunning FirstBootstrapObjectId\n"
1092+
if $result >= $FirstBootstrapObjectId;
1093+
1094+
return $result;
1095+
}
1096+
10821097
sub usage
10831098
{
10841099
die <<EOM;

src/include/access/transam.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,20 @@ FullTransactionIdAdvance(FullTransactionId *dest)
161161
* development purposes (such as in-progress patches and forks);
162162
* they should not appear in released versions.
163163
*
164-
* OIDs 10000-12999 are reserved for assignment by genbki.pl, for use
164+
* OIDs 10000-11999 are reserved for assignment by genbki.pl, for use
165165
* when the .dat files in src/include/catalog/ do not specify an OID
166-
* for a catalog entry that requires one.
166+
* for a catalog entry that requires one. Note that genbki.pl assigns
167+
* these OIDs independently in each catalog, so they're not guaranteed
168+
* to be globally unique.
167169
*
168-
* OIDS 13000-16383 are reserved for assignment during initdb
169-
* using the OID generator. (We start the generator at 13000.)
170+
* OIDS 12000-16383 are reserved for assignment during initdb
171+
* using the OID generator. (We start the generator at 12000.)
170172
*
171173
* OIDs beginning at 16384 are assigned from the OID generator
172174
* during normal multiuser operation. (We force the generator up to
173175
* 16384 as soon as we are in normal operation.)
174176
*
175-
* The choices of 8000, 10000 and 13000 are completely arbitrary, and can be
177+
* The choices of 8000, 10000 and 12000 are completely arbitrary, and can be
176178
* moved if we run low on OIDs in any category. Changing the macros below,
177179
* and updating relevant documentation (see bki.sgml and RELEASE_CHANGES),
178180
* should be sufficient to do this. Moving the 16384 boundary between
@@ -186,7 +188,7 @@ FullTransactionIdAdvance(FullTransactionId *dest)
186188
* ----------
187189
*/
188190
#define FirstGenbkiObjectId 10000
189-
#define FirstBootstrapObjectId 13000
191+
#define FirstBootstrapObjectId 12000
190192
#define FirstNormalObjectId 16384
191193

192194
/*

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202105271
56+
#define CATALOG_VERSION_NO 202105272
5757

5858
#endif

0 commit comments

Comments
 (0)