WITH disabled_rules AS (SELECT n.nspname AS schemaname,
c.relname AS tablename,
r.rulename,
CASE WHEN ev_type='1' THEN 'SELECT' WHEN ev_type='2' THEN 'UPDATE' WHEN ev_type='3' THEN 'INSERT' ELSE 'DELETE' END AS event,
pg_get_ruledef(r.oid) AS definition
FROM pg_rewrite r
JOIN pg_class c ON c.oid = r.ev_class
JOIN pg_namespace n ON n.oid = c.relnamespace
JOIN pg_authid u ON n.nspowner = u.oid
WHERE ev_enabled='D' AND
(n.nspname = 'public' OR u.rolname <> 'postgres'))
SELECT schemaname, tablename, rulename, event, definition
FROM disabled_rules
ORDER BY schemaname, tablename, rulename;
SQL statements that help generate fixes for the identified problem.
SQL Query to Generate Fix
Description
WITH disabled_rules AS (SELECT n.nspname AS schemaname,
c.relname AS tablename,
r.rulename
FROM pg_rewrite r
JOIN pg_class c ON c.oid = r.ev_class
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE ev_enabled='D')
SELECT format('ALTER TABLE %1$I.%2$I ENABLE RULE %3$I;', schemaname, tablename, rulename) AS statements
FROM disabled_rules
ORDER BY schemaname, tablename, rulename;
Enable the rule.
WITH disabled_rules AS (SELECT n.nspname AS schemaname,
c.relname AS tablename,
r.rulename
FROM pg_rewrite r
JOIN pg_class c ON c.oid = r.ev_class
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE ev_enabled='D')
SELECT format('DROP RULE %1$I ON %2$I.%3$I RESTRICT;', rulename, schemaname, tablename) AS statements
FROM disabled_rules
ORDER BY schemaname, tablename, rulename;
Drop the rule.
Collections
This query belongs to the following collections:
Name
Description
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
Categories
This query is classified under the following categories:
Name
Description
Triggers and rules
Queries of this category provide information about triggers and rules in a database.
Unused implementation elements
Queries of this catergory provide information about the database objects that are not used.