我需要db中包含的对象列表:表格,序列等......
获取表格列表是我唯一能够找到的。
我可以使用哪些想法来获取所有内容?
答案 0 :(得分:9)
您可以使用INFORMATION_SCHEMA表以及系统目录来执行此操作。
http://www.alberton.info/postgresql_meta_info.html
如,
列出序列
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'
);
列出触发器
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');