postgreSQL數據字典簡介2-數據庫對象類

一、查詢Schema信息

1、select * from pg_namespace;

2、select * from information_schema.schemata;

3、select * from "current_schema"()

二、查詢表空間信息

select * from pg_tablespace;

三、查詢表信息

1、所有表

select * from pg_tables

2、分區表

select * from pg_partitioned_table

四、查詢索引信息

1、索引基本情況

select * from pg_index

select * from pg_indexes

2、索引訪問類型

select relname, n.amname as index_type
from pg_class m,
     pg_am n
where m.relam = n.oid
  and m.oid in
      (select b.indexrelid
       from pg_class a,
            pg_index b
       where a.oid = b.indrelid);

3、索引佔用空間情況

SELECT c.relname, c2.relname, c2.relpages * 8 as size_kb
FROM pg_class c,
     pg_class c2,
     pg_index i
WHERE c.oid = i.indrelid
  AND c2.oid = i.indexrelid
ORDER BY c2.relname;

4、索引定義

select a.relname, b.indexrelid, pg_get_indexdef(b.indexrelid)
from pg_class a,
     pg_index b
where a.oid = b.indrelid

五、查詢約束信息

1、基本情況

select * from pg_constraint

2、約束所關聯的表、索引情況

select tn.nspname,
       ts.relname  table_name,
       ts1.relname index_name,
       tc.conname,
       tc.contype,
       tc.confupdtype,
       tc.confmatchtype
from pg_constraint tc
         inner join pg_catalog.pg_namespace tn on tc.connamespace = tn.oid
         left join pg_class ts on ts.oid = tc.conrelid
         left join pg_class ts1 on ts1.oid = tc.conindid
where tn.nspname = 'caahuman'
order by ts.relname, ts1.relname

六、查詢函數定義

select t.oid, pg_get_functiondef(t.oid)
from "HR".pg_catalog.pg_proc t
order by t.oid

七、其他對象信息

1、視圖

select * from pg_views

2、觸發器

select * from pg_trigger

3、序列

select * from pg_sequence

4、自定義類型

select * from pg_type

你可能感兴趣的:(postgreSQL,postgresql)