Re: preserving db/ts/relfilenode OIDs across pg_upgrade (was Re: storing an explicit nonce)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Shruthi Gowda <gowdashru@gmail.com>, Julien Rouhaud <rjuju123@gmail.com>,
Sadhuprasad Patro <b.sadhu@gmail.com>,
Stephen Frost <sfrost@snowman.net>, Bruce Momjian <bruce@momjian.us>,
Andres Freund <andres@anarazel.de>,
Alvaro Herrera <alvherre@alvh.no-ip.org>,
Masahiko Sawada <sawada.mshk@gmail.com>,
Tom Kincaid <tomjohnkincaid@gmail.com>,
Amit Kapila <amit.kapila16@gmail.com>,
Thomas Munro <thomas.munro@gmail.com>,
PostgreSQL Development <pgsql-hackers@postgresql.org>,
Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Date: 2022-04-20T18:34:52Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Rethink method for assigning OIDs to the template0 and postgres DBs.
- 2cb1272445d2 15.0 landed
-
pg_upgrade: Preserve database OIDs.
- aa01051418f1 15.0 landed
-
pg_upgrade: Preserve relfilenodes and tablespace OIDs.
- 9a974cbcba00 15.0 landed
-
Fix for new Boolean node
- cf925936ecc0 15.0 cited
-
Improve error handling of HMAC computations
- 5513dc6a304d 15.0 cited
-
Add macro RelationIsPermanent() to report relation permanence
- 95d77149c535 14.0 landed
-
Enhance nbtree index tuple deletion.
- d168b666823b 14.0 cited
Attachments
- fix-assignment-of-initdb-database-OIDs.patch (text/x-diff) patch
Robert Haas <robertmhaas@gmail.com> writes: > On Sat, Jan 22, 2022 at 2:20 AM Shruthi Gowda <gowdashru@gmail.com> wrote: >> Agree. In the latest patch, the template0 and postgres OIDs are fixed >> to unused manually assigned OIDs 4 and 5 respectively. These OIDs are >> no more listed as unused OIDs. > Thanks. Committed with a few more cosmetic changes. I happened to take a closer look at this patch today, and I'm pretty unhappy with the way that the assignment of those OIDs was managed. There are two big problems: 1. IsPinnedObject() will now report that template0 and postgres are pinned. This seems not to prevent one from dropping them (I guess dropdb() doesn't consult IsPinnedObject), but it would probably bollix any pg_shdepend management that should happen for them. 2. The Catalog.pm infrastructure knows nothing about these OIDs. While the unused_oids script was hack-n-slashed to claim that the OIDs are used, other scripts won't know about them; for example duplicate_oids won't report conflicts if someone tries to reuse those OIDs. The attached draft patch attempts to improve this situation. It reserves these OIDs, and creates the associated macros, through the normal BKI infrastructure by adding entries in pg_database.dat. We have to delete those rows again during initdb, which is slightly ugly but surely no more so than initdb's other direct manipulations of pg_database. There are a few loose ends: * I'm a bit inclined to simplify IsPinnedObject by just teaching it that *no* entries of pg_database are pinned, which would correspond to the evident lack of enforcement in dropdb(). Can anyone see a reason why we might pin some database in future? * I had to set up the additional pg_database entries with nonzero datfrozenxid to avoid an assertion failure during initdb's first VACUUM. (That VACUUM will overwrite template1's datfrozenxid before computing the global minimum frozen XID, but not these others; and it doesn't like finding that the minimum is zero.) This feels klugy. An alternative is to delete the extra pg_database rows before that VACUUM, which would mean taking those deletes out of make_template0 and make_postgres and putting them somewhere seemingly unrelated, so that's a bit crufty too. Anybody have a preference? * The new macro names seem ill-chosen. Template0ObjectId is spelled randomly differently from the longstanding TemplateDbOid, and surely PostgresObjectId is about as vague a name as could possibly have been thought of (please name an object that it couldn't apply to). I'm a little inclined to rename TemplateDbOid to Template1DbOid and use Template0DbOid and PostgresDbOid for the others, but I didn't pull that trigger here. Comments? regards, tom lane