zoukankan      html  css  js  c++  java
  • oracle性能诊断排查

    https://blog.csdn.net/qq_30553235/article/details/78809872

    查看oracle用户权限:

    1.查看不同用户的连接数
    select username,count(username) from v$session where username is not null group by username;
    2.查看所有用户
    select * from all_users;
    3.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
    select * from dba_sys_privs;
    select * from user_sys_privs;
    4.查看角色(只能查看登陆用户拥有的角色)所包含的权限
    select * from role_sys_privs;
    5.查看用户对象权限:
    select * from dba_tab_privs;
    select * from all_tab_privs;
    select * from user_tab_privs;
    
    6.查看所有角色:
    select * from dba_roles;
    7.查看用户或角色所拥有的角色:
    select * from dba_role_privs;
    select * from user_role_privs;
    8.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
    select * from V$PWFILE_USERS;
    

      

    查看oracle链接池开放及使用

    1.查询数据库允许的最大连接数
    select value from v$parameter where name = 'processes'
    alter system set processes = 300 scope = spfile; //修改链接数<重启数据库>
    2.查看当前有哪些用户正在使用数据
    select osuser, a.username,cpu_time/executions/1000000||'s', sql_fulltext,machine
    from v$session a, v$sqlarea b
    where a.sql_address =b.address order by cpu_time/executions desc;
    
    3.查看数据库当前链接数
    select count(*) from v$session;
    4.查询oracle的并发连接数
    select count(*) from v$session where status='ACTIVE';
    //show parameter processes #最大连接
    //alter system set processes = value scope = spfile;重启数据库 #修改连接
    5.查看不同用户的连接数 select username,count(username) from v$session where username is not null group by username;

      

    oracle查看表空间使用率,包含临时表空间

    select * from ( 
    Select a.tablespace_name, 
    to_char(a.bytes/1024/1024,'99,999.999') total_bytes, 
    to_char(b.bytes/1024/1024,'99,999.999') free_bytes, 
    to_char(a.bytes/1024/1024 - b.bytes/1024/1024,'99,999.999') use_bytes, 
    to_char((1 - b.bytes/a.bytes)*100,'99.99') || '%' use 
    from (select tablespace_name, 
    sum(bytes) bytes 
    from dba_data_files 
    group by tablespace_name) a, 
    (select tablespace_name, 
    sum(bytes) bytes 
    from dba_free_space 
    group by tablespace_name) b 
    where a.tablespace_name = b.tablespace_name 
    union all 
    select c.tablespace_name, 
    to_char(c.bytes/1024/1024,'99,999.999') total_bytes, 
    to_char( (c.bytes-d.bytes_used)/1024/1024,'99,999.999') free_bytes, 
    to_char(d.bytes_used/1024/1024,'99,999.999') use_bytes, 
    to_char(d.bytes_used*100/c.bytes,'99.99') || '%' use 
    from 
    (select tablespace_name,sum(bytes) bytes 
    from dba_temp_files group by tablespace_name) c, 
    (select tablespace_name,sum(bytes_cached) bytes_used 
    from v$temp_extent_pool group by tablespace_name) d 
    where c.tablespace_name = d.tablespace_name 
    ) 
    

      

    oracle查看内存使用情况

    SGA、PGA使用情况

    --pctused: 使用率
    select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctused from 
    (select 'SGA' name,(select sum(value/1024/1024) from v$sga) total,
    (select sum(bytes/1024/1024) from v$sgastat where name='free memory')free from dual)
    union
    select name,total,round(used,2)used,round(total-used,2)free,round(used/total*100,2)pctused from (
    select 'PGA' name,(select value/1024/1024 total from v$pgastat where name='aggregate PGA target parameter')total,
    (select value/1024/1024 used from v$pgastat where name='total PGA allocated')used from dual);

    内存使用率

    -- pctused: 使用率
    select * from (
    select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctused from 
    (select 'SGA' name,(select sum(value/1024/1024) from v$sga) total,
    (select sum(bytes/1024/1024) from v$sgastat where name='free memory')free from dual)
    union
    select name,total,round(used,2)used,round(total-used,2)free,round(used/total*100,2)pctused from (
    select 'PGA' name,(select value/1024/1024 total from v$pgastat where name='aggregate PGA target parameter')total,
    (select value/1024/1024 used from v$pgastat where name='total PGA allocated')used from dual)
      union
    select name,round(total,2) total,round((total-free),2) used,round(free,2) free,round((total-free)/total*100,2) pctused from (
    select 'Shared pool' name,(select sum(bytes/1024/1024) from v$sgastat where pool='shared pool')total,
    (select bytes/1024/1024 from v$sgastat where name='free memory' and pool='shared pool') free from dual)
    union
    select name,round(total,2)total,round(total-free,2) used,round(free,2) free,round((total-free)/total,2) pctused from (
    select 'Default pool' name,( select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p
      where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=(select value from v$parameter where name='db_block_size')) total,
    (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p 
    where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual)
    union
      select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from (
    select 'KEEP pool' name,(select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p
      where a.set_id=p.LO_SETID and p.name='KEEP' and p.block_size=(select value from v$parameter where name='db_block_size')) total,
    (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p 
    where a.set_id=p.LO_SETID and p.name='KEEP' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual)
    union
    select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from (
    select 'RECYCLE pool' name,( select a.cnum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 total from x$kcbwds a, v$buffer_pool p
      where a.set_id=p.LO_SETID and p.name='RECYCLE' and p.block_size=(select value from v$parameter where name='db_block_size')) total,
    (select a.anum_repl*(select value from v$parameter where name='db_block_size')/1024/1024 free from x$kcbwds a, v$buffer_pool p 
    where a.set_id=p.LO_SETID and p.name='RECYCLE' and p.block_size=(select value from v$parameter where name='db_block_size')) free from dual)
    union
    select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from(
    select 'DEFAULT 16K buffer cache' name,(select a.cnum_repl*16/1024 total from x$kcbwds a, v$buffer_pool p
      where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=16384) total,
      (select a.anum_repl*16/1024 free from x$kcbwds a, v$buffer_pool p 
    where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=16384) free from dual)
    union
    select name,nvl(round(total,2),0)total,nvl(round(total-free,2),0) used,nvl(round(free,2),0) free,nvl(round((total-free)/total,2),0) pctused from(
    select 'DEFAULT 32K buffer cache' name,(select a.cnum_repl*32/1024 total from x$kcbwds a, v$buffer_pool p
      where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=32768) total,
      (select a.anum_repl*32/1024 free from x$kcbwds a, v$buffer_pool p 
    where a.set_id=p.LO_SETID and p.name='DEFAULT' and p.block_size=32768) free from dual)
    union
    select name,total,total-free used,free, (total-free)/total*100 pctused from (
    select 'Java Pool' name,(select sum(bytes/1024/1024) total from v$sgastat where pool='java pool' group by pool)total,
    ( select bytes/1024/1024 free from v$sgastat where pool='java pool' and name='free memory')free from dual)
    union
    select name,Round(total,2),round(total-free,2) used,round(free,2) free, round((total-free)/total*100,2) pctused from (
    select 'Large Pool' name,(select sum(bytes/1024/1024) total from v$sgastat where pool='large pool' group by pool)total,
    ( select bytes/1024/1024 free from v$sgastat where pool='large pool' and name='free memory')free from dual)
    order by pctused desc);
    

      

    诊断

    select * from v$sga_dynamic_components;
    select * from v$pgastat;
     
    -- 查询share pool的空闲内存
    select a.*,round(a.bytes/1024/1024,2) M from v$sgastat a where a.NAME = 'free memory';
     
    -- 通过下面的sql查询占用share pool内存大于10M的sql
    SELECT substr(sql_text,1,100) "Stmt", count(*),
                    sum(sharable_mem)    "Mem",
                    sum(users_opening)   "Open",
                    sum(executions)      "Exec"
              FROM v$sql
             GROUP BY substr(sql_text,1,100)
            HAVING sum(sharable_mem) > 10000000;
            
            
    -- 查询一下version count过高的语句
    SELECT address,
           sql_id,
           hash_value,
           version_count,
           users_opening,
           users_executing,
           sql_text
      FROM v$sqlarea WHERE version_count > 10;
    

      

     

      

  • 相关阅读:
    re
    jieba
    Normalization的作用,LN,BN,WN
    RBF神经网络
    其他论文
    numpy, pandas,collections.Counter
    tensorflow 相关
    机器翻译(machine translation)相关
    2020 weblogin rce CVE-2020-14882 漏洞利用POC
    CVE-2021-3019 漏洞细节纰漏
  • 原文地址:https://www.cnblogs.com/Alexr/p/9993427.html
Copyright © 2011-2022 走看看