diff options
| author | Tom Lane | 2017-06-23 15:03:04 +0000 |
|---|---|---|
| committer | Tom Lane | 2017-06-23 15:03:04 +0000 |
| commit | 8be8510cf89d4e150816941029d7cdddfe9aa474 (patch) | |
| tree | ce8af1f286d7b5bead684c42852f24880ee2fcde /src/bin/initdb | |
| parent | da2322883b9e50b1aac70a3b6eaf2a4f0e486469 (diff) | |
Add testing to detect errors of omission in "pin" dependency creation.
It's essential that initdb.c's setup_depend() scan each system catalog
that could contain objects that need to have "p" (pin) entries in pg_depend
or pg_shdepend. Forgetting to add that, either when a catalog is first
invented or when it first acquires DATA() entries, is an obvious bug
hazard. We can detect such omissions at reasonable cost by probing every
OID-containing system catalog to see whether the lowest-numbered OID in it
is pinned. If so, the catalog must have been properly accounted for in
setup_depend(). If the lowest OID is above FirstNormalObjectId then the
catalog must have been empty at the end of initdb, so it doesn't matter.
There are a small number of catalogs whose first entry is made later in
initdb than setup_depend(), resulting in nonempty expected output of the
test, but these can be manually inspected to see that they are OK. Any
future mistake of this ilk will manifest as a new entry in the test's
output.
Since pg_conversion is already in the test's output, add it to the set of
catalogs scanned by setup_depend(). That has no effect today (hence, no
catversion bump here) but it will protect us if we ever do add pin-worthy
conversions.
This test is very much like the catalog sanity checks embodied in
opr_sanity.sql and type_sanity.sql, but testing pg_depend doesn't seem to
fit naturally into either of those scripts' charters. Hence, invent a new
test script misc_sanity.sql, which can be a home for this as well as tests
on any other catalogs we might want in future.
Discussion: https://postgr.es/m/8068.1498155068@sss.pgh.pa.us
Diffstat (limited to 'src/bin/initdb')
| -rw-r--r-- | src/bin/initdb/initdb.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 0f22e6d29a4..b76eb1eae40 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1478,9 +1478,16 @@ setup_depend(FILE *cmdfd) * for instance) but generating only the minimum required set of * dependencies seems hard. * - * Note that we deliberately do not pin the system views, which - * haven't been created yet. Also, no conversions, databases, or - * tablespaces are pinned. + * Catalogs that are intentionally not scanned here are: + * + * pg_database: it's a feature, not a bug, that template1 is not + * pinned. + * + * pg_extension: a pinned extension isn't really an extension, hmm? + * + * pg_tablespace: tablespaces don't participate in the dependency + * code, and DropTableSpace() explicitly protects the built-in + * tablespaces. * * First delete any already-made entries; PINs override all else, and * must be the only entries for their objects. @@ -1501,6 +1508,8 @@ setup_depend(FILE *cmdfd) "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' " " FROM pg_constraint;\n\n", "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' " + " FROM pg_conversion;\n\n", + "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' " " FROM pg_attrdef;\n\n", "INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' " " FROM pg_language;\n\n", @@ -2906,6 +2915,11 @@ initialize_data_directory(void) setup_depend(cmdfd); + /* + * Note that no objects created after setup_depend() will be "pinned". + * They are all droppable at the whim of the DBA. + */ + setup_sysviews(cmdfd); setup_description(cmdfd); |
