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
2017-06-23 17:03:04 +02:00
|
|
|
--
|
|
|
|
-- MISC_SANITY
|
|
|
|
-- Sanity checks for common errors in making system tables that don't fit
|
|
|
|
-- comfortably into either opr_sanity or type_sanity.
|
|
|
|
--
|
|
|
|
-- Every test failure in this file should be closely inspected.
|
|
|
|
-- The description of the failing test should be read carefully before
|
|
|
|
-- adjusting the expected output. In most cases, the queries should
|
|
|
|
-- not find *any* matching entries.
|
|
|
|
--
|
|
|
|
-- NB: run this test early, because some later tests create bogus entries.
|
|
|
|
-- **************** pg_depend ****************
|
|
|
|
-- Look for illegal values in pg_depend fields.
|
|
|
|
SELECT *
|
|
|
|
FROM pg_depend as d1
|
|
|
|
WHERE refclassid = 0 OR refobjid = 0 OR
|
2021-07-15 17:41:47 +02:00
|
|
|
classid = 0 OR objid = 0 OR
|
|
|
|
deptype NOT IN ('a', 'e', 'i', 'n', 'x', 'P', 'S');
|
2021-05-07 10:17:42 +02:00
|
|
|
classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype
|
|
|
|
---------+-------+----------+------------+----------+-------------+---------
|
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
2017-06-23 17:03:04 +02:00
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
-- **************** pg_shdepend ****************
|
|
|
|
-- Look for illegal values in pg_shdepend fields.
|
|
|
|
SELECT *
|
|
|
|
FROM pg_shdepend as d1
|
|
|
|
WHERE refclassid = 0 OR refobjid = 0 OR
|
2021-07-15 17:41:47 +02:00
|
|
|
classid = 0 OR objid = 0 OR
|
|
|
|
deptype NOT IN ('a', 'o', 'r', 't');
|
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
2017-06-23 17:03:04 +02:00
|
|
|
dbid | classid | objid | objsubid | refclassid | refobjid | deptype
|
|
|
|
------+---------+-------+----------+------------+----------+---------
|
|
|
|
(0 rows)
|
|
|
|
|
2018-07-12 12:31:49 +02:00
|
|
|
-- **************** pg_class ****************
|
Add toast tables to most system catalogs
It has been project policy to create toast tables only for those catalogs
that might reasonably need one. Since this judgment call can change over
time, just create one for every catalog, as this can be useful when
creating rather-long entries in catalogs, with recent examples being in
the shape of policy expressions or customly-formatted SCRAM verifiers.
To prevent circular dependencies and to avoid adding complexity to VACUUM
FULL logic, exclude pg_class, pg_attribute, and pg_index. Also, to
prevent pg_upgrade from seeing a non-empty new cluster, exclude
pg_largeobject and pg_largeobject_metadata from the set as large object
data is handled as user data. Those relations have no reason to use a
toast table anyway.
Author: Joe Conway, John Naylor
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/84ddff04-f122-784b-b6c5-3536804495f8@joeconway.com
2018-07-20 00:43:41 +02:00
|
|
|
-- Look for system tables with varlena columns but no toast table. All
|
|
|
|
-- system tables with toastable columns should have toast tables, with
|
|
|
|
-- the following exceptions:
|
|
|
|
-- 1. pg_class, pg_attribute, and pg_index, due to fear of recursive
|
|
|
|
-- dependencies as toast tables depend on them.
|
|
|
|
-- 2. pg_largeobject and pg_largeobject_metadata. Large object catalogs
|
|
|
|
-- and toast tables are mutually exclusive and large object data is handled
|
|
|
|
-- as user data by pg_upgrade, which would cause failures.
|
2018-07-12 12:31:49 +02:00
|
|
|
SELECT relname, attname, atttypid::regtype
|
|
|
|
FROM pg_class c JOIN pg_attribute a ON c.oid = attrelid
|
|
|
|
WHERE c.oid < 16384 AND
|
|
|
|
reltoastrelid = 0 AND
|
|
|
|
relkind = 'r' AND
|
|
|
|
attstorage != 'p'
|
|
|
|
ORDER BY 1, 2;
|
Add toast tables to most system catalogs
It has been project policy to create toast tables only for those catalogs
that might reasonably need one. Since this judgment call can change over
time, just create one for every catalog, as this can be useful when
creating rather-long entries in catalogs, with recent examples being in
the shape of policy expressions or customly-formatted SCRAM verifiers.
To prevent circular dependencies and to avoid adding complexity to VACUUM
FULL logic, exclude pg_class, pg_attribute, and pg_index. Also, to
prevent pg_upgrade from seeing a non-empty new cluster, exclude
pg_largeobject and pg_largeobject_metadata from the set as large object
data is handled as user data. Those relations have no reason to use a
toast table anyway.
Author: Joe Conway, John Naylor
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/84ddff04-f122-784b-b6c5-3536804495f8@joeconway.com
2018-07-20 00:43:41 +02:00
|
|
|
relname | attname | atttypid
|
|
|
|
-------------------------+---------------+--------------
|
|
|
|
pg_attribute | attacl | aclitem[]
|
|
|
|
pg_attribute | attfdwoptions | text[]
|
|
|
|
pg_attribute | attmissingval | anyarray
|
|
|
|
pg_attribute | attoptions | text[]
|
|
|
|
pg_class | relacl | aclitem[]
|
|
|
|
pg_class | reloptions | text[]
|
|
|
|
pg_class | relpartbound | pg_node_tree
|
|
|
|
pg_index | indexprs | pg_node_tree
|
|
|
|
pg_index | indpred | pg_node_tree
|
|
|
|
pg_largeobject | data | bytea
|
|
|
|
pg_largeobject_metadata | lomacl | aclitem[]
|
|
|
|
(11 rows)
|
2018-07-12 12:31:49 +02:00
|
|
|
|
2021-01-30 19:14:31 +01:00
|
|
|
-- system catalogs without primary keys
|
|
|
|
--
|
|
|
|
-- Current exceptions:
|
|
|
|
-- * pg_depend, pg_shdepend don't have a unique key
|
|
|
|
SELECT relname
|
|
|
|
FROM pg_class
|
|
|
|
WHERE relnamespace = 'pg_catalog'::regnamespace AND relkind = 'r'
|
|
|
|
AND pg_class.oid NOT IN (SELECT indrelid FROM pg_index WHERE indisprimary)
|
|
|
|
ORDER BY 1;
|
|
|
|
relname
|
|
|
|
-------------
|
|
|
|
pg_depend
|
|
|
|
pg_shdepend
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
-- system catalog unique indexes not wrapped in a constraint
|
|
|
|
-- (There should be none.)
|
|
|
|
SELECT relname
|
|
|
|
FROM pg_class c JOIN pg_index i ON c.oid = i.indexrelid
|
|
|
|
WHERE relnamespace = 'pg_catalog'::regnamespace AND relkind = 'i'
|
|
|
|
AND i.indisunique
|
|
|
|
AND c.oid NOT IN (SELECT conindid FROM pg_constraint)
|
|
|
|
ORDER BY 1;
|
|
|
|
relname
|
|
|
|
---------
|
|
|
|
(0 rows)
|
|
|
|
|