How to get a list of all objects? - PostgreSQL

I need a list of objects included in db: tables, sequences, etc.


Getting the list of tables was the only thing I could find out.


Any ideas for what I could use to get everything?

+5
source share
1 answer

You can do this using the INFORMATION_SCHEMA tables as well as the system catalog.

http://www.alberton.info/postgresql_meta_info.html

eg.

List Sequences

SELECT relname
FROM pg_class
WHERE relkind = 'S'
AND relnamespace IN (
    SELECT oid
    FROM pg_namespace
    WHERE nspname NOT LIKE 'pg_%'
    AND nspname != 'information_schema'
);

Trigger list

SELECT trg.tgname AS trigger_name
  FROM pg_trigger trg, pg_class tbl
 WHERE trg.tgrelid = tbl.oid
   AND tbl.relname !~ '^pg_';
-- or
SELECT tgname AS trigger_name
  FROM pg_trigger
 WHERE tgname !~ '^pg_';

-- with INFORMATION_SCHEMA:

SELECT DISTINCT trigger_name
  FROM information_schema.triggers
 WHERE trigger_schema NOT IN
       ('pg_catalog', 'information_schema');
+7
source

All Articles