mirror of
https://github.com/postgres/postgres.git
synced 2026-03-13 14:14:09 -04:00
As of v14, pg_depend contains almost 7000 "pin" entries recording the OIDs of built-in objects. This is a fair amount of bloat for every database, and it adds time to pg_depend lookups as well as initdb. We can get rid of all of those entries in favor of an OID range check, i.e. "OIDs below FirstUnpinnedObjectId are pinned". (template1 and the public schema are exceptions. Those exceptions are now wired into IsPinnedObject() instead of initdb's code for filling pg_depend, but it's the same amount of cruft either way.) The contents of pg_shdepend are modified likewise. Discussion: https://postgr.es/m/3737988.1618451008@sss.pgh.pa.us
74 lines
2.3 KiB
SQL
74 lines
2.3 KiB
SQL
--
|
|
-- 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
|
|
classid = 0 OR objid = 0 OR
|
|
deptype NOT IN ('a', 'e', 'i', 'n', 'x', 'P', 'S');
|
|
|
|
|
|
-- **************** pg_shdepend ****************
|
|
|
|
-- Look for illegal values in pg_shdepend fields.
|
|
|
|
SELECT *
|
|
FROM pg_shdepend as d1
|
|
WHERE refclassid = 0 OR refobjid = 0 OR
|
|
classid = 0 OR objid = 0 OR
|
|
deptype NOT IN ('a', 'o', 'r', 't');
|
|
|
|
|
|
-- **************** pg_class ****************
|
|
|
|
-- 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.
|
|
|
|
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;
|
|
|
|
|
|
-- 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;
|
|
|
|
|
|
-- 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;
|