postgresql/src/test/regress/sql/misc_sanity.sql
Tom Lane 95e28b7f0c Fix over-aggressive sanity check in misc_sanity.sql.
Fix thinko in commit 8be8510cf: it's okay to have dbid == 0 in normal
(non-pin) entries in pg_shdepend, because global objects such as
databases are entered that way.  The test would pass so long as it
was run in a cluster containing no databases/tablespaces owned by,
or granted to, roles other than the bootstrap superuser.  That's the
expected situation for "make check", but for "make installcheck", not
so much.

Reported by Ryan Murphy.

Discussion: https://postgr.es/m/CAHeEsBc6EQe0mxGBKDXAwJbntgfvoAd5MQC-5362SmC3Tng_6g@mail.gmail.com
2017-08-28 10:14:46 -04:00

74 lines
2.6 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.
-- classid/objid can be zero, but only in 'p' entries
SELECT *
FROM pg_depend as d1
WHERE refclassid = 0 OR refobjid = 0 OR
deptype NOT IN ('a', 'e', 'i', 'n', 'p') OR
(deptype != 'p' AND (classid = 0 OR objid = 0)) OR
(deptype = 'p' AND (classid != 0 OR objid != 0 OR objsubid != 0));
-- **************** pg_shdepend ****************
-- Look for illegal values in pg_shdepend fields.
-- classid/objid can be zero, but only in 'p' entries
SELECT *
FROM pg_shdepend as d1
WHERE refclassid = 0 OR refobjid = 0 OR
deptype NOT IN ('a', 'o', 'p', 'r') OR
(deptype != 'p' AND (classid = 0 OR objid = 0)) OR
(deptype = 'p' AND (dbid != 0 OR classid != 0 OR objid != 0 OR objsubid != 0));
-- Check each OID-containing system catalog to see if its lowest-numbered OID
-- is pinned. If not, and if that OID was generated during initdb, then
-- perhaps initdb forgot to scan that catalog for pinnable entries.
-- Generally, it's okay for a catalog to be listed in the output of this
-- test if that catalog is scanned by initdb.c's setup_depend() function;
-- whatever OID the test is complaining about must have been added later
-- in initdb, where it intentionally isn't pinned. Legitimate exceptions
-- to that rule are listed in the comments in setup_depend().
do $$
declare relnm text;
reloid oid;
shared bool;
lowoid oid;
pinned bool;
begin
for relnm, reloid, shared in
select relname, oid, relisshared from pg_class
where relhasoids and oid < 16384 order by 1
loop
execute 'select min(oid) from ' || relnm into lowoid;
continue when lowoid is null or lowoid >= 16384;
if shared then
pinned := exists(select 1 from pg_shdepend
where refclassid = reloid and refobjid = lowoid
and deptype = 'p');
else
pinned := exists(select 1 from pg_depend
where refclassid = reloid and refobjid = lowoid
and deptype = 'p');
end if;
if not pinned then
raise notice '% contains unpinned initdb-created object(s)', relnm;
end if;
end loop;
end$$;