Oracle数据字典详解

Oracle数据字典详解

学习笔记:oracle数据字典详解

---

本文为TTT学习笔记,首先介绍数据字典及查看方法,然后分类总结各类数据字典的表和视图。然后列出一些附例。

 

数据字典系统表,保存在system表空间中。

由表和视图组成,由服务器在安装数据库时自动创建,用户不可以直接修改数据库字典,在执行DDL语句时,oracle会自动修改。

记录一些表和视图(只读的),新建的表不要和这空间建在一起(9i以前的版本新用户建的表默认表空间为system,注意修改)

 

--查询数据字典:

select * from dictionary

 

--数据字典导出方法:

conn / as sysdba

spool on 

spool c:\dic.txt

select * from dictionary

spool off

 

主要四部分:

1,内部RDBMS表:x$……

2,数据字典表:……$

3,动态性能视图:gv$……,v$……

4,数据字典视图:user_……,all_……,dba_……

 

数据库启动时,动态创建x$,在X$基础上创建GV$,在GV$基础上创建V$X$表-->GV$(视图)--->V$(视图)

 

+++

一,内部RDBMS表 x$……,例如:x$kvit,x$bh,x$ksmsp,x$ksppi和x$ksppcv

核心部分,用于跟踪内部数据库信息,维持DB的正常运行。

是加密命名的,不允许sysdba以外的用户直接访问,显示授权不被允许。最好不要修改.

x$kvit=Kernel Layer Performance Layer V Information tables Transitory Instance parameter

数据库启动时,动态创建x$……

 

+++

二,数据字典表 ……$,如tab$,obj$,ts$……

--用来存储表、索引、约束以及其他数据库结构的信息。

--创建数据库时通过脚本sql.bsq来创建,脚本:$oracle_home/rdbms/admin/sql.bsq

 

+++

三,动态性能视图 gv$……,v$……,如V$parameter

--记录了DB运行时信息和统计数据,大部分动态性能视图被实时更新以反映DB当前状态。

--数据库创建时建立的。

--只有sysdba可以直接访问。

--查看表v$fixed_view_definition(***),可以查看GV$和V$视图的创建语句。(oracle提供一些特殊视图,用来记录其他视图的创建方式,v$fixed_view_definition就是其中之一)

--select view_definition from v$fixed_view_definition where view_name='V$FIXED_TABLE';

 

--gv$……=Global V$,在X$……基础上创建,是为了满足OPS环境(多个实例)的需要面产生的,可以返回多个实例的信息。

V$……,在GV$……基础上创建,只返回当前实例的信息。定义语句都带有:where inst_id =USERENV('Instance')

 

--GV$和V$之后,oracle建立了GV_$和V_$视图,又为这些视图建立了公用同义词。由脚本catalog.sql实现的,脚本:$oracle_home/rdbms/admin/catalog.sql

create or replace view v_$process as select * from v$process;

create or replace public synonym v$process for v_$process;

 

create or replace view gv_$process as select * from gv$process;

create or replace public synonym gv$process for gv_$process;

 

-->可以看出:

V$(视图)-->V_$(视图)-->V$(公用同义词)

GV$(视图)-->GV_$(视图)-->GV$(公用同义词)

这样做的目的:通过V_$和GV_$,oracle把V$视图和GV视图和普通用户隔离开来。(oracle允许V_$视图权限可以授权给其他用户,但不允许任何对于V$视图的直接授权。)

所以,在非Sys用户下,我们访问的都是同义词,而不是V$视图或GV视图。

 

--oracle访问数据顺序:view-->同义词。

 

+++

四,数据库字典视图

--是在X$表和数据字典表之上建立的视图。

--创建数据库时由脚本catalog.sql创建。脚本 :$oracle_home/rdbms/admin/catalog.sql

--按前缀不同,作用范围的分为三类:

1、以user开头的数据字典: 包含当前用户所拥有的相关对象信息。--能够查到对象的所有者是当前用户的所有对象

select table_name from user_tables;  (scott) 5

2、以all开头的数据字典:  包含当前用户有权限访问的所有对象的信息。--能够查到所有当前用户有权限访问的对象

select table_name from all_tables;  (scott) 96

3、以dba开头的数据字典:  包含数据库所有相关对象的信息。--只能是有dba权限的用户查询,能查到数据库中所有对象

select table_name from dba_tables (sys system)

 

+++

附:

比较user,all,dba数据字典视图

各数据字典表数量比较

表Dictionary与V$fixed_table比较

通过V$parameter视图来追踪一下数据库的架构

oracle如何通过同义词定位对象(10046事件)

 

+++

比较user,all,dba数据字典视图

---

可以查看脚本catalog.sql中的定义:

 

+++

--USER_TABLES

create or replace view USER_TABLES

    (TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,

     PCT_FREE, PCT_USED,

     INI_TRANS, MAX_TRANS,

     INITIAL_EXTENT, NEXT_EXTENT,

     MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,

     FREELISTS, FREELIST_GROUPS, LOGGING,

     BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,

     AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,

     AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,

     DEGREE, INSTANCES, CACHE, TABLE_LOCK,

     SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,

     IOT_TYPE, TEMPORARY, SECONDARY, NESTED,

     BUFFER_POOL, ROW_MOVEMENT,

     GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,

     CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED)

as

select o.name, decode(bitand(t.property, 2151678048), 0, ts.name, null),

       decode(bitand(t.property, 1024), 0, null, co.name),

       decode((bitand(t.property, 512)+bitand(t.flags, 536870912)),

              0, null, co.name),

       decode(bitand(t.trigflag, 1073741824), 1073741824, 'UNUSABLE', 'VALID'),

       decode(bitand(t.property, 32+64), 0, mod(t.pctfree$, 100), 64, 0, null),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

          decode(bitand(t.property, 32+64), 0, t.pctused$, 64, 0, null)),

       decode(bitand(t.property, 32), 0, t.initrans, null),

       decode(bitand(t.property, 32), 0, t.maxtrans, null),

       s.iniexts * ts.blocksize,

       decode(bitand(ts.flags, 3), 1, to_number(NULL),

                                      s.extsize * ts.blocksize),

       s.minexts, s.maxexts,

       decode(bitand(ts.flags, 3), 1, to_number(NULL),

                                      s.extpct),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

         decode(bitand(o.flags, 2), 2, 1, decode(s.lists, 0, 1, s.lists))),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

         decode(bitand(o.flags, 2), 2, 1, decode(s.groups, 0, 1, s.groups))),

       decode(bitand(t.property, 32+64), 0,

                decode(bitand(t.flags, 32), 0, 'YES', 'NO'), null),

       decode(bitand(t.flags,1), 0, 'Y', 1, 'N', '?'),

       t.rowcnt,

       decode(bitand(t.property, 64), 0, t.blkcnt, null),

       decode(bitand(t.property, 64), 0, t.empcnt, null),

       decode(bitand(t.property, 64), 0, t.avgspc, null),

       t.chncnt, t.avgrln, t.avgspc_flb,

       decode(bitand(t.property, 64), 0, t.flbcnt, null),

       lpad(decode(t.degree, 32767, 'DEFAULT', nvl(t.degree,1)),10),

       lpad(decode(t.instances, 32767, 'DEFAULT', nvl(t.instances,1)),10),

       lpad(decode(bitand(t.flags, 8), 8, 'Y', 'N'),5),

       decode(bitand(t.flags, 6), 0, 'ENABLED', 'DISABLED'),

       t.samplesize, t.analyzetime,

       decode(bitand(t.property, 32), 32, 'YES', 'NO'),

       decode(bitand(t.property, 64), 64, 'IOT',

               decode(bitand(t.property, 512), 512, 'IOT_OVERFLOW',

               decode(bitand(t.flags, 536870912), 536870912, 'IOT_MAPPING', null))),

       decode(bitand(o.flags, 2), 0, 'N', 2, 'Y', 'N'),

       decode(bitand(o.flags, 16), 0, 'N', 16, 'Y', 'N'),

       decode(bitand(t.property, 8192), 8192, 'YES',

              decode(bitand(t.property, 1), 0, 'NO', 'YES')),

       decode(bitand(o.flags, 2), 2, 'DEFAULT',

             decode(s.cachehint, 0, 'DEFAULT', 1, 'KEEP', 2, 'RECYCLE', NULL)),

       decode(bitand(t.flags, 131072), 131072, 'ENABLED', 'DISABLED'),

       decode(bitand(t.flags, 512), 0, 'NO', 'YES'),

       decode(bitand(t.flags, 256), 0, 'NO', 'YES'),

       decode(bitand(o.flags, 2), 0, NULL,

           decode(bitand(t.property, 8388608), 8388608,

                  'SYS$SESSION', 'SYS$TRANSACTION')),

       decode(bitand(t.flags, 1024), 1024, 'ENABLED', 'DISABLED'),

       decode(bitand(o.flags, 2), 2, 'NO',

           decode(bitand(t.property, 2147483648), 2147483648, 'NO',

              decode(ksppcv.ksppstvl, 'TRUE', 'YES', 'NO'))),

       decode(bitand(t.property, 1024), 0, null, cu.name),

       decode(bitand(t.flags, 8388608), 8388608, 'ENABLED', 'DISABLED'),

       decode(bitand(t.property, 32), 32, null,

                decode(bitand(s.spare1, 2048), 2048, 'ENABLED', 'DISABLED')),

       decode(bitand(o.flags, 128), 128, 'YES', 'NO')

from sys.ts$ ts, sys.seg$ s, sys.obj$ co, sys.tab$ t, sys.obj$ o,

     sys.obj$ cx, sys.user$ cu, x$ksppcv ksppcv, x$ksppi ksppi

where o.owner# = userenv('SCHEMAID')

  and o.obj# = t.obj#

  and bitand(t.property, 1) = 0

  and bitand(o.flags, 128) = 0

  and t.bobj# = co.obj# (+)

  and t.ts# = ts.ts#

  and t.file# = s.file# (+)

  and t.block# = s.block# (+)

  and t.ts# = s.ts# (+)

  and t.dataobj# = cx.obj# (+)

  and cx.owner# = cu.user# (+)

  and ksppi.indx = ksppcv.indx

  and ksppi.ksppinm = '_dml_monitoring_enabled'

 

  --可以看到限制条件:where o.owner# = userenv('SCHEMAID')

 

+++

--USER_ALL_TABLES

create or replace view USER_ALL_TABLES

    (TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,

     PCT_FREE, PCT_USED,

     INI_TRANS, MAX_TRANS,

     INITIAL_EXTENT, NEXT_EXTENT,

     MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,

     FREELISTS, FREELIST_GROUPS, LOGGING,

     BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,

     AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,

     AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,

     DEGREE, INSTANCES, CACHE, TABLE_LOCK,

     SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,

     IOT_TYPE, OBJECT_ID_TYPE,

     TABLE_TYPE_OWNER, TABLE_TYPE, TEMPORARY, SECONDARY, NESTED,

     BUFFER_POOL, ROW_MOVEMENT,

     GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,

     CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED)

as

select TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS, 

     PCT_FREE, PCT_USED,

     INI_TRANS, MAX_TRANS,

     INITIAL_EXTENT, NEXT_EXTENT,

     MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,

     FREELISTS, FREELIST_GROUPS, LOGGING,

     BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,

     AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,

     AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,

     DEGREE, INSTANCES, CACHE, TABLE_LOCK,

     SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,

     IOT_TYPE,

     NULL, NULL, NULL, TEMPORARY, SECONDARY, NESTED,

     BUFFER_POOL, ROW_MOVEMENT,

     GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,

     CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED

from user_tables

union all

select TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,

     PCT_FREE, PCT_USED,

     INI_TRANS, MAX_TRANS,

     INITIAL_EXTENT, NEXT_EXTENT,

     MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,

     FREELISTS, FREELIST_GROUPS, LOGGING,

     BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,

     AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,

     AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,

     DEGREE, INSTANCES, CACHE, TABLE_LOCK,

     SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,

     IOT_TYPE, OBJECT_ID_TYPE,

     TABLE_TYPE_OWNER, TABLE_TYPE, TEMPORARY, SECONDARY, NESTED,

     BUFFER_POOL, ROW_MOVEMENT,

     GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,

     CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED

from user_object_tables

 

  --扩展了关于用户有权限访问的对象信息,所以user_tables是all_tables的子集。

 

+++

--DBA_tables

create or replace view DBA_TABLES

    (OWNER, TABLE_NAME, TABLESPACE_NAME, CLUSTER_NAME, IOT_NAME, STATUS,

     PCT_FREE, PCT_USED,

     INI_TRANS, MAX_TRANS,

     INITIAL_EXTENT, NEXT_EXTENT,

     MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE,

     FREELISTS, FREELIST_GROUPS, LOGGING,

     BACKED_UP, NUM_ROWS, BLOCKS, EMPTY_BLOCKS,

     AVG_SPACE, CHAIN_CNT, AVG_ROW_LEN,

     AVG_SPACE_FREELIST_BLOCKS, NUM_FREELIST_BLOCKS,

     DEGREE, INSTANCES, CACHE, TABLE_LOCK,

     SAMPLE_SIZE, LAST_ANALYZED, PARTITIONED,

     IOT_TYPE, TEMPORARY, SECONDARY, NESTED,

     BUFFER_POOL, ROW_MOVEMENT,

     GLOBAL_STATS, USER_STATS, DURATION, SKIP_CORRUPT, MONITORING,

     CLUSTER_OWNER, DEPENDENCIES, COMPRESSION, DROPPED)

as

select u.name, o.name, decode(bitand(t.property,2151678048), 0, ts.name, null),

       decode(bitand(t.property, 1024), 0, null, co.name),

       decode((bitand(t.property, 512)+bitand(t.flags, 536870912)),

              0, null, co.name),

       decode(bitand(t.trigflag, 1073741824), 1073741824, 'UNUSABLE', 'VALID'),

       decode(bitand(t.property, 32+64), 0, mod(t.pctfree$, 100), 64, 0, null),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

          decode(bitand(t.property, 32+64), 0, t.pctused$, 64, 0, null)),

       decode(bitand(t.property, 32), 0, t.initrans, null),

       decode(bitand(t.property, 32), 0, t.maxtrans, null),

       s.iniexts * ts.blocksize,

       decode(bitand(ts.flags, 3), 1, to_number(NULL),

                                      s.extsize * ts.blocksize),

       s.minexts, s.maxexts,

       decode(bitand(ts.flags, 3), 1, to_number(NULL),

                                      s.extpct),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

         decode(bitand(o.flags, 2), 2, 1, decode(s.lists, 0, 1, s.lists))),

       decode(bitand(ts.flags, 32), 32, to_number(NULL),

         decode(bitand(o.flags, 2), 2, 1, decode(s.groups, 0, 1, s.groups))),

       decode(bitand(t.property, 32+64), 0,

                decode(bitand(t.flags, 32), 0, 'YES', 'NO'), null),

       decode(bitand(t.flags,1), 0, 'Y', 1, 'N', '?'),

       t.rowcnt,

       decode(bitand(t.property, 64), 0, t.blkcnt, null),

       decode(bitand(t.property, 64), 0, t.empcnt, null),

       t.avgspc, t.chncnt, t.avgrln, t.avgspc_flb,

       decode(bitand(t.property, 64), 0, t.flbcnt, null),

       lpad(decode(t.degree, 32767, 'DEFAULT', nvl(t.degree,1)),10),

       lpad(decode(t.instances, 32767, 'DEFAULT', nvl(t.instances,1)),10),

       lpad(decode(bitand(t.flags, 8), 8, 'Y', 'N'),5),

       decode(bitand(t.flags, 6), 0, 'ENABLED', 'DISABLED'),

       t.samplesize, t.analyzetime,

       decode(bitand(t.property, 32), 32, 'YES', 'NO'),

       decode(bitand(t.property, 64), 64, 'IOT',

               decode(bitand(t.property, 512), 512, 'IOT_OVERFLOW',

               decode(bitand(t.flags, 536870912), 536870912, 'IOT_MAPPING', null))),

       decode(bitand(o.flags, 2), 0, 'N', 2, 'Y', 'N'),

       decode(bitand(o.flags, 16), 0, 'N', 16, 'Y', 'N'),

       decode(bitand(t.property, 8192), 8192, 'YES',

              decode(bitand(t.property, 1), 0, 'NO', 'YES')),

       decode(bitand(o.flags, 2), 2, 'DEFAULT',

             decode(s.cachehint, 0, 'DEFAULT', 1, 'KEEP', 2, 'RECYCLE', NULL)),

       decode(bitand(t.flags, 131072), 131072, 'ENABLED', 'DISABLED'),

       decode(bitand(t.flags, 512), 0, 'NO', 'YES'),

       decode(bitand(t.flags, 256), 0, 'NO', 'YES'),

       decode(bitand(o.flags, 2), 0, NULL,

          decode(bitand(t.property, 8388608), 8388608,

                 'SYS$SESSION', 'SYS$TRANSACTION')),

       decode(bitand(t.flags, 1024), 1024, 'ENABLED', 'DISABLED'),

       decode(bitand(o.flags, 2), 2, 'NO',

           decode(bitand(t.property, 2147483648), 2147483648, 'NO',

              decode(ksppcv.ksppstvl, 'TRUE', 'YES', 'NO'))),

       decode(bitand(t.property, 1024), 0, null, cu.name),

       decode(bitand(t.flags, 8388608), 8388608, 'ENABLED', 'DISABLED'),

       decode(bitand(t.property, 32), 32, null,

                decode(bitand(s.spare1, 2048), 2048, 'ENABLED', 'DISABLED')),

       decode(bitand(o.flags, 128), 128, 'YES', 'NO')

from sys.user$ u, sys.ts$ ts, sys.seg$ s, sys.obj$ co, sys.tab$ t, sys.obj$ o,

     sys.obj$ cx, sys.user$ cu, x$ksppcv ksppcv, x$ksppi ksppi

where o.owner# = u.user#

  and o.obj# = t.obj#

  and bitand(t.property, 1) = 0

  and bitand(o.flags, 128) = 0

  and t.bobj# = co.obj# (+)

  and t.ts# = ts.ts#

  and t.file# = s.file# (+)

  and t.block# = s.block# (+)

  and t.ts# = s.ts# (+)

  and t.dataobj# = cx.obj# (+)

  and cx.owner# = cu.user# (+)

  and ksppi.indx = ksppcv.indx

  and ksppi.ksppinm = '_dml_monitoring_enabled'

  --返回数据库中所有表的信息

 

+++

各数据字典表数量比较:可以从V$fixed_table中查询。

(以下为oracle10g单机数据库,定制DB)

 

SQL> select * from v$version;

 

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

PL/SQL Release 10.2.0.1.0 - Production

CORE    10.2.0.1.0      Production

TNS for 32-bit Windows: Version 10.2.0.1.0 - Production

NLSRTL Version 10.2.0.1.0 - Production

 

 

SQL> select count(*) from v$fixed_table where name like 'X$%';

 

  COUNT(*)

----------

       613

 

SQL> select count(*) from v$fixed_table where name like 'GV$%';

 

  COUNT(*)

----------

       372

 

SQL> select count(*) from v$fixed_table where name like 'V$%';

 

  COUNT(*)

----------

       396

 

--这里:X%+GV$+V$=613+372+396=1381

 

SQL> select count(*) from v$fixed_table;

 

  COUNT(*)

----------

      1383

 

--一般情况下,这里会=X%+GV$+V$,但现在不等,我们看一下有什么其他的表:

 

SQL> select substr(name,1,2) from v$fixed_table group by substr(name,1,2);

 

SUBS

----

X$

V$

O$

GO

GV

 

--可以看出,多出两个前缀分别是O$,GO的两类表,应该每种只有一个:

 

SQL> select name from v$fixed_table where name like 'O$%';

 

NAME

------------------------------

O$SQL_BIND_CAPTURE

 

SQL> select name from v$fixed_table where name like 'GO%';

 

NAME

------------------------------

GO$SQL_BIND_CAPTURE

 

SQL>

 

--此外,一般情况下GV$=V$,但现在GV$=396,V$=372个,我们看一下GV$都多出什么表了:

 

SQL> select max(a.name_max) from (select length(name) as name_max from v$fixed_t

able where name like 'GV$%' or name like 'V$%') a;

 

MAX(A.NAME_MAX)

---------------

             30

 

select a.gv_name,b.v_name from

(select substr(name,4,30) GV_name from v$fixed_table where substr(name,1,3)='GV$') a,

(select substr(name,3,30) V_name from v$fixed_table where substr(name,1,2)='V$') b

where a.GV_name=b.V_name(+)

  and b.v_name is null

???

 

+++

表Dictionary与V$fixed_table比较(没有什么用处~~)

---

 

SQL> select count(*) from dictionary;

 

  COUNT(*)

----------

      1870

 

SQL> select count(*) from v$fixed_table;

 

  COUNT(*)

----------

      1383

 

--两表综合比较:

Dic有,Fixed无--1112

Dic无,Fixed有--625

 

dictionary中GV$-368 V$-398

V$fixed_table中GV$-372 V$-396

 

--两表中GV$比较:

Dic有,Fixed

GV$SQL_BIND_CAPTURE

GV$AQ

GV$TEMPSEG_USAGE

 

Dic无,Fixed

GV$_LOCK1

GV$_RESUMABLE2

GV$RMAN_STATUS_CURRENT

GV$_SEQUENCES

GV$DB_TRANSPORTABLE_PLATFORM

GV$RMAN_ENCRYPTION_ALGORITHMS

GV$TRANSPORTABLE_PLATFORM

 

--两表中V$表比较

Dic有,Fixed

V$AQ

V$TEMPSEG_USAGE

V$SQL_BIND_CAPTURE

V$BACKUP_FILES

V$ROLLNAME

 

Dic无,Fixed

V$_LOCK1

V$RMAN_ENCRYPTION_ALGORITHMS

V$_SEQUENCES

 

+++

通过V$parameter视图来追踪一下数据库的架构

1,V$parameter的结构:

SQL> select view_definition from v$fixed_view_definition where view_name='V$PARA

METER';

 

VIEW_DEFINITION

--------------------------------------------------------------------------------

 

select  NUM , NAME , TYPE , VALUE , DISPLAY_VALUE, ISDEFAULT , ISSES_MODIFIABLE

, ISSYS_MODIFIABLE , ISINSTANCE_MODIFIABLE, ISMODIFIED , ISADJUSTED , ISDEPRECAT

 

ED, DESCRIPTION, UPDATE_COMMENT, HASH  from GV$PARAMETER where inst_id = USERENV

 

('Instance')

 

--可以看出V$parameter是由GV$parameter创建的

 

SQL> select view_definition from v$fixed_view_definition where view_name='GV$PAR

AMETER';

 

VIEW_DEFINITION

--------------------------------------------------------------------------------

 

select x.inst_id,x.indx+1,ksppinm,ksppity,ksppstvl, ksppstdvl, ksppstdf,  decode

 

(bitand(ksppiflg/256,1),1,'TRUE','FALSE'),  decode(bitand(ksppiflg/65536,3),1,'I

 

MMEDIATE',2,'DEFERRED',                                  3,'IMMEDIATE','FALSE'),

 

  decode(bitand(ksppiflg,4),4,'FALSE',                                     decod

 

e(bitand(ksppiflg/65536,3), 0, 'FALSE', 'TRUE')),     decode(bitand(ksppstvf,7),

 

1,'MODIFIED',4,'SYSTEM_MOD','FALSE'),  decode(bitand(ksppstvf,2),2,'TRUE','FALSE

 

'),  decode(bitand(ksppilrmflg/64, 1), 1, 'TRUE', 'FALSE'),  ksppdesc, ksppstcmn

 

t, ksppihash  from x$ksppi x, x$ksppcv y where (x.indx = y.indx) and  ((translat

 

e(ksppinm,'_','#') not like '##%') and    ((translate(ksppinm,'_','#') not like

'#%')      or (ksppstdf = 'FALSE') or      (bitand(ksppstvf,5) > 0)))

 

--可以看出GV$parameter是由x$ksppi和x$ksppcv两个x$创建的

--x$ksppi和x$ksppcv基本上包含所有数据库参数,GV$parameter展现的是不包含“_”开头的参数

--“_”开头的参数为隐含参数,不建议修改,也少有人知,但很多隐含参数因为功能强大而经常使用,并不段的被探索和研究。

 

+++

oracle如何通过同义词定位对象(10046事件)

 

如果愿意的话,我们可以进一步来进行追溯,使用 10046事件,我们可以看到更多的东西。 

 

通过 10046事件跟踪查询: 

[oracle@jumper udump]$ sqlplus eygle/eygle 

 

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Jun 13 18:29:22 2005 

 

Copyright (c) 1982, 2002, Oracle Corporation.    All rights reserved. 

 

 

Connected to: 

Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production 

With the Partitioning option 

JServer Release 9.2.0.4.0 - Production 

 

SQL> alter session set events '10046 trace name context forever,level 12'; 

 

Session altered. 

 

SQL> select count(*) from v$parameter;

 

  COUNT(*) 

---------- 

       262 

 

SQL> exit 

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production 

With the Partitioning option 

JServer Release 9.2.0.4.0 - Production 

 

--查看生成的跟踪文件

 

10046 事件的使用请参考: 

http://www.eygle.com/case/Use.sql_trace.to.Diagnose.database.htm

 

Ok,在这里我们不要使用 tkprof格式化,因为 tkprof可能会隐去重要信息(本文仅摘取几段重要跟踪信息,你完全可以通过实验获得相同的输出): 

 

第一段重要代码是: 

PARSING IN CURSOR #2 len=198 dep=1 uid=0 oct=3 lid=0 tim=1092440257023120 hv=2703824309 ad='567681f0' 

select obj#,type#,ctime,mtime,stime,status,dataobj#,flags,oid$, spare1, spare2 from obj$ where owner#=:1 and name=:2 and 

namespace=:3 and remoteowner is null and linkname is null and subname is null 

END OF STMT 

PARSE #2:c=0,e=1601,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257023088 

BINDS #2: 

  bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 

   bfp=b701cf24 bln=22 avl=02 flg=05 

   value=25 

  bind 1: dty=1 mxl=32(11) mal=00 scl=00 pre=00 oacflg=18 oacfl2=1 size=32 offset=0 

   bfp=b701c7b4 bln=32 avl=11 flg=05 

   value="V$PARAMETER" 

  bind 2: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 

   bfp=b701c790 bln=24 avl=02 flg=05 

   value=1 

 

Oracle 根据三个传入参数 owner#=25,name=V$PARAMETER,namespace=1,来判断对象类型,按照表、视图优

先规则来定位判断,对于本例这个查询是不会有结果的。 

 

接下来 Oracle 继续判断,那么此时需要验证同一词了: 

 

PARSING IN CURSOR #4 len=46 dep=1 uid=0 oct=3 lid=0 tim=1092440257028409 hv=3378994511 ad='576eb040' 

select node,owner,name from syn$ where obj#=:1 

END OF STMT 

PARSE #4:c=0,e=1278,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257028379                                                           

BINDS #4: 

  bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0 

   bfp=b701b3cc bln=22 avl=03 flg=05 

   value=841 

 

传入绑定变量值是 841,我们看看 841 是什么: 

SQL> select object_name,object_id,object_type from dba_objects where object_id=841; 

 

OBJECT_NAME                     OBJECT_ID OBJECT_TYPE 

------------------------------                 ----------   ------------------ 

V$PARAMETER                           841 SYNONYM 

 

841 正是这个同义词,我们再继续看这个递归 SQL 的作用: 

 

SQL> select node,owner,name from syn$ where obj#=841; 

 

NODE     OWNER                          NAME 

-------- ------------------------------ ------------------------------ 

         SYS                            V_$PARAMETER 

 

 

原来这个 SQL 获得的是同义词的底层对象,这里得到了 V_$PARAMETER。 

 

我们继续向下看: 

PARSING IN CURSOR #8 len=37 dep=1 uid=0 oct=3 lid=0 tim=1092440257074273 hv=3468666020 ad='576db210' 

select text from view$ where rowid=:1 

END OF STMT 

PARSE #8:c=0,e=1214,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1092440257074242 

BINDS #8: 

  bind 0: dty=11 mxl=16(16) mal=00 scl=00 pre=00 oacflg=18 oacfl2=1 size=16 offset=0 

   bfp=b7018770 bln=16 avl=16 flg=05 

   value=000001CD.0013.0001 

EXEC #8:c=0,e=972,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1092440257075602 

 

 

注意这里,Oracle 执行查询访问 view$视图,获得视图定义文本,我们看一下这里访问的是什么对象,绑定变

量传入的 rowid 值为000001CD.0013.0001,注意这是个受限 rowid,查询时需要转换一下处理: 

 

SQL> select obj# from view$ where dbms_rowid.rowid_to_restricted(rowid,0) = '000001CD.0013.0001'; 

 

      OBJ# 

----------

       840 

 

 

SQL> select object_name,object_type from dba_objects where object_id=840; 

 

OBJECT_NAME                    OBJECT_TYPE 

------------------------------ ------------------ 

V_$PARAMETER                   VIEW 

 

 

这里 Oracle访问的正是 V_$PARAMETER 视图的定义方式。执行查询可以得到: 

 

select text from view$ where obj#=840; 

 

TEXT 

-------------------------------------------------------------------------------- 

select 

"NUM","NAME","TYPE","VALUE","ISDEFAULT","ISSES_MODIFIABLE","ISSYS_MODIFIABLE","ISMODIFIED","ISADJUSTE

D","DESCRIPTION","UPDATE_COMMENT" from v$parameter 

 

 

至此就完成了查询中的回溯及定位,当然,实际过程中 Oracle 后台的递归操作比这还要复杂的多,感兴趣的

朋友可以按照文中的方法测试研究一下,文中不再赘述。 

 

--sql语句中oracle对于对象名的解析顺序:

--用户表/视图-->私有同义词-->公共同义词-->返回错误ora-00942

 

参考一:盖国强<深入Oracle--DBA入门、进阶与诊断案例>之<第三章 数据字典>

参考二:张云河老师课堂笔记。

 

转帖请注明:

本文源自TTT BLOG,原文地址:http://blog.chinaunix.net/u3/107265/showart_2192657.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1073页啊,够爽吧: Introduction 15 New in This Release 15 Introduction to Toad 23 DB Admin Module 24 Toad and Oracle Enterprise Manager 29 Quick Search Bar 30 Additional Resources 31 Working with other Quest Products 32 Knowledge Xpert 32 Using SQL Optimizer with Toad 32 Benchmark Factory 33 Quest Code Tester Integration 35 Toad Basics 37 Toad Tips 37 Errors 37 RAC Support 37 Task Bar & Status Bar 38 Toolbars, Menus and Shortcut Keys 40 Installation and Administration of Toad 64 Window Privileges and Toad 64 Toad for Oracle, Read-Only 64 Registering Toad 65 Silent Installation 66 Group Policy Management 71 Citrix Support 71 SQL*Net Versions 72 Configuration Files 73 Server Side Objects Installation 93 Connecting to Oracle 97 Server Login Window 97 Create New Connection 99 Selecting Connection Color 101 SET ROLE 101 Auto Connect 103 Save Passwords for Connections 104 Select and View Favorite Connections 104 Organize your login display 105 Use Existing Connection 106 SQLNET Editor 106 LDAP Editor 107 Oracle Homes 108 TNSNames Editor 111 Tutorials 119 CodeXpert 119 PL/SQL Debugger 121 SQL*Loader 140 Team Coding 158 RMAN Templates 164 RMAN Scripts in Toad 164 Working with RMAN Templates 164 Executing RMAN Scripts from Toad 165 Comparing 166 Data Duplicates 166 Compare Single Objects 166 Comparing Databases 167 Comparing Data 174 Compare Files (Difference Viewer) 176 Comparing Schemas 180 Controlling Sessions 188 Select Session 188 End Connections 188 Test Connections 188 Configure User Lists 188 Session Information 189 Change Password 190 Commit & Rollback 190 Connect and Disconnect 191 DBMS_Flashback 191 Diagnosing Problems 193 View Extents 193 Identify Space Deficits 193 Log Switch Frequency Map 194 Tablespace Map 194 TKProf Interface Wizard 196 Undo Advisor 198 Segment Advisor 200 LogMiner Interface 203 Health Check 207 Trace File Browser 226 CodeXpert 231 Database Administration 259 Audit SQL/Sys Privs 259 NLS Parameters 260 Toad Features Security 260 ASM Manager 263 Audit Objects 269 Multiple Object Privileges 270 Oracle Parameters 272 Tablespaces 274 Redo Log Manager 282 Importing and Exporting Data 285 Data Pump 285 Export Dataset 304 Export DDL 310 Export File Browser 318 General Export 324 General Import 329 Generate Database Script 341 Generate Schema Script 342 Managing Projects 346 Using Automation Designer to Control Toad 346 Project Manager 387 Query Viewer 416 SQL Command Recall 418 Script Manager 419 Monitoring 431 Toad Server Statistics 431 SQL Monitor 432 Toad UNIX Monitor 432 ADDM/AWR 434 Database Browser 446 Database Monitor 449 Database Probe 453 Index Monitoring 458 Instance Manager 460 Session Browser 466 SGA Trace/Optimization 483 StatsPack Browser 486 Top Session Finder 495 Optimizing (Tuning) 499 DBMS_REDEFINITION Wizard 499 Estimate Index Size 500 Estimate Table Size 501 Explain Plan 503 Pinned Code 504 Repair Chained Rows 505 Rebuild Table 506 Unix Kernel Parms 507 Windows Registry Parms 508 Analyze All Objects 509 Profilers 512 Oracle Tuning 523 Rebuild Multiple Objects 525 Options 535 Formatting Options 535 Toad Options 536 Language Management 603 Printing 620 Printing 620 Print Grid 620 Report Link Designer 620 Reporting 623 Toad Control Files 623 Dependencies 624 ER Diagrams 624 Explain Plans 631 Code Road Map 636 HTML Schema Doc Generator 641 Master/Detail Browser 643 Reports Manager 648 Reporting from Data Grids 655 Spool SQL 659 Spool SQL 659 Utilities 660 Archive 660 Wrap Code 660 Service Manager 661 External tools 662 FTP 665 Java Manager 668 Network Utilities 672 Task Scheduler 676 Unix Job Scheduler 678 Source Control and Team Coding 693 Support for Version Control Products 693 Third Party File Based Source Control 694 Team Coding 697 Status in the Editor Status Bar or Team Coding Viewer Status Column 707 Detailed File Properties 708 Checking Objects and Scripts in and out 709 Using Automatic Check-in and Automatic Check-out 709 Manually check-in or check-out 709 Entering Comments on Check in or out 710 Check In All 711 Undo Checkout 712 Freezing an Object 713 TC Locks not selected 726 TC Locks selected 726 Working from the Command Line 738 Command Line Syntax 738 Converting Old Settings Files to Actions 743 Command Line Passwords 744 Export Tables, Views, SQL Queries from the Command Line 744 Run Analyze Objects from the Command Line 745 Run CodeXpert from the Command Line 750 Running Actions from the Command Line 751 Run Compare Databases from Command Prompt 754 Run Compare Schemas from a Command Prompt 757 Run Copy to another Schema from Command Prompt 757 Run Generate Database Script from a Command Prompt 758 Run Generate Schema Script from Command Line 760 Run Rebuild Objects from the Command Prompt 762 Run Reports Manager from the Command Line 766 Using Variables 768 Using Variables 768 Working with Code 769 Editor 769 Debugging 819 Query Builder 851 Working with Data 861 Column Names Supported 861 Graph Properties 861 OPS$ Accounts 861 Viewing or Hiding Docked Windows 862 Viewing Source Surrounding a PL/SQL Error 863 Dataset Operations 864 Data Grids 866 DBMS Output 881 Finding Data 883 Generate Test Data 890 Working with Database Objects 896 Schema Browser Overview 896 Auto-Refreshing the Datagrid 897 Icon Legend 898 Privileges 898 Schema Browser Toolbars 899 Statement Processing 900 Create Objects in Another Schema 900 Personalizing the Schema Browser 900 General Schema Browser Actions 903 Browser Filters 907 Clusters 912 Constraints 914 Contexts 917 DB Links 918 Dimensions 920 Directories 921 Favorites 923 Flashback Archives 924 Functions 926 Indexes 928 Invalid Objects 929 Java 931 Jobs 933 Libraries 936 Materialized Views (Snapshots) 938 Materialized View (Snapshot) Logs 940 Oracle Scheduler 941 Packages 953 Policies 955 Policy Groups 956 Procedures 957 Profiles 959 Queue Tables 960 Queues 964 Recycle Bin 966 Refresh Groups 968 Resource Consumer Groups 970 Resource Plans 972 Roles 974 Rollback Segments 975 Sequences 977 Synonyms 978 System Privileges 980 Tables 981 Tablespaces 996 Triggers 1002 Types 1004 Users 1010 Views 1012 Troubleshooting 1017 Unicode Troubleshooting 1017 Hints and Tips: Connecting To Personal Oracle 1018 Hints and Tips: Table Does Not Exist Errors 1019 Create Support Bundles 1019 Toad Advisor 1019 Contact Quest 1021 Contact Quest Support 1021 Contact Quest Software 1021 About Quest Software, Inc 1021 Appendix: Contact Quest 1022 Contact Quest Support 1022 Contact Quest Software 1022 About Quest Software, Inc 1022 Index 1023

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值