1-- 2-- MISC_SANITY 3-- Sanity checks for common errors in making system tables that don't fit 4-- comfortably into either opr_sanity or type_sanity. 5-- 6-- Every test failure in this file should be closely inspected. 7-- The description of the failing test should be read carefully before 8-- adjusting the expected output. In most cases, the queries should 9-- not find *any* matching entries. 10-- 11-- NB: run this test early, because some later tests create bogus entries. 12 13 14-- **************** pg_depend **************** 15 16-- Look for illegal values in pg_depend fields. 17-- classid/objid can be zero, but only in 'p' entries 18 19SELECT * 20FROM pg_depend as d1 21WHERE refclassid = 0 OR refobjid = 0 OR 22 deptype NOT IN ('a', 'e', 'i', 'n', 'p') OR 23 (deptype != 'p' AND (classid = 0 OR objid = 0)) OR 24 (deptype = 'p' AND (classid != 0 OR objid != 0 OR objsubid != 0)); 25 26-- **************** pg_shdepend **************** 27 28-- Look for illegal values in pg_shdepend fields. 29-- classid/objid can be zero, but only in 'p' entries 30 31SELECT * 32FROM pg_shdepend as d1 33WHERE refclassid = 0 OR refobjid = 0 OR 34 deptype NOT IN ('a', 'o', 'p', 'r') OR 35 (deptype != 'p' AND (classid = 0 OR objid = 0)) OR 36 (deptype = 'p' AND (dbid != 0 OR classid != 0 OR objid != 0 OR objsubid != 0)); 37 38 39-- Check each OID-containing system catalog to see if its lowest-numbered OID 40-- is pinned. If not, and if that OID was generated during initdb, then 41-- perhaps initdb forgot to scan that catalog for pinnable entries. 42-- Generally, it's okay for a catalog to be listed in the output of this 43-- test if that catalog is scanned by initdb.c's setup_depend() function; 44-- whatever OID the test is complaining about must have been added later 45-- in initdb, where it intentionally isn't pinned. Legitimate exceptions 46-- to that rule are listed in the comments in setup_depend(). 47 48do $$ 49declare relnm text; 50 reloid oid; 51 shared bool; 52 lowoid oid; 53 pinned bool; 54begin 55for relnm, reloid, shared in 56 select relname, oid, relisshared from pg_class 57 where relhasoids and oid < 16384 order by 1 58loop 59 execute 'select min(oid) from ' || relnm into lowoid; 60 continue when lowoid is null or lowoid >= 16384; 61 if shared then 62 pinned := exists(select 1 from pg_shdepend 63 where refclassid = reloid and refobjid = lowoid 64 and deptype = 'p'); 65 else 66 pinned := exists(select 1 from pg_depend 67 where refclassid = reloid and refobjid = lowoid 68 and deptype = 'p'); 69 end if; 70 if not pinned then 71 raise notice '% contains unpinned initdb-created object(s)', relnm; 72 end if; 73end loop; 74end$$; 75