Query goal: | Do not keep in your database elements that are not needed by anybody. These should be put in use or dropped, otherwise these are dead code. |
Notes about the query: | The query finds all the non-system schemas that do not contain any schema object. |
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: | Drop the schema or start to use it. |
Data source: | system catalog only |
SQL query: | Click on query to copy it
SELECT nspname AS schema_name FROM pg_namespace AS n INNER JOIN pg_authid AS a ON n.nspowner=a.oid WHERE (nspname='public' OR rolname<>'postgres') AND NOT EXISTS (SELECT 1 FROM pg_class AS c WHERE n.oid=c.relnamespace) AND NOT EXISTS (SELECT 1 FROM pg_type AS pt WHERE n.oid=pt.typnamespace) AND NOT EXISTS (SELECT 1 FROM pg_proc AS pc WHERE n.oid=pc.pronamespace) ORDER BY nspname; |
SQL query | Description |
---|---|
SELECT format('DROP SCHEMA %1$I;', nspname) AS statements FROM pg_namespace AS n INNER JOIN pg_authid AS a ON n.nspowner=a.oid WHERE (nspname='public' OR rolname<>'postgres') AND NOT EXISTS (SELECT 1 FROM pg_class AS c WHERE n.oid=c.relnamespace) AND NOT EXISTS (SELECT 1 FROM pg_type AS pt WHERE n.oid=pt.typnamespace) AND NOT EXISTS (SELECT 1 FROM pg_proc AS pc WHERE n.oid=pc.pronamespace) ORDER BY nspname; | Drop the schema. |
Collection name | Collection 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 . |
Category name | Category description |
---|---|
Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
Unused implementation elements | Queries of this catergory provide information about the database objects that are not used. |
Reference |
---|
https://en.wikipedia.org/wiki/Dead_code |
The corresponding code smells in case of cleaning code are "F4: Dead Function" and "G9: Dead Code". (Robert C. Martin, Clean Code) |