zoukankan      html  css  js  c++  java
  • 两个简单的动态视图:v$statname、v$mystat的一点说明

     
    关于Oracle错误:动态执行表不可访问,本会话自动统计被禁止,关闭自动统计之后的问题:
     
        在v$session,v$statname,v$sesstat和v$mystat四个动态执行表中没有select权限导致我每次执行语句时会提示,告诉我会话的自动统计被禁止。
     
    解决方法:
     
    用SYS登录,授权给相应的用户,用下面的语句,
    grant select on v_$statname to user;
    自动统计功能可以关掉。
    最后的这个,超时断开问题,可以设置USER_PROFILES里面看到的IDLE_TIME值,
    首先查看你的当前用户的PROFILE是哪个,
    select profile from dba_users where username='SCOTT' ;
    假如是DEFAULT这个PROFILE,那么修改IDLE_TIME这个值
    alter profile default limit idle_time unlimited ;
    必要时创建新的PROFILE。
     
    v$statname是对统计信息的说明,STATISTIC#相当于编号,NAME就是统计量的名称。
    Sql代码 复制代码 收藏代码
    1. sys@OCP10G> desc v$statname;   
    2. 名称                          是否为空?                       类型 
    3. --------------------------------------------------------------------------------------- 
    4. STATISTIC#                                NUMBER 
    5. NAME                                   VARCHAR2(64) 
    6. CLASS                                   NUMBER 
    7. STAT_ID                                  NUMBER 
    sys@OCP10G> desc v$statname;  
     名称                          是否为空?                       类型
    ---------------------------------------------------------------------------------------
    STATISTIC#                                NUMBER
    NAME                                   VARCHAR2(64)
    CLASS                                   NUMBER
    STAT_ID                                  NUMBER
    
     
    Sql代码 复制代码 收藏代码
    1. sys@OCP10G> select * from v$statname; 
    2.  
    3. STATISTIC# 
    4. NAME                                      CLASS                                 STAT_ID 
    5. --------------------------------------------------------------------------------------- 
    6. 0 logons cumulative                     1                                 2666645286 
    7. 1 logons current                           1                                 3080465522 
    8. 2 opened cursors cumulative        1                                85052502 
    9. 3 opened cursors current             1                                2301954928 
    10.     .... 
    11. 314 OTC commit optimization hits          1                    284064864054 
    12. 315 OTC commit optimization failure - setup      1       28 3633344886 
    sys@OCP10G> select * from v$statname;
    
    STATISTIC#
     NAME                                      CLASS                                 STAT_ID
    ---------------------------------------------------------------------------------------
    0 logons cumulative                     1                                 2666645286
    1 logons current                           1                                 3080465522
    2 opened cursors cumulative        1                                85052502
    3 opened cursors current             1                                2301954928
        ....
    314 OTC commit optimization hits          1                    284064864054
    315 OTC commit optimization failure - setup      1       28 3633344886
    
    
    v$mystat字面来说就是当前用户的各种统计信息,sid就是session的id(也就是当前用户),STATISTIC#就是统计量的编号(用来唯一确定统计量
    的名称),value是统计量的值。
    Sql代码 复制代码 收藏代码
    1. sys@OCP10G> show user 
    2.  
    3. USER"SYS" 
    4.  
    5. sys@OCP10G> select sid,username from v$session where username='SYS'
    6.        SID                 USERNAME 
    7. ------------------------------------------------------------------ 
    8.        138                      SYS 
    9.  
    10. sys@OCP10G> desc v$mystat; 
    11.  
    12. 名称                    是否为空?                    类型 
    13. -------------------------------------------------------------------------------------- 
    14. SID                                                             NUMBER 
    15. STATISTIC#                                                NUMBER 
    16. VALUE                                                         NUMBER 
    17.  
    18. sys@OCP10G> select * from v$mystat where rownum<10; 
    19.  
    20.        SID       STATISTIC#         VALUE 
    21. ------------------------------------------------------------------------ 
    22.        138            0                       1 
    23.        138            1                       1 
    24.        138            2                      54 
    25.        138            3                       1 
    26.         ... 
    27.        138          314                    0 
    28.        138          315                     0 
    sys@OCP10G> show user
    
    USER 为 "SYS"
    
    sys@OCP10G> select sid,username from v$session where username='SYS';
           SID                 USERNAME
    ------------------------------------------------------------------
           138                      SYS
    
    sys@OCP10G> desc v$mystat;
    
    名称                    是否为空?                    类型
    --------------------------------------------------------------------------------------
    SID                                                             NUMBER
    STATISTIC#                                                NUMBER
    VALUE                                                         NUMBER
    
    sys@OCP10G> select * from v$mystat where rownum<10;
    
           SID       STATISTIC#         VALUE
    ------------------------------------------------------------------------
           138            0                       1
           138            1                       1
           138            2                      54
           138            3                       1
            ...
           138          314                    0
           138          315                     0
    
    小结: v$statname视图获取系统的统计量的说明 v$mystat视图获取当前用户的在v$statname中的每个统计量的值 两个视图按STATISTIC#连接,可以得到当前用户的sid,统计量的编号,统计量的名称,和统计值.
    Sql代码 复制代码 收藏代码
    1. select b.sid,a.STATISTIC#,a.name,b.value from v$statname a,v$mystat b  
    2.  
    3. where a.STATISTIC#=b.STATISTIC#; 
    4.  
    5.    SID      STATISTIC#                  NAME                                 VALUE 
    6. --------------------------------------------------------------------------------------- 
    7.    138             0                    logonscumulative          1 
    8.    138             1                      logons current           1 
    9.    138             2               opened cursors cumulative      56 
    10.    138             3                 opened cursors current       1 
    11.         ... 
    12.    138            314           OTC commit optimization hits     0 
    13.    138            315       OTC commit optimization failure - setup 0 
  • 相关阅读:
    OAuth
    PHP获取客户端的真实IP
    负载均衡----实现配置篇(Nginx)
    在线时间戳转换
    使用curl进行模拟登录
    定时任务
    Matplotlib使用教程
    CentOS7.X安装PHP
    Python虚拟环境的搭建与使用
    CentOS7.X安装openssl
  • 原文地址:https://www.cnblogs.com/weixun/p/3087760.html
Copyright © 2011-2022 走看看