一些小SQL

action929發表於2007-07-30

找出資料庫中熱點物件 SELECT B.OWNER, B.OBJECT_NAME, B.OBJECT_TYPE, A.FILE#, A.DBABLK, A.TCH FROM X$BH A, DBA_OBJECTS B WHERE A.OBJ = B.OBJECT_ID AND A.TCH >= 10 AND B.OWNER <> 'SYS' ORDER BY TCH DESC 找到熱資料塊 Oracle 8i保留著一個X$BH內部檢視錶,用來顯示資料緩衝池的相對效能。X$BH檢視錶有下列資料列: Tim:兩次使用之間的時間差,和_db_aging_touch_time引數相關。 Tch:使用計數,它和被使用過_db_aging_hot_criteria次之後從冷區移入熱區直接相關。

找出全表(索引)掃描
===========================================================

select OBJ.OWNER,OBJ.OBJECT_NAME,count(*),
(select ROUND(sum(SEG.BYTES) / 1024 / 1024, 2) from DBA_SEGMENTS SEG
where SEG.OWNER=OBJ.OWNER and SEG.SEGMENT_NAME=OBJ.OBJECT_NAME ) OBJSIZE_M
from DBA_OBJECTS OBJ,
SYS.X$BH XBH
where OBJ.OBJECT_TYPE in ('TABLE', 'INDEX') and
XBH.OBJ = OBJ.DATA_OBJECT_ID and
BITAND(XBH.FLAG, 524288) > 0 and
OBJ.OWNER not in ('SYS', 'SYSTEM', 'XDB')
group by OBJ.OWNER,
OBJ.OBJECT_NAME
order by 3 desc;


select OPNAME,
TARGET,
TO_CHAR(START_TIME, 'yy-mm-dd:hh24:mi:ss') START_TIME,
ELAPSED_SECONDS ELAPSED,
EXECUTIONS EXECS,
BUFFER_GETS / DECODE(EXECUTIONS, 0, 1, EXECUTIONS) BUFGETS,
MODULE,
SQL_TEXT
from V$SESSION_LONGOPS SL,
V$SQLAREA SA
where SL.SQL_HASH_VALUE = SA.HASH_VALUE and
UPPER(SUBSTR(MODULE, 1, 4)) <>'RMAN' and
SUBSTR(OPNAME, 1, 4)<> 'RMAN' and
MODULE <>'SQL*Plus' and
SL.START_TIME > TRUNC(sysdate) - 100
order by START_TIME;

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133835/viewspace-929459/,如需轉載,請註明出處,否則將追究法律責任。

相關文章