签到成功

知道了

CNDBA社区CNDBA社区

Oracle 动态性能视图

2016-11-25 15:59 1380 0 原创 Oracle 11g
作者: dave

 

Oracle 联机文档上有关动态性能视图的内容:

http://www.cndba.cn/Dave/article/1449

                Data Dictionary and Dynamic Performance Views

                http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/datadict.htm#i4370

 

Throughout its operation, Oracle Database maintains a set of virtual tables that record current database activity. These views are called dynamic performance views because they are continuously updated while a database is open and in use. The views, also sometimes called V$ views, contain information such as the following:

·         System and session parameters

·         Memory usage and allocation

·         File states (including RMAN backup files)

·         Progress of jobs and tasks

·         SQL execution

·         Statistics and metrics

The dynamic performance views have the following primary uses:

·         Oracle Enterprise Manager uses the views to obtain information about the database (see "Oracle Enterprise Manager").

·         Administrators can use the views for performance monitoring and debugging.

See Also:

Oracle Database Reference for a complete list of the dynamic performance views

Contents of the Dynamic Performance Views

Dynamic performance views are sometimes called fixed views because they cannot be altered or removed by a database administrator. However, database administrators can query and create views on the tables and grant access to these views to other users.

SYS owns the dynamic performance tables, whose names begin with V_$. Views are created on these tables, and then public synonyms prefixed with V$. For example, the V$DATAFILE view contains information about data files. The V$FIXED_TABLE view contains information about all of the dynamic performance tables and views.

For almost every V$ view, a corresponding GV$ view exists. In Oracle Real Application Clusters (Oracle RAC), querying a GV$ view retrieves the V$ view information from all qualified database instances (see "Database Server Grid").

When you use the Database Configuration Assistant (DBCA) to create a database, Oracle automatically creates the data dictionary. Oracle Database automatically runs the catalog.sql script, which contains definitions of the views and public synonyms for the dynamic performance views. You must run catalog.sql to create these views and synonyms.

Storage of the Dynamic Performance Views

Dynamic performance views are based on virtual tables built from database memory structures. Thus, they are not conventional tables stored in the database. Read consistency is not guaranteed for the views because the data is updated dynamically.

Because the dynamic performance views are not true tables, the data is dependent on the state of the database and instance. For example, you can query V$INSTANCE and V$BGPROCESS when the database is started but not mounted. However, you cannot query V$DATAFILE until the database has been mounted.

 

. 动态性能视图

 

1.1 动态性能图

动态性能视图属于数据字典,系统管理员用户 SYS 可以访问它们。 关于这部分的内容,参考我的Blog

                Oracle 数据字典

                http://blog.csdn.net/tianlesoftware/archive/2010/09/04/5862508.aspx

 

动态性能视图在数据库打开和使用时不断进行更新,而且它们的内容主要与性能有关。虽然这些视图很像普通的数据库表,但它们不允许用户直接进行修改。这些视图提供内部磁盘结构和内存结构方面的数据。用户可以对这些视图进行查询,以便对系统进行管理与优化。

 

CATALOG.SQL 文件包含这些视图的定义以及公用同义词,必须运行CATALOG.SQL 创建这些视图及同义词。升级系统也后要执行这个脚本.

 

当数据库管理员启动某个例程时,数据库会自动建立动态性能视图;

停止某个例程时,数据库又会自动删除这些动态性能视图

 

 数据字典的信息是从数据文件中取得; 而动态性能视图的信息则是从SGA内存以及控制文件中取得。所以,两者所反映的信息还是有很大差异的。数据库管理员利用这些动态性能视图,可以了解数据库运行的一些基本信息,为我们进行数据库维护以及数据库性能优化提供一些数据上的支持。

 

一般情况下,我们可以通过动态性能数据掌握两类重要的数据库运行信息http://www.cndba.cn/Dave/article/1449

1)了解数据库运行相关的性能数据,如内存的使用量、磁盘排序发生的机率等等。

2)取得与磁盘和内存结构相关的其他信息。http://www.cndba.cn/Dave/article/1449

 

在通常情况下,数据库不同的状态其动态性能视图还是有比较大的差异

 

1)数据库处于“NOMOUNT”状态。数据库启动例程时,Oracle数据库会打开参数文件,分配SGA内存并启动后台进程。此时,其实数据库还没有挂栽。此时,动态性呢视图收集的信息来源只有是SGA,而不会从控制文件中收集相关的信息。所以,动态性能视图的数量要少得多。

2)当数据库处于MOUNT状态时,数据库会根据初始化参数打开所有的控制文件。所以,当例程处于Mount状态时,动态性能视图其收集到的信息就要第一个状态多的多。因为此时,动态性能视图还会去收集控制文件的相关信息。不过,此时动态性能视图所收集到的资料还不是最全的。

3)当用户打开数据库时,Oracle系统会根据控制文件所记载的信息去打开所有的数据库文件以及重做日志。此时,数据库管理员除了可以从 SGA和控制文件中获取信息的动态性能视图外,还可能访问与Oracle数据库性能相关的动态性能视图,如会话等待时间等视图。另外需要注意一点,就是只有在这个状态时,我们才能够访问数据库的数据字典视图。

SYS owns the dynamic performance tables, whose names begin with V_$. Views are created on these tables, and then public synonyms prefixed with V$. For example, the V$DATAFILE view contains information about data files. The V$FIXED_TABLE view contains information about all of the dynamic performance tables and views.

 

从这段描述里,我们可以理解,通过V$FIXED_TBLE 视图可以查看几乎所有的动态性能表和视图。 V$V_$的同义词。

 

1.2  V$, V_$, GV$,  X$ 视图说明

 

1.2.1  X$

X$表包含了特定实例的各方面的信息,是Oracle数据库的运行基础,如当前的配置信息,连接到实例的会话,以及丰富而有价值的性能信息。 X$表并不是驻留在数据库文件的永久表或临时表。X$表仅仅驻留在内存中,当实例启动时,由Oracle应用程序动态创建,在内存中进行实时的维护。 它们中的大多数至少需要装载或已经打开的数据库。X$表为SYS用户所拥有,并且是只读的。 不能进行DML(更新,插入,删除)X$表对数据库来说至关重要,所以Oracle不允许SYSDBA之外的用户直接访问,显示授权不被允许

 

可以从v$fixed_table中查到X$
SQL>  select count(*) from v$fixed_table where name like 'X$%';

  COUNT(*)

----------

    945

Oracle 11g共有945X$表。

 

关于X$表,其创建信息我们也可以通过bootstrap$表查看,该表中记录了数据库启动的基本及驱动信息。

 

bootstrap$ 实际上存储的是数据字典的基表的定义,如OBJ$,C_OBJ$,TAB$等等。Oracle通过读取这些定义创建数据字典的基表,进而创建数据字典。

 

SQL> select * from bootstrap$;

bootstrap$ 部分比较深,有空在研究。

 

 

1.2.2  GV$ V$ 同义词

 

1.2.2.1  V$ 视图

动态性能视图由前缀V_$标识。这些视图的公用同义词具有前缀V$。数据库管理员或用户应该只访问V$对象,而不是访问V_$对象。动态性能视图由企业管理器和Oracle Trace 使用,Oracle Trace 是访问系统性能信息的主要界面。一旦实例启动,从内存读取数据的 V$视图就可以访问了。

 

注意: 每个V$视图都包含类似语句:

where inst_id = USERENV('Instance')

用于限制返回当前实例信息。

 

这一点我们可以通过V$FIXED_VIEW_DEFINITION 视图 来验证。如:

SQL>  select view_definition from v_$fixed_view_definition where view_name='V$FIXED_TABLE';

VIEW_DEFINITION

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

select  NAME , OBJECT_ID , TYPE , TABLE_NUM from GV$FIXED_TABLE where inst_id = USERENV('Instance')

 

 

通过v$fixed_table 查询V$视图信息:

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

  COUNT(*)

----------

      525http://www.cndba.cn/Dave/article/1449

 

1.2.2.2  GV$ 视图

Oracle8开始,GV$视图开始被引入, GV$Global V$,全局V$。除了一些特例以外(如:V$CACHE_LOCKV$LOCK_ACTIVITYV$LOCKS_WITH_COLLISIONSV$ROLLNAME),每个V$视图都有一个对应的GV$视图存在。在并行服务器环境下,可查询GV$视图从所有限定实例中检索V$视图的信息。V$视图和GV$视图是相同的,V$GV$只是少了INST_ID字段。INST_ID 列显示从其获得相关的V$视图信息的实例号。INST_ID 列可用作一个从可得到的实例集检索V$信息的过滤器。

 

如:

SQL>SELECT * FROM GV$LOCK WHERE INST_ID = 2;

表示从实例2上的V$ 视图中检索信息。

 

通过v$fixed_table 查询GV$视图信息:

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

  COUNT(*)

----------

       496

从查询结果看,GV$496个,V$525个,从这个结果可以证明:不是每个V$同义词都有对应的GV$同义词。

 

1.2.2.3  V$FIXED_VIEW_DEFINITION 视图

通过 V$FIXED_VIEW_DEFINITION 视图可以获取组成V$视图的底层X$表的所有信息。

 

示例1.查看V$FIXED_TABLE 视图定义

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

VIEW_DEFINITION

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

select  NAME , OBJECT_ID , TYPE , TABLE_NUM from GV$FIXED_TABLE where inst_id = USERENV('Instance')

http://www.cndba.cn/Dave/article/1449

 

从这里,我们看到V$FIXED_TABLE基于GV$FIXED_TABLE创建。

 

示例2.查看GV$FIXED_TABLE定义

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

VIEW_DEFINITION

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

select inst_id,kqftanam, kqftaobj, 'TABLE', indx from x$kqfta

union all select inst_id,kqfvinam, kqfviobj, 'VIEW', 65537 from x$kqfvi

union all select inst_id,kqfdtnam, kqfdtobj, 'TABLE', 65537 from x$kqfdt

 

从这里,我们找到了GV$FIXED_TABLE视图的创建语句,该视图基于X$表创建。

 

示例3. 研究下V$PARAMETER 视图

SQL> select view_definition from v$fixed_view_definition a where a.VIEW_NAME='V$PARAMETER';

 

VIEW_DEFINITION

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

/* Formatted on 2010/9/4 13:37:37 (QP5 v5.115.810.9015) */

SELECT   NUM,

         NAME,

         TYPE,

         VALUE,

         DISPLAY_VALUE,

         ISDEFAULT,

         ISSES_MODIFIABLE,

         ISSYS_MODIFIABLE,

         ISINSTANCE_MODIFIABLE,

         ISMODIFIED,

         ISADJUSTED,

         ISDEPRECATED,

         ISBASIC,

         DESCRIPTION,

         UPDATE_COMMENT,

         HASH

  FROM   GV$PARAMETER

 WHERE   inst_id = USERENV ('Instance')

从这里,我们看到V$PARAMETER 是基于GV$PARAMETER 构造的。

http://www.cndba.cn/Dave/article/1449

 

SQL> select view_definition from v$fixed_view_definition a where a.VIEW_NAME='GV$PARAMETER';

 

VIEW_DEFINITION

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

/* Formatted on 2010/9/4 13:38:10 (QP5 v5.115.810.9015) */

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, 'IMMEDIATE',

                 2, 'DEFERRED',

                 3, 'IMMEDIATE',

                 'FALSE'),

         DECODE (BITAND (ksppiflg, 4),

                 4, 'FALSE',

                 DECODE (BITAND (ksppiflg / 65536, 3), 0, 'FALSE', 'TRUE')),

         DECODE (BITAND (ksppstvf, 7),http://www.cndba.cn/Dave/article/1449

                 1, 'MODIFIED',

                 4, 'SYSTEM_MOD',

                 'FALSE'),

         DECODE (BITAND (ksppstvf, 2), 2, 'TRUE', 'FALSE'),

         DECODE (BITAND (ksppilrmflg / 64, 1), 1, 'TRUE', 'FALSE'),

         DECODE (BITAND (ksppilrmflg / 268435456, 1), 1, 'TRUE', 'FALSE'),

         ksppdesc,

         ksppstcmnt,

         ksppihash

  FROM   x$ksppi x, x$ksppcv y

 WHERE   (x.indx = y.indx) AND BITAND (ksppiflg, 268435456) = 0

         AND ( (TRANSLATE (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 基本上包含所有数据库可调整参数.

v$parameter展现的是不包含"_"开头的参数。以"_"开头的参数我们通常称为隐含参数,一般不建议修改,但很多因为功能强大经常使用而广为人知。

 http://www.cndba.cn/Dave/article/1449

关于参数的更多内容参考Blog

Oracle 参数分类 参数的查看方法

http://blog.csdn.net/tianlesoftware/archive/2010/05/13/5583655.aspx

 

 

感兴趣的,可以自己研究下V$FIXED_VIEW_DEFINITION 视图,它是我们研究数据字典的一个入口。

 

 

1.2.3  GV_$, V_$视图

动态性能的视图是通过catalog.sql创建。当catalog.sql运行时:

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

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

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

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

 

我们注意到, 先创建 V_$GV_$ 视图,然后基于V_$视图和GV_$视图来创建V$GV$同义词。

 

所以,实际上通常我们访问的V$视图,其实是指向V_$视图的同义词。而V_$视图是基于X$表建立的。关于这一点可以通过:v$fixed_view_definition视图 来验证。 在上面1.2.2 节有相关的示例。

 

 

访问V$FIXED_VIEW_DEFINITION 视图可以获取组成V$视图的底层X$表的所有信息

 

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

  COUNT(*)

----------

    496

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

  COUNT(*)

----------

     525

 

动态性能对象那么多,如何来判断某个对象到底是同义词还是视图呢? 可以通过如下SQL来实现:

 

SQL> select object_type from all_objects where object_name=upper('v$datafile');

OBJECT_TYPE

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

SYNONYM

 

 

总结一下:

                在实例启动时,会先创建X$表,然后基于X$表创建GV_$ V_$ 视图,在基于GV_$ V_$视图创建GV$V$同义词。 我们一般查询的都是同义词。 关于这些视图的定义,可以通过V$FIXED_VIEW_DEFINITION 视图 来查看。 在数据库运行期间,动态性能视图保存在内存中,时刻监控着数据库的状态,我们在需要的时候可以查看这些视图。 当实例关闭时,数据库又会从内存中自动删除这些动态性能视图。

 

20个常用的动态性能视图:http://www.cndba.cn/Dave/article/1449

1v$sysstat  

2v$sesstat  

3v$sql & v$sql_plan  

4v$sqltext & v$sqlarea  

5v$session  

6v$session_wait & v$session_event  

7v$process  

8v$lock & v$locked_object  

9v$filestat  

10v$session_longops  

11v$latch$ v$latch_children  

12v$db_object_cache  

13v$open_cursor  

14v$parameter & v$system_parameter

15v$rollstat  

16v$rowcache  

17v$segstat & v$segment_statistics  

18v$system_event

19v$undostat  

20v$waitstat  

 

 

 

 

整理自网络

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

Blog http://blog.csdn.net/tianlesoftware

网上资源: http://tianlesoftware.download.csdn.net http://www.cndba.cn/Dave/article/1449

相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx

DBA1 群:62697716(); DBA2 群:62697977()

DBA3 群:63306533;     聊天 群:40132017

版权声明:本文为博主原创文章,未经博主允许不得转载。

oracle 11g

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2237
    原创
  • 2
    翻译
  • 535
    转载
  • 185
    评论
  • 访问:6546568次
  • 积分:4229
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ