[ORACLE]Oracle数据字典

X$

X$表是Oracle数据库的核心部分,用于跟踪数据库内部信息,维护数据库的正常运行。

CREATE OR REPLACE VIEW BH AS SELECT * FROM SYS.X$BH;
CREATE OR REPLACE PUBLIC SYNONYM X$BH FOR BH;

Oracle 的 X$表信息可以从V$FIXED_TABLE中查到:

SYS @ D4C>select count(*) from v$fixed_table where name like 'X$%';
  COUNT(*)
----------
      1378
SYS @ D4C>select count(*) from v$fixed_table where name like 'GV$%';
  COUNT(*)
----------
       740
SYS @ D4C>select count(*) from v$fixed_table where name like 'V$%';
  COUNT(*)
----------
       778
SYS @ D4C>select count(*) from v$fixed_table;
  COUNT(*)
----------
      2898
select name from v$fixed_table  where name not like 'GV%' and name not like 'V$%' and name not like 'X$%';
    NAME
--------------------------------------------------------------------------------------------------------------------------------
GO$SQL_BIND_CAPTURE
O$SQL_BIND_CAPTURE

 数据字典表

数据字典表用以存储表、索引、约束以及其他数据库结构的信息。这些对象通常是以“$”结尾(例如:TAB$OBJ$TS$、SYN$等)。Bsq是非常重要的一个文件,其中包含了数据字典的定义以及注释说明,深入学习Oracle数据库的用户都应该仔细阅读该文件,该文件位于$ORACLE_HOME/rdbms/admin目录下(在Oracle 11gbsq文件被分别归类到不通的.bsq文件)。

当用户创建一张数据表时,Oracle 将会在后台执行一系列的内部操作,比如向 obj$表中插入数据、向 tab$表中记录表数据、向 col$表中记录字段信息、向 con$记录约束信息、向seg$中记录数据段信息等,

select dbms_metadata.get_ddl('TABLE','TX1') from dual;

DBMS_METADATA.GET_DDL('TABLE','TX1')
--------------------------------------------------------------------------------

  CREATE TABLE "SYS"."TX1"
   (    "X" NUMBER(*,0)
   ) PCTFREE 10 PCTUSED 40 INI

 

  DBA_OBJECTS 字典视图就是基于OBJ$数据字典表创建的,DBA_OBJECTS中有两个字段经常使人误解"OBJECT_ID"和"DATA_OBJECT_ID"。这两个字段分别来自 OBJ$中的 OBJ#和 DATAOBJ#,其中OBJ#(也即OBJECT_ID)可以被看作是对象的逻辑号(类似序列号一样分配),该序号一旦分配之后就不会发生改变;而 DATAOBJ#(也即 DATA_OBJECT_ID)则是和物理存储关联的编号,通常被认为是对象的物理号,这个编号会随着对象物理存储结构的改变而发生改变。


当用户创建一张数据表时,Oracle 将会在后台执行一系列的内部操作,比如向 obj$表中插入数据、向 tab$表中记录表数据、向 col$表中记录字段信息、向 con$记录约束信息、向seg$中记录数据段信息等,

select dbms_metadata.get_ddl('TABLE','EYGLE') from dual;

 

OBJ$是一个底层的字典表,其中记录了数据库中所有对象的信息,DBA_OBJECTS 视图基于 OBJ$建立,一脉相承的,ALL_OBJECTS 和 USER_OBJECTS 视图也随之建立。
OBJ 是一个对于 USER_OBJECTS 建立的同义词,其创建语句为:

    CREATE PUBLIC SYNONYM OBJ FOR SYS.USER_OBJECTS;

 

静态数据字典视图

静态数据字典视图是由catalog.sql脚本创建(在$ORACLE_HOME/rdbms/admin下)。静态数据字典中的视图可以分为三类,它们分别由三个前缀构成:USER_*ALL_*DBA_*

DBA_SOURCE/USER_SOUCE/ALL_SOURCE 用于保存存储对象(Stored Object)的源码。
这类视图存储的对象类型包括 FUNCTION, JAVA SOURCE, PACKAGE, PACKAGE BODY,PROCEDURE, TRIGGER, TYPE, TYPE BODY 等:
通过 TEXT 字段能够获取相关对象的创建文本:

动态性能视图

动态性能视图基于从数据库内存结构构建的虚拟表。因此,它们不是存储在数据库中的常规表。由于数据动态更新,所以,动态性能视图的读一致性不能保证。

SYS是这些动态性能表的所有者,这些表的名字都以V_$开头,基于这些表的视图被创建后,Oracle还会为视图创建公共同义词。同义词名称以V$开头,例如,视图V$DATAFILE包含数据库数据文件的信息,而V$FIXED_TABLE包含数据库中所有动态性能表和视图的信息。NOMOUNT状态不能查询所有的V$视图。因为动态性能视图不是真实表,所以数据依赖于数据库和实例的状态。例如,当数据库处于NOMOUNT时,可以查询V$INSTANCEV$BGPROCEP。但是,在MOUNT数据库之前,不能查询V$DATAFILE

只有赋予了SELECT ANY DICTIONARY权限的用户才可以查询所有的V$视图。

v$动态视图主要是针对SGA和数据库实例进程的显示。在这个过程中,Oracle使用了DMADirect Memory Access)技术,可以高效的获取这些分析数据。

 数据库启动时,Oracle动态创建X$表,在此基础之上,Oracle创建了GV$V$视图。

 

 系统数据字典视图定义有关的几个视图

 DICTIONARY视图记录了全部数据字典表的名称和解释,它有一个同义词DICT

 DICT_COLUMNS视图记录了全部数据字典表里字段名称和解释。

如果想知道数据字典中的USER_INDEXES视图中各字段的详细含义,那么可以用如下SQL语句:

SQL> SELECT COLUMN_NAME, COMMENTS  FROM DICT_COLUMNS WHERE TABLE_NAME = 'USER_INDEXES';

COLUMN_NAME               COMMENTS
------------------------------ ----------------------------------------------------------------------------------------------------
INDEX_NAME               Name of the index
INDEX_TYPE
TABLE_OWNER               Owner of the indexed object
TABLE_NAME               Name of the indexed object
TABLE_TYPE               Type of the indexed object
UNIQUENESS               Uniqueness status of the index:    "UNIQUE",  "NONUNIQUE", or "BITMAP"
COMPRESSION               Compression property of the index: "ENABLED",  "DISABLED", or NULL
PREFIX_LENGTH               Number of key columns in the prefix used for compression
TABLESPACE_NAME            Name of the tablespace containing the index
INI_TRANS               Initial number of transactions
MAX_TRANS               Maximum number of transactions
INITIAL_EXTENT               Size of the initial extent in bytes
NEXT_EXTENT               Size of secondary extents in bytes
MIN_EXTENTS               Minimum number of extents allowed in the segment
MAX_EXTENTS               Maximum number of extents allowed in the segment
PCT_INCREASE               Percentage increase in extent size
PCT_THRESHOLD               Threshold percentage of block space allowed per index entry
INCLUDE_COLUMN               User column-id for last column to be included in index-only table top index
FREELISTS               Number of process freelists allocated in this segment
FREELIST_GROUPS            Number of freelist groups allocated to this segment
PCT_FREE               Minimum percentage of free space in a block
LOGGING                Logging attribute
BLEVEL                   B-Tree level
LEAF_BLOCKS               The number of leaf blocks in the index
DISTINCT_KEYS               The number of distinct keys in the index
AVG_LEAF_BLOCKS_PER_KEY        The average number of leaf blocks per key
AVG_DATA_BLOCKS_PER_KEY        The average number of data blocks per key
CLUSTERING_FACTOR           A measurement of the amount of (dis)order of the table this index is for
STATUS                   Whether the non-partitioned index is in USABLE or not
NUM_ROWS               Number of rows in the index
SAMPLE_SIZE               The sample size used in analyzing this index
LAST_ANALYZED               The date of the most recent time this index was analyzed
DEGREE                   The number of threads per instance for scanning the partitioned index
INSTANCES               The number of instances across which the partitioned index is to be scanned
PARTITIONED               Is this index partitioned? YES or NO
TEMPORARY               Can the current session only see data that it place in this object itself?
GENERATED               Was the name of this index system generated?
SECONDARY               Is the index object created as part of icreate for domain indexes?
BUFFER_POOL               The default buffer pool to be used for index blocks
FLASH_CACHE               The default flash cache hint to be used for index blocks
CELL_FLASH_CACHE           The default cell flash cache hint to be used for index blocks
USER_STATS               Were the statistics entered directly by the user?
DURATION               If index on temporary table, then duration is sys$session or sys$transaction else NULL
PCT_DIRECT_ACCESS           If index on IOT, then this is percentage of rows with Valid guess
ITYP_OWNER               If domain index, then this is the indextype owner
ITYP_NAME               If domain index, then this is the name of the associated indextype
PARAMETERS               If domain index, then this is the parameter string
GLOBAL_STATS               Are the statistics calculated without merging underlying partitions?
DOMIDX_STATUS               Is the indextype of the domain index valid
DOMIDX_OPSTATUS            Status of the operation on the domain index
FUNCIDX_STATUS               Is the Function-based Index DISABLED or ENABLED?
JOIN_INDEX               Is this index a join index?
IOT_REDUNDANT_PKEY_ELIM        Were redundant primary key columns eliminated from iot secondary index?
DROPPED                Whether index is dropped and is in Recycle Bin
VISIBILITY               Whether the index is VISIBLE or INVISIBLE to the optimizer
DOMIDX_MANAGEMENT           If this a domain index, then whether it is system managed or user managed
SEGMENT_CREATED            Whether the index segment has been created
ORPHANED_ENTRIES
INDEXING
AUTO                   Whether the index is automatically created
CONSTRAINT_INDEX

61 rows selected.

V$FIXED_TABLE可以查询数据库中所有底层的表。V$FIXED_TABLE视图显示数据库中所有动态性能表、视图和导出表。由于某些V$表(例如V$ROLLNAME)涉及底层的表,因此,没有列出.

V$FIXED_VIEW_DEFINITION这个视图包含所有固定视图(以V$起头的视图)的定义,v$fixed_view_definition 视图是我们研究 Oracle 对象关系的一个入口,仔细理解 Oracle 的数据字典机制,有助于深入了解和学习 Oracle 数据库知识。

 

v$session_wait --对于不同进程的等待进行查询
   v$system_event --数据库全局行等待

posted on 2020-05-04 00:05  InnoLeo  阅读(766)  评论(0编辑  收藏  举报