Greenplum6 數據庫數據庫學習_數據字典

GP6數據字典中帶隱藏字段oid的全部表,這些表的oid增長都是共享一個序列,固然,還有其餘的表也是共享這些序列,好比pg_class的relfilenode

查詢語句:
postgres=# select attrelid::regclass,attname 
from pg_attribute a ,pg_class b
where a.attrelid=b.oid
and b.relnamespace=11
and atttypid=26
and b.relstorage='h'
and attname='oid'
and b.relname not like '%index';
        attrelid         | attname 
-------------------------+---------
 pg_proc                 | oid
 pg_type                 | oid
 pg_class                | oid
 pg_attrdef              | oid
 pg_constraint           | oid
 pg_operator             | oid
 pg_opfamily             | oid
 pg_opclass              | oid
 pg_am                   | oid
 pg_amop                 | oid
 pg_amproc               | oid
 pg_language             | oid
 pg_largeobject_metadata | oid
 pg_rewrite              | oid
 pg_trigger              | oid
 pg_event_trigger        | oid
 pg_cast                 | oid
 pg_enum                 | oid
 pg_namespace            | oid
 pg_conversion           | oid
 pg_database             | oid
 pg_tablespace           | oid
 pg_authid               | oid
 pg_ts_config            | oid
 pg_ts_dict              | oid
 pg_ts_parser            | oid
 pg_ts_template          | oid
 pg_extension            | oid
 pg_foreign_data_wrapper | oid
 pg_foreign_server       | oid
 pg_user_mapping         | oid
 pg_default_acl          | oid
 pg_collation            | oid
 pg_resqueue             | oid
 pg_resqueuecapability   | oid
 pg_resourcetype         | oid
 pg_resgroup             | oid
 pg_resgroupcapability   | oid
 pg_extprotocol          | oid
 pg_partition            | oid
 pg_partition_rule       | oid
 pg_compression          | oid
(42 rows)

postgres=# 

postgres=#  select * from pg_attribute a where atttypid=26 limit 1;
-[ RECORD 1 ]-+-------------
attrelid      | 1255
attname       | pronamespace
atttypid      | 26
attstattarget | -1
attlen        | 4
attnum        | 2
attndims      | 0
attcacheoff   | -1
atttypmod     | -1
attbyval      | t
attstorage    | p
attalign      | i
attnotnull    | t
atthasdef     | f
attisdropped  | f
attislocal    | t
attinhcount   | 0
attcollation  | 0
attacl        | 
attoptions    | 
attfdwoptions | 

postgres=# \x
Expanded display is on.
postgres=#  select * from pg_class a where relnamespace=11 limit 1;
-[ RECORD 1 ]--+--------------------------------
relname        | pg_attribute_relid_attnam_index
relnamespace   | 11
reltype        | 0
reloftype      | 0
relowner       | 10
relam          | 403
relfilenode    | 0
reltablespace  | 0
relpages       | 8
reltuples      | 3367
relallvisible  | 0
reltoastrelid  | 0
relhasindex    | f
relisshared    | f
relpersistence | p
relkind        | i
relstorage     | h
relnatts       | 2
relchecks      | 0
relhasoids     | f
relhaspkey     | f
relhasrules    | f
relhastriggers | f
relhassubclass | f
relispopulated | t
relreplident   | n
relfrozenxid   | 0
relminmxid     | 0
relacl         | 
reloptions     |

如何識別對象

一、識別臨時表、UNLOGGED TABLE、臨時表

select relname from pg_class where relpersistence=? and relkind='r';  
pg_class 的relpersistence用於識別表是什麼表(正常表、不記日誌表、臨時表)。 relkind用於識別是什麼對象類別(表、索引、序列、切片、視圖、物化視圖、複合類型、外部表、分區表)。
relpersistence    
        p = permanent table, u = unlogged table, t = temporary table  
relkind   
        r = ordinary table, i = index, S = sequence, t = TOAST table, v = view, m = materialized view, c = composite type, f = foreign table, p = partitioned table

Greenplum 擴展

pg_class.relstorage 用於區分是什麼存儲

h = 堆表(heap)  
a = append only row存儲表  
c = append only column存儲表

存儲過程

pg_proc

數據庫

pg_database

表空間

pg_tablespace

schema

pg_namespace

用戶

pg_roles

索引接口

pg_am

如何獲取對象定義

使用這些函數接口,能夠得到對應對象的定義。

pg_get_indexdef  

pg_get_functiondef  

pg_get_triggerdef  

pg_get_ruledef  

pg_get_viewdef  

pg_get_constraintdef
postgres=# select * from pg_get_indexdef('idx_tbl2_1'::regclass);  
                 pg_get_indexdef                    
--------------------------------------------------  
 CREATE INDEX idx_tbl2_1 ON tbl2 USING btree (id)  
(1 row)

將oid 轉換成名稱的集中類型

名字 引用 描述
regproc pg_proc 函數名
regprocedure pg_proc 帶參數類型的函數
regoper pg_operator 操做符名
regoperator pg_operator 帶參數類型操做符
regclass pg_class 關係名

舉例子

postgres=# select 1259::regclass;
 regclass 
----------
 pg_class
(1 row)

postgres=# select oid,relname from pg_class where oid='pg_class'::regclass;
 oid  | relname  
------+----------
 1259 | pg_class
(1 row)

postgres=# select oid::regoper,oid::regoperator,oid,oprname from pg_operator limit 1;
     oid      |        oid        | oid | oprname 
--------------+-------------------+-----+---------
 pg_catalog.= | =(integer,bigint) |  15 | =
(1 row)

postgres=# select oid:: regoper,oid::regoperator,oid,oprname from pg_operator limit 1;
     oid      |        oid        | oid | oprname 
--------------+-------------------+-----+---------
 pg_catalog.= | =(integer,bigint) |  15 | =
(1 row)
相關文章
相關標籤/搜索