summaryrefslogtreecommitdiffstats
path: root/src/test/regress/sql/sanity_check.sql
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:15:05 +0000
commit46651ce6fe013220ed397add242004d764fc0153 (patch)
tree6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/test/regress/sql/sanity_check.sql
parentInitial commit. (diff)
downloadpostgresql-14-46651ce6fe013220ed397add242004d764fc0153.tar.xz
postgresql-14-46651ce6fe013220ed397add242004d764fc0153.zip
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/regress/sql/sanity_check.sql')
-rw-r--r--src/test/regress/sql/sanity_check.sql39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/regress/sql/sanity_check.sql b/src/test/regress/sql/sanity_check.sql
new file mode 100644
index 0000000..a4ec003
--- /dev/null
+++ b/src/test/regress/sql/sanity_check.sql
@@ -0,0 +1,39 @@
+VACUUM;
+
+--
+-- sanity check, if we don't have indices the test will take years to
+-- complete. But skip TOAST relations (since they will have varying
+-- names depending on the current OID counter) as well as temp tables
+-- of other backends (to avoid timing-dependent behavior).
+--
+
+-- temporarily disable fancy output, so catalog changes create less diff noise
+\a\t
+
+SELECT relname, relhasindex
+ FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
+ WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE
+ ORDER BY relname;
+
+-- restore normal output mode
+\a\t
+
+--
+-- another sanity check: every system catalog that has OIDs should have
+-- a unique index on OID. This ensures that the OIDs will be unique,
+-- even after the OID counter wraps around.
+-- We exclude non-system tables from the check by looking at nspname.
+--
+SELECT relname, nspname
+ FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace JOIN pg_attribute a ON (attrelid = c.oid AND attname = 'oid')
+ WHERE relkind = 'r' and c.oid < 16384
+ AND ((nspname ~ '^pg_') IS NOT FALSE)
+ AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE indrelid = c.oid
+ AND indkey[0] = a.attnum AND indnatts = 1
+ AND indisunique AND indimmediate);
+
+-- check that relations without storage don't have relfilenode
+SELECT relname, relkind
+ FROM pg_class
+ WHERE relkind IN ('v', 'c', 'f', 'p', 'I')
+ AND relfilenode <> 0;