Skip to content

Commit 273ae97

Browse files
committed
Add a sanity check to make sure that all system catalogs that have OIDs
also have a unique index on OID.
1 parent 039cb47 commit 273ae97

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/test/regress/expected/sanity_check.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@ SELECT relname, relhasindex
6565
tenk2 | t
6666
(53 rows)
6767

68+
--
69+
-- another sanity check: every system catalog that has OIDs should have
70+
-- a unique index on OID. This ensures that the OIDs will be unique,
71+
-- even after the OID counter wraps around.
72+
-- We exclude non-system tables from the check by looking at nspname.
73+
--
74+
SELECT relname, nspname
75+
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
76+
WHERE relhasoids
77+
AND ((nspname ~ '^pg_') IS NOT FALSE)
78+
AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE indrelid = c.oid
79+
AND indkey[0] = -2 AND indkey[1] = 0 AND indisunique);
80+
relname | nspname
81+
---------+---------
82+
(0 rows)
83+

src/test/regress/sql/sanity_check.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
VACUUM;
2+
33
--
44
-- sanity check, if we don't have indices the test will take years to
55
-- complete. But skip TOAST relations since they will have varying
@@ -10,3 +10,15 @@ SELECT relname, relhasindex
1010
WHERE relhasindex AND relkind != 't'
1111
ORDER BY relname;
1212

13+
--
14+
-- another sanity check: every system catalog that has OIDs should have
15+
-- a unique index on OID. This ensures that the OIDs will be unique,
16+
-- even after the OID counter wraps around.
17+
-- We exclude non-system tables from the check by looking at nspname.
18+
--
19+
SELECT relname, nspname
20+
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
21+
WHERE relhasoids
22+
AND ((nspname ~ '^pg_') IS NOT FALSE)
23+
AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE indrelid = c.oid
24+
AND indkey[0] = -2 AND indkey[1] = 0 AND indisunique);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy