| 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 (opens in new tab) |
| Fixing Suggestion | Enable the rule or drop it. |
| Data Source | system catalog only |
| SQL Query |
|
SQL statements that help generate fixes for the identified problem.
Fix Action #1
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.
Fix Action #2
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.
| SQL Query to Generate Fix | Description |
|---|---|
| Enable the rule. |
| Drop the rule. |
Collections
This query belongs to the following collections:
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 .
| 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:
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.
| 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. |
Further reading and related materials: