Last active
October 23, 2022 20:56
-
-
Save dsouzajude/aaffb0a87b7312fec683bee8ba05411e to your computer and use it in GitHub Desktop.
Run sanity checks to check source and destination is in sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Sanity check with schemas and tables -------------------------- | |
-- Check counts of objects in the database | |
SELECT | |
n.nspname as schema_name | |
,CASE c.relkind | |
WHEN 'r' THEN 'table' | |
WHEN 'v' THEN 'view' | |
WHEN 'i' THEN 'index' | |
WHEN 's' THEN 'special' | |
END as object_type | |
,count(1) as object_count | |
FROM pg_catalog.pg_class c | |
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | |
WHERE c.relkind IN ('r','v','i','s') | |
AND n.nspname NOT IN ('pg_catalog', 'pg_toast') | |
GROUP BY n.nspname, | |
CASE c.relkind | |
WHEN 'r' THEN 'table' | |
WHEN 'v' THEN 'view' | |
WHEN 'i' THEN 'index' | |
WHEN 's' THEN 'special' | |
END | |
ORDER BY n.nspname, | |
CASE c.relkind | |
WHEN 'r' THEN 'table' | |
WHEN 'v' THEN 'view' | |
WHEN 'i' THEN 'index' | |
WHEN 's' THEN 'special' | |
END; | |
-- Check the counts of a couple of important tables | |
SELECT COUNT(*) FROM <TABLE_1>; | |
SELECT COUNT(*) FROM <TABLE_2>; | |
SELECT COUNT(*) FROM <TABLE_3>; | |
-- Check the max of a couple of important tables | |
SELECT MAX(id) FROM <TABLE_1>; | |
SELECT MAX(id) FROM <TABLE_2>; | |
SELECT MAX(id) FROM <TABLE_3>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment