你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle Namespace 说明

[日期:2011-07-28] 来源:Linux社区  作者:tianlesoftware [字体:大 中 小]

二. 深入研究Namespace

            先执行如下SQL,查看每个namespace 对应名称和它所包含的对象的个数:

/* Formatted on 2011/7/21 14:24:47(QP5 v5.163.1008.3004) */

  SELECTnamespace,object_type, COUNT (*)

    FROM (SELECTnamespace,

                 DECODE (o.type#,

                        0, 'NEXTOBJECT',

                        1, 'INDEX',

                        2, 'TABLE',

                         3, 'CLUSTER',

                        4, 'VIEW',

                        5, 'SYNONYM',

                        6, 'SEQUENCE',

                        7, 'PROCEDURE',

                        8, 'FUNCTION',

                        9, 'PACKAGE',

                        11, 'PACKAGEBODY',

                        12, 'TRIGGER',

                        13, 'TYPE',

                        14, 'TYPEBODY',

                        19, 'TABLEPARTITION',

                        20, 'INDEX PARTITION',

                        21, 'LOB',

                        22, 'LIBRARY',

                        23, 'DIRECTORY',

                        24, 'QUEUE',

                        28, 'JAVASOURCE',

                        29, 'JAVACLASS',

                         30, 'JAVARESOURCE',

                        32, 'INDEXTYPE',

                        33, 'OPERATOR',

                        34, 'TABLESUBPARTITION',

                        35, 'INDEXSUBPARTITION',

                        40, 'LOBPARTITION',

                        41, 'LOBSUBPARTITION',

                        42, 'MATERIALIZEDVIEW',

                        43, 'DIMENSION',

                        44, 'CONTEXT',

                        46, 'RULESET',

                         47, 'RESOURCEPLAN',

                        48, 'CONSUMERGROUP',

                        51, 'SUBSCRIPTION',

                        52, 'LOCATION',

                        55, 'XMLSCHEMA',

                        56, 'JAVADATA',

                         57, 'SECURITYPROFILE',

                        59, 'RULE',

                        62, 'EVALUATIONCONTEXT',

                        'UNDEFINED')

                   object_type

            FROM sys.obj$ o)

GROUP BYnamespace,object_type;

NAMESPACE OBJECT_TYPE          COUNT(*)

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

        4 INDEX                    2253

        2 TYPE BODY                 175

       51 UNDEFINED                   6

       21 CONTEXT                     5

         9 DIRECTORY                   6

        1 SYNONYM                 20122

        1 PACKAGE                   859

        1 VIEW                     3684

        1 PROCEDURE                  98

        3 TRIGGER                   164

       38 EVALUATION CONTEXT         12

        1 SEQUENCE                  138

        2 PACKAGE BODY              804

        1 INDEXTYPE                  10

        1 TYPE                     1953

       24 RESOURCE PLAN               3

        4 INDEX PARTITION           144

       25 XML SCHEMA                 25

        1 TABLE                    1619

        8 LOB                       541

       10 QUEUE                      23

       23 RULE SET                   15

        8 LOB PARTITION               1

       36 RULE                        4

        1 JAVA CLASS              16450

        1 NEXT OBJECT                 1

        1 FUNCTION                  268

        1 UNDEFINED                 660

        1 LIBRARY                   154

        32 JAVA DATA                 298

        5 CLUSTER                    10

       24 CONSUMER GROUP              5

        1 TABLE PARTITION           124

        1 OPERATOR                   57

       14 JAVA RESOURCE             775

35 rows selected.

 

            通过这个查询结果,我们可以看到一些对象使用相同的namespace。 第一列的数字代表的就是namespace。 关于type#的定义,在Oracle的obj$基表创建的定义SQL 有明确的说明。

 

            先在$ORACLE_HOME/RDBMS/admin/bin 下查找sql.bsq脚本。sql.bsq主要记录了ORACLE中的系统字典表的定义,比如过tab$,col$,obj$ 等,通过查询这个文件可以知道数据字典表的定义. 在sql.bsq里面保存了相关的脚本信息,其中就有dcore.bsq 脚本,在该脚本里就可以找到obj$ 表的定义SQL:

 

/* Formatted on 2011/7/21 14:42:51(QP5 v5.163.1008.3004) */

CREATE TABLE obj$                                           /*object table */

(

   obj#       NUMBER NOT NULL,                             /*object number */

   dataobj#   NUMBER,                           /*data layer object number */

   owner#     NUMBER NOT NULL,                         /*owner user number */

   name       VARCHAR2 ("M_IDEN") not null,                  /* object name */

namespace    number not null,         /* namespace of object (see KQD.H):*/

/* 1 = TABLE/PROCEDURE/TYPE, 2 =BODY, 3 = TRIGGER, 4 = INDEX, 5 = CLUSTER, */

                                                 /* 8 =LOB, 9 = DIRECTORY, */

  /* 10 = QUEUE, 11 = REPLICATIONOBJECT GROUP, 12 = REPLICATION PROPAGATOR, */

                                     /* 13 = JAVA SOURCE, 14 = JAVARESOURCE */

                                                /* 58= (Data Mining) MODEL */

  subname       varchar2("M_IDEN"),               /* subordinate tothe name */

  type#         number not null,                 /* object type(see KQD.H): */

  /* 1 =INDEX, 2 = TABLE, 3 = CLUSTER, 4 = VIEW, 5 = SYNONYM, 6 = SEQUENCE, */

             /* 7 =PROCEDURE, 8 = FUNCTION, 9 = PACKAGE, 10 = NON-EXISTENT, */

              /* 11= PACKAGE BODY, 12 = TRIGGER, 13 = TYPE, 14 = TYPE BODY, */

      /* 19= TABLE PARTITION, 20 = INDEX PARTITION, 21 = LOB, 22 = LIBRARY, */

                                             /* 23= DIRECTORY , 24 = QUEUE, */

    /* 25= IOT, 26 = REPLICATION OBJECT GROUP, 27 = REPLICATION PROPAGATOR, */

    /* 28= JAVA SOURCE, 29 = JAVA CLASS, 30 = JAVA RESOURCE, 31 = JAVA JAR, */

                 /* 32= INDEXTYPE, 33 = OPERATOR , 34 = TABLE SUBPARTITION, */

                                                 /* 35= INDEX SUBPARTITION */

                                                /* 82= (Data Mining) MODEL */

                                /* 92= OLAP CUBE DIMENSION,  93 = OLAP CUBE */

                   /* 94= OLAP MEASURE FOLDER, 95 = OLAP CUBE BUILD PROCESS */

  ctime         date not null,                       /*object creation time */

  mtime         date not null,                      /* DDLmodification time */

  stime         date not null,          /* specificationtimestamp (version) */

  status        number not null,            /* status ofobject (see KQD.H): */

                                     /* 1 =VALID/AUTHORIZED WITHOUT ERRORS, */

                         /* 2 =VALID/AUTHORIZED WITH AUTHORIZATION ERRORS, */

                            /* 3 =VALID/AUTHORIZED WITH COMPILATION ERRORS, */

                        /* 4 =VALID/UNAUTHORIZED, 5 = INVALID/UNAUTHORIZED */

  remoteowner   varchar2("M_IDEN"),     /* remote ownername (remote object) */

  linkname      varchar2("M_XDBI"),             /* link name(remote object) */

  flags         number,               /* 0x01 = extentmap checking required */

                                      /*0x02 = temporary object             */

                                     /*0x04 = system generated object      */

                                      /*0x08 = unbound (invoker's rights)   */

                                      /*0x10 = secondary object             */

                                      /*0x20 = in-memory temp table         */

                                      /*0x80 = dropped table (RecycleBin)   */

                                      /*0x100 = synonym VPD policies        */

                                      /*0x200 = synonym VPD groups          */

                                      /*0x400 = synonym VPD context         */

                                      /*0x4000 = nested table partition     */

  oid$          raw(16),        /* OID for typedtable, typed view, and type */

  spare1        number,                      /* sqlversion flag: see kpul.h */

  spare2        number,                             /*object version number */

  spare3        number,                                        /*base user# */

  spare4        varchar2(1000),

  spare5        varchar2(1000),

  spare6        date

)

  storage (initial 10k next 100k maxextents unlimited pctincrease 0)

 

            在obj$ 这个字典里面,保存的是namespace的ID。 他们之间的对应关系在obj$里有说明。

   namespace     number not null,         /* namespace ofobject (see KQD.H): */

1 = TABLE/PROCEDURE/TYPE,

2 = BODY,

3 = TRIGGER,

4 = INDEX,

5 = CLUSTER,

8 = LOB,

9 = DIRECTORY,

10 = QUEUE,

11 = REPLICATION OBJECT GROUP,

12 = REPLICATION PROPAGATOR,

13 = JAVA SOURCE,

14 = JAVA RESOURCE

58 = (Data Mining) MODEL

 

查看obj$中共有多少个不同的namespace:

SYS@anqing2(rac2)> select distinctnamespace from obj$ order by namespace;

  NAMESPACE

----------

        1

        2

        3

        4

        5

        8

        9

       10

       14

       21

       23

       24

       25

       32

       36

       38

       51

17 rows selected.

 

SYS@anqing2(rac2)> select distinct namespace from v$librarycache;

NAMESPACE

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

BODY

JAVA DATA

SQL AREA

OBJECT

PIPE

JAVA RESOURCE

TABLE/PROCEDURE

TRIGGER

INDEX

JAVA SOURCE

CLUSTER

11 rows selected.

 

注意:

            在这里有一个问题,我们通过distinct obj$ 和distinct v$librarycache 查看的值不对应,而且这个值与我们obj$的注释也不一致。 这个问题是关键,因为它可以引出到底Namespace 是什么。

 

看一下DSI405里对library cache object所属于的namespace的定义:

            1.Library cache objects are grouped in namespaces according to their type.

            2.Each object can only be of one type.

            3.All the objects of the same type are in the same namespace.

            4.A namespace may be used by more than one type.

            5. The most important namespace is called cursor (CRSR)and houses the shared SQL cursors.

 

            通过这段解释,我们可以看出,我们之前通过obj$ 看到的namespace 是不全的,因为像shared cursor这样的library cache object根本就不在obj$里。

 

可以这样来理解Namespace:

            Namespace是针对缓存在library cache里的library cache object来说的。

            我们之前在obj$里也有namespace的定义,是因为library cache object有一部分的来源就是来自于数据库里已经存在的、固化的object的metadata。

 

在DSI405中关于library cache object所属于的namespace的详细说明:

            Currentlythere are 64 different object types but this number may grow at any time withthe introduction of new features. Examples of types are: cursor, table,synonym, sequence, index, LOB, Java source, outline, dimension, and so on. Not every type corresponds to a namespace. Actually, thereare only 32 namespaces which, of course, are also subject to increase at anytime.

            Youcan see the list of namespaces in the library cache dump.

            Whatis a certainty is that all the objects of the same type will always be storedin the same namespace. An object can only be of one type, hence the search foran object in the library cache is reduced to a search for this object in thecorresponding namespace.

            Somenamespaces contain objects of two or three different types.

 

These are some of themost commonly used namespaces:

            CRSR: Stores library objects of type cursor (sharedSQL statements)

           TABL/PRCD/TYPE: Stores tables, views, sequences,synonyms, procedure specifications, function specifications, packagespecifications, libraries, and type specifications

            BODY/TYBD: Stores procedure, function, package, and typebodies

            TRGR: Stores library objects of type trigger

            INDX: Stores library objects of type index

            CLST: Stores library objects of type cluster

 

            The exact number and name of namespaces in use depends on theserver features that are used by the application. For example, if theapplication uses Java, namespaces like JVSC (Java source) and JVRE (Javaresource) may be used, otherwise they will not be used.

            Note: These namespaces do not store tables, clusters, orindexes as such, only the metadata is stored.

 

            在obj$的注释里提到了KQD.H文件,这个是Oracle 的源代码,我们看不到它的内容,虽然这里面有我们所有namespace 和其对应的namespace id。 不过我们可以dump library cache,来查看该版本下所有namespace 的名称。 版本不同,namespace 也可能不同。

 

--查看Oracle 版本

SYS@anqing2(rac2)> select * fromv$version where rownum=1;

BANNER

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

Oracle Database 10gEnterprise Edition Release 10.2.0.4.0 - Prod

 

SYS@anqing2(rac2)> oradebug setmypid

Statement processed.

--把librarycache dump 出来

SYS@anqing2(rac2)> alter session set events 'immediate trace name library_cachelevel 1';

Session altered.

--获取tracefile 名称和路径

SYS@anqing2(rac2)> oradebug tracefile_name

/u01/app/oracle/admin/anqing/udump/anqing2_ora_18783.trc

 

[oracle@rac2 ~]$ cat/u01/app/oracle/admin/anqing/udump/anqing2_ora_18783.trc

/u01/app/oracle/admin/anqing/udump/anqing2_ora_18783.trc

Oracle Database 10g Enterprise EditionRelease 10.2.0.4.0 - Production

With the Partitioning, Real ApplicationClusters, OLAP, Data Mining

and Real Application Testing options

ORACLE_HOME =/u01/app/oracle/product/10.2.0/db_1

System name:    Linux

Node name:      rac2

Release:        2.6.18-194.el5

Version:        #1 SMP Tue Mar 16 21:52:43 EDT 2010

Machine:        i686

Instance name: anqing2

Redo thread mounted by this instance: 2

Oracle process number: 23

Unix process pid: 18783, image: oracle@rac2(TNS V1-V3)

*** 2011-07-21 19:23:32.578

*** ACTION NAME:() 2011-07-21 19:23:32.574

*** MODULE NAME:(sqlplus@rac2 (TNS V1-V3))2011-07-21 19:23:32.574

*** SERVICE NAME:(SYS$USERS) 2011-07-2119:23:32.574

*** SESSION ID:(128.4091) 2011-07-2119:23:32.574

LIBRARY CACHE STATISTICS:

namespace           gets hit ratio      pins hit ratio    reloads  invalids

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

CRSR        164017     0.978   4693745    0.999      373    123

TABL          62538     0.966  1408421     0.868   182957     0

BODY           1575     0.970     1937     0.967        8     0

TRGR            231     0.818      284     0.852        0     0

INDX             60     0.183      107     0.430        4     0

CLST            281     0.954      720     0.982        0     0

KGLT              0     0.000         0    0.000        0      0

PIPE              0     0.000         0    0.000        0      0

LOB               0     0.000         0    0.000        0      0

DIR               2     0.500         4    0.500        0      0

QUEU              3     0.000        13    0.462        1      0

OBJG              0     0.000         0    0.000        0     0

PROP              0     0.000         0    0.000        0      0

JVSC              0     0.000         0    0.000        0      0

JVRE              0     0.000         0    0.000        0      0

ROBJ              0     0.000        0     0.000        0     0

REIP              0     0.000         0    0.000        0      0

CPOB              0     0.000         0    0.000        0      0

EVNT          15773     1.000    15915     0.999        1     0

SUMM              0     0.000         0    0.000        0      0

DIMN              0     0.000         0    0.000        0      0

CTX               0     0.000         0    0.000        0      0

OUTL              0     0.000         0    0.000        0      0

RULS              1     0.000         3    0.667        0      0

RMGR          32159     1.000    39619     1.000        1     0

XDBS              7     0.286         7    0.000        0      0

PPLN              0     0.000         0    0.000        0      0

PCLS             0     0.000         0    0.000        0      0

SUBS              2     0.500         2    0.500        0      0

LOCS              0     0.000         0    0.000        0      0

RMOB              0     0.000         0    0.000        0      0

RSMD              0     0.000         0    0.000        0      0

JVSD              0     0.000         0    0.000        0      0

STFG              0     0.000         0    0.000        0      0

TRANS             0     0.000         0    0.000        0      0

RELC              0     0.000         0    0.000        0      0

RULE              0     0.000         0    0.000        0      0

STRM              0     0.000         0    0.000        0      0

REVC              1     0.000         0    0.000        0      0

STAP              0     0.000         0    0.000        0      0

RELS              0     0.000         0    0.000        0      0

RELD              0     0.000         0    0.000        0      0

IFSD              0     0.000         0    0.000        0     0

XDBC              1     0.000         1    0.000        0      0

USAG              0     0.000         0    0.000        0      0

MVOBTBL           1    0.000         1     0.000        0     0

JSQI              0     0.000        0     0.000        0     0

CDC               0     0.000         0    0.000        0      0

MVOBIND           1    0.000         1     0.000        0     0

STBO              0     0.000         0    0.000        0      0

HTSO              0     0.000         0    0.000        0      0

JSGA           9805     0.999  3152085     0.942   181763     0

JSET              7     0.000         7    0.000        0      0

TABL_T           20     0.400        20    0.000        8      0

CLST_T            0     0.000         0    0.000        0      0

INDX_T            2     0.000         2    0.000        0      0

NSCPD             0     0.000         0    0.000        0      0

JSLV              4     0.750         4    0.750        0      0

MODL              0     0.000         0    0.000        0      0

CUMULATIVE  286491     0.979   9312898    0.960   365116    123

第一列就是Oracle 10.2.0.4.0 版本下所有Namespace 的个数:共60个。 这个远比我们通过obj$ 查询出来的多。

linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款