ITPub博客

首页 > 数据库 > Oracle > 监控oracle性能的一些常用查询

监控oracle性能的一些常用查询

原创 Oracle 作者:xing_lang 时间:2014-02-21 16:45:32 0 删除 编辑

1.查看临时表空间使用情况
 
Select
f.tablespace_name
,sum(f.bytes_free + f.bytes_used)
/1024/1024/1024 "total GB"
,sum((f.bytes_free + f.bytes_used) - nvl(p.bytes_used, 0))
/1024/1024/1024 "Free GB"
,sum(nvl(p.bytes_used, 0))
/1024/1024/1024 "Used GB"
from sys.v_$temp_space_header f, dba_temp_files d, sys.v_$temp_extent_pool p
where f.tablespace_name(+) = d.tablespace_name
and f.file_id(+) = d.file_id
and p.file_id(+) = d.file_id
group by f.tablespace_name


2.查看使用临时表空间的SQL
Select se.username,

       se.sid,

       su.extents,

       su.blocks * to_number(rtrim(p.value)) as Space,

       tablespace,

       segtype,

       sql_text

  from v$sort_usage su, v$parameter p, v$session se, v$sql s

 where p.name = 'db_block_size'

   and su.session_addr = se.saddr

   and s.hash_value = su.sqlhash

   and s.address = su.sqladdr

 order by se.username, se.sid ;
3.收缩临时表空间
 

alter tablespace temp shrink space;

 

alter tablespace temp shrink tempfile ''

 

4.重建索引
 

alter index PK_CROSSRELATION rebuild;

 

5.查看表空间使用情况
 

SELECT UPPER(F.TABLESPACE_NAME) "表空间名",

  D.TOT_GROOTTE_MB "表空间大小(M)",

  D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",

  TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比",

  F.TOTAL_BYTES "空闲空间(M)",

  F.MAX_BYTES "最大块(M)"

  FROM (SELECT TABLESPACE_NAME,

  ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,

  ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES

  FROM SYS.DBA_FREE_SPACE

  GROUP BY TABLESPACE_NAME) F,

  (SELECT DD.TABLESPACE_NAME,

   ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB

  FROM SYS.DBA_DATA_FILES DD

  GROUP BY DD.TABLESPACE_NAME) D

  WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME

  ORDER BY 1;

 

6.查询表空间的总容量
 

  select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_data_files

  group by tablespace_name;

 

7. 查询表空间使用率
 

  select total.tablespace_name,

  round(total.MB, 2) as Total_MB,考试大论坛

  round(total.MB - free.MB, 2) as Used_MB,

  round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct

  from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_free_space

  group by tablespace_name) free,

  (select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_data_files

  group by tablespace_name) total

  where free.tablespace_name = total.tablespace_name;

 

8. 查找当前表级锁的SQL如下:
 

select sess.sid,

    sess.serial#,

    lo.oracle_username,

    lo.os_user_name,

    ao.object_name,

    lo.locked_mode

    from v$locked_object lo,

    dba_objects ao,

    v$session sess

    where ao.object_id = lo.object_id and lo.session_id = sess.sid;

 

         杀掉锁表进程:

         alter system kill session '436,35123';

 

 

9.监控当前数据库谁在运行什么SQL语句 select osuser, username, sql_text 

from  v$session a, v$sqltext b

where  a.sql_address =b.address order by address, piece;

 

 

10.找使用CPU多的用户session
         select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value

         from  v$session a,v$process b,v$sesstat c

         where  c.statistic#=12 and 

       c.sid=a.sid and 

       a.paddr=b.addr 

       order by value desc;

 

11.查看死锁信息
SELECT (SELECT username

          FROM v$session

         WHERE SID = a.SID) blocker, a.SID, 'is blocking',

       (SELECT username

          FROM v$session

         WHERE SID = b.SID) blockee, b.SID

  FROM v$lock a, v$lock b

 WHERE a.BLOCK = 1 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2;

 

12.具有最高等待的对象
SELECT   o.OWNER,o.object_name, o.object_type, a.event,

         SUM (a.wait_time + a.time_waited) total_wait_time

    FROM v$active_session_history a, dba_objects o

   WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

     AND a.current_obj# = o.object_id

GROUP BY o.OWNER,o.object_name, o.object_type, a.event

ORDER BY total_wait_time DESC;

 

 

13.查看具有最高等待的对象
 

SELECT   a.session_id, s.osuser, s.machine, s.program, o.owner, o.object_name,

         o.object_type, a.event,

         SUM (a.wait_time + a.time_waited) total_wait_time

    FROM v$active_session_history a, dba_objects o, v$session s

   WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

     AND a.current_obj# = o.object_id

     AND a.session_id = s.SID

GROUP BY o.owner,

         o.object_name,

         o.object_type,

         a.event,

         a.session_id,

         s.program,

         s.machine,

         s.osuser

ORDER BY total_wait_time DESC;

 

14.查看等待最多的SQL
 

SELECT   a.program, a.session_id, a.user_id, d.username, s.sql_text,

         SUM (a.wait_time + a.time_waited) total_wait_time

    FROM v$active_session_history a, v$sqlarea s, dba_users d

   WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

     AND a.sql_id = s.sql_id

     AND a.user_id = d.user_id

GROUP BY a.program, a.session_id, a.user_id, s.sql_text, d.username;

 

15.显示正在等待锁的所有会话
 

   SELECT * FROM DBA_WAITERS;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9182041/viewspace-1085850/,如需转载,请注明出处,否则将追究法律责任。

上一篇: SLA GL SqlLink
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2008-05-15

  • 博文量
    39
  • 访问量
    116515