The list of all the queries

Disabled rules

Query goal: Identify disabled rules. These should be enabled or dropped, otherwise these are dead code.
Notes about the query: Rules are specific to PostgreSQL and thus it is not possible to get information about these from the INFORMATION_SCHEMA views.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: High (Few or no false-positive results)
Query license: MIT License
Fixing suggestion: Enable the rule or drop it.
Data source: system catalog only
SQL query: Click on query to copy it

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 for generating SQL statements that help us to fix the problem

SQL queryDescription
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 where the query belongs to

Collection nameCollection description
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 where the query belongs to

Category nameCategory description
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.

Reference materials for further reading

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

The list of all the queries