Goal Identify disabled rules. These should be enabled or dropped, otherwise these are dead code.
Notes Rules are specific to PostgreSQL and thus it is not possible to get information about these from the INFORMATION_SCHEMA views.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability High (Few or no false-positive results)
License MIT License
Fixing Suggestion Enable the rule or drop it.
Data Source system catalog only
SQL Query
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 FixDescription
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:

NameDescription
Find problems automaticallyQueries, 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:

NameDescription
Triggers and rulesQueries of this category provide information about triggers and rules in a database.
Unused implementation elementsQueries of this catergory provide information about the database objects that are not used.

Further reading and related materials:

Reference
https://en.wikipedia.org/wiki/Dead_code