WITH routine_count AS (SELECT Count(*) AS number_of_routines_that_use_xmin
FROM
pg_catalog.pg_proc,
pg_catalog.pg_namespace
WHERE
pg_proc.pronamespace = pg_namespace.oid
AND pg_proc.prokind<>'a'
AND pg_get_functiondef(pg_proc.oid)~*'[[:space:]](UPDATE|DELETE)[[:space:]][^;]*[[:space:]]WHERE[[:space:]][^;]*[[:space:]]xmin[[:space:]]*=[[:space:]]*'
AND pg_namespace.nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
AND NOT EXISTS (SELECT 1
FROM pg_catalog.pg_depend d
WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE d.refobjid=e.oid) AND
d.objid=pg_proc.oid)),
view_count AS (SELECT
Count(*) AS number_of_views_that_provide_xmin_column
FROM (SELECT
table_schema,
table_name
FROM
information_schema.views AS v
WHERE table_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
AND EXISTS (SELECT 1
FROM information_schema.columns AS c
WHERE v.table_schema=c.table_schema AND v.table_name=c.table_name AND c.data_type='xid')
UNION SELECT nspname, relname
FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid
INNER JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid INNER JOIN pg_type ON
pg_attribute.atttypid=pg_type.oid
WHERE relkind = 'm' AND attnum>=1 AND attisdropped='f' AND typname='xid') AS foo)
SELECT number_of_routines_that_use_xmin, number_of_views_that_provide_xmin_column
FROM routine_count, view_count
WHERE number_of_routines_that_use_xmin>0 OR number_of_views_that_provide_xmin_column>0;