ASH Filter 11g+
ASH Filter 11g+
ASH Filter 11g+
NULL SAMPLE_TIME, NULL INST, NULL SID, NULL SQL_ID, NULL SQL_EXEC_ID, NULL XID,
NULL PLAN_ID, NULL ACTION, NULL TIME_US,
NULL OBJECT_NAME, NULL FILE_NAME, NULL SQL_TYPE, NULL CLIENT_ID, NULL PROGRAM,
NULL MODULE, NULL P1, NULL P2, NULL P3, NULL BLOCKING_SESSION,
NULL COORDINATOR, NULL PLAN_HASH, NULL ACTIVITY, NULL PGA_MB, NULL TEMP_MB, NULL
SQL_TEXT FROM DUAL WHERE 1 = 0
UNION ALL (
SELECT
NULL SAMPLE_TIME, NULL INST, NULL SID, NULL SQL_ID, NULL SQL_EXEC_ID, NULL XID,
NULL PLAN_ID, NULL ACTION, NULL TIME_US,
NULL OBJECT_NAME, NULL FILE_NAME, NULL SQL_TYPE, NULL CLIENT_ID, NULL PROGRAM,
NULL MODULE, NULL P1, NULL P2, NULL P3, NULL BLOCKING_SESSION,
NULL COORDINATOR, NULL PLAN_HASH, NULL ACTIVITY, NULL PGA_MB, NULL TEMP_MB, NULL
SQL_TEXT FROM DUAL WHERE 1 = 0
) UNION ALL ( SELECT * FROM (
WITH BASIS_INFO AS
( SELECT /*+ MATERIALIZE */
/* 11g: - PLAN_ID
- SQL_EXEC_ID
- Direct BLOCKING_SESSION for "cursor: pin S wait on X"
- Activity information (HARD_PARSE, SOFT_PARSE, SQL_EXECUTION, ...)
- PGA and TEMP information
*/
DECODE(DBID, -1, OWN_DBID, DBID) DBID,
DECODE(INSTANCE_NUMBER, -1, USERENV('INSTANCE'), INSTANCE_NUMBER)
INSTANCE_NUMBER,
BEGIN_DATE,
END_DATE,
TO_TIMESTAMP(TO_CHAR(BEGIN_DATE, 'dd.mm.yyyy hh24:mi:ss'),
'dd.mm.yyyy hh24:mi:ss') BEGIN_TIME,
TO_TIMESTAMP(TO_CHAR(END_DATE, 'dd.mm.yyyy hh24:mi:ss'),
'dd.mm.yyyy hh24:mi:ss') END_TIME,
BEGIN_SNAP_ID,
END_SNAP_ID,
SESSION_ID,
SQL_ID,
SQL_EXEC_ID,
PLAN_HASH,
PLAN_ID,
EVENT,
PROGRAM,
MODULE,
CLIENT_ID,
XID,
MIN_PGA_MB,
MIN_TEMP_MB,
ONLY_PARALLEL,
TIME_WAITED_MS,
NUM_RECORDS,
DATA_SOURCE
FROM
( SELECT
-1 DBID,
-2 INSTANCE_NUMBER, /* -2 for all instances, -1 for current instance
*/
TO_DATE('01.01.1000 00:00:00', 'dd.mm.yyyy hh24:mi:ss') BEGIN_DATE,
TO_DATE('31.12.9999 15:00:00', 'dd.mm.yyyy hh24:mi:ss') END_DATE,
-1 BEGIN_SNAP_ID, /* explicit SNAP_IDs sometimes required for ASH partition
pruning */
-1 END_SNAP_ID,
-1 SESSION_ID,
'%' SQL_ID,
-1 SQL_EXEC_ID,
-1 PLAN_HASH,
-1 PLAN_ID,
'%' EVENT,
'%' XID,
'%' PROGRAM,
'%' MODULE,
'%' CLIENT_ID,
-1 MIN_PGA_MB,
-1 MIN_TEMP_MB,
-1 NUM_RECORDS,
-1 TIME_WAITED_MS,
' ' ONLY_PARALLEL,
'AWR' DATA_SOURCE /* AWR, CURRENT */
FROM
DUAL
),
( SELECT DBID OWN_DBID FROM V$DATABASE )
),
SNAPSHOTS AS
( SELECT
HSS.DBID,
HSS.INSTANCE_NUMBER,
MIN(HSS.SNAP_ID) BEGIN_SNAP_ID,
MIN(HSS.BEGIN_INTERVAL_TIME) BEGIN_TIME,
MAX(HSS.SNAP_ID) END_SNAP_ID,
MAX(HSS.END_INTERVAL_TIME) END_TIME
FROM
DBA_HIST_SNAPSHOT HSS,
BASIS_INFO BI
WHERE
HSS.DBID = BI.DBID AND
HSS.END_INTERVAL_TIME >= BI.BEGIN_TIME AND
HSS.BEGIN_INTERVAL_TIME <= BI.END_TIME AND
( BI.BEGIN_SNAP_ID = -1 OR
HSS.SNAP_ID >= BI.BEGIN_SNAP_ID ) AND
( BI.END_SNAP_ID = -1 OR
HSS.SNAP_ID <= BI.END_SNAP_ID )
GROUP BY
HSS.DBID,
HSS.INSTANCE_NUMBER
),
DATAFILES AS
( SELECT
FILE_ID,
FILE_NAME
FROM
DBA_DATA_FILES
UNION ALL
( SELECT
P.VALUE + DTF.FILE_ID FILE_ID,
DTF.FILE_NAME
FROM
DBA_TEMP_FILES DTF,
V$PARAMETER P
WHERE
UPPER(P.NAME) = 'DB_FILES'
)
)
SELECT DISTINCT
TO_CHAR(SAMPLE_TIME, 'YYYY-MM-DD HH24:MI:SS') SAMPLE_TIME,
TO_CHAR(INSTANCE_NUMBER, 9990) INST,
TO_CHAR(SESSION_ID, 99990) SID,
SQL_ID,
SQL_EXEC_ID,
TO_CHAR(RAWTOHEX(XID)) XID,
TO_CHAR(SQL_PLAN_LINE_ID, 999990) PLAN_ID,
DECODE(SESSION_STATE, 'WAITING', EVENT, 'CPU') ACTION,
TO_CHAR(TIME_WAITED, 999999990) TIME_US,
CASE
WHEN EVENT = 'direct path read temp' OR
EVENT = 'direct path write temp' OR
EVENT = 'Data file init write'
THEN
'n/a'
WHEN WAIT_CLASS = 'Application' OR
WAIT_CLASS = 'Cluster' OR
WAIT_CLASS = 'User I/O'
THEN
NVL(OBJECT_NAME, DECODE(CURRENT_OBJ#,
-1, 'Header / Rollback / ANALYZE',
0, 'Undo Data',
SEGSTAT_OBJECT_NAME || ' (previous)'))
ELSE
'n/a'
END OBJECT_NAME,
CASE
WHEN EVENT = 'free buffer waits' OR
EVENT = 'local write wait' OR
EVENT = 'write complete waits' OR
EVENT = 'write complete waits: flash cache' OR
EVENT = 'buffer read retry' OR
EVENT = 'buffer busy waits' OR
EVENT = 'gc buffer busy acquire' OR
EVENT = 'gc buffer busy release' OR
EVENT = 'read by other session' OR
EVENT = 'pi renounce write complete' OR
EVENT = 'db file sequential read' OR
EVENT = 'db file scattered read' OR
EVENT = 'db file single write' OR
EVENT = 'gc current request' OR
EVENT = 'gc cr request' OR
EVENT = 'gc cr disk request' OR
EVENT = 'gc cr multi block request' OR
EVENT = 'gc current multi block request' OR
EVENT = 'gc block recovery request' OR
EVENT = 'gc remaster' OR
EVENT = 'gc domain validation' OR
EVENT = 'gc recovery quiesce' OR
EVENT = 'buffer exterminate' OR
EVENT = 'cr request retry' OR
EVENT = 'recovery buffer pinned' OR
EVENT = 'Auto BMR completion'
THEN
FILE_NAME
ELSE
'n/a'
END FILE_NAME,
NAME SQL_TYPE,
CLIENT_ID,
PROGRAM,
MODULE,
P1,
P2,
P3,
BLOCKING_SESSION,
QC_SESSION_ID COORDINATOR,
SQL_PLAN_HASH_VALUE PLAN_HASH,
DECODE(IN_CONNECTION_MGMT, 'Y', 'CONN_MGMT ') ||
DECODE(IN_PARSE, 'Y', 'SOFT_PARSE ') ||
DECODE(IN_HARD_PARSE, 'Y', 'HARD_PARSE ') ||
DECODE(IN_SQL_EXECUTION, 'Y', 'SQL_EXEC ') ||
DECODE(IN_PLSQL_EXECUTION, 'Y', 'PLSQL_EXEC ') ||
DECODE(IN_PLSQL_RPC, 'Y', 'PLSQL_RPC ') ||
DECODE(IN_PLSQL_COMPILATION, 'Y', 'PLSQL_COMP ') ||
DECODE(IN_JAVA_EXECUTION, 'Y', 'JAVA_EXEC ') ||
DECODE(IN_BIND, 'Y', 'BIND ') ||
DECODE(IN_CURSOR_CLOSE, 'Y', 'CUR_CLOSE ') ||
DECODE(IN_SEQUENCE_LOAD, 'Y', 'SEQ_LOAD ') ACTIVITY,
TO_CHAR(PGA_ALLOCATED / 1024 / 1024, 9990.99) PGA_MB,
TO_CHAR(TEMP_SPACE_ALLOCATED / 1024 / 1024, 999990.99) TEMP_MB,
TO_CHAR(SUBSTR(NVL(SQL_TEXT, NAME), 1, 400)) SQL_TEXT
FROM
( SELECT /*+ FULL(ASH.ASH) */
ASH.SAMPLE_TIME,
ASH.INSTANCE_NUMBER,
ASH.SESSION_ID,
ASH.SQL_ID,
ASH.SQL_EXEC_ID,
ASH.SESSION_STATE,
ASH.EVENT,
ASH.TIME_WAITED,
ASH.WAIT_CLASS,
O.OBJECT_NAME,
SSO.OBJECT_NAME SEGSTAT_OBJECT_NAME,
ASH.CURRENT_OBJ#,
DF.FILE_NAME,
ASH.SQL_OPNAME NAME,
ASH.PROGRAM,
ASH.MODULE,
ASH.CLIENT_ID,
ASH.XID,
ASH.P1,
ASH.P2,
ASH.P3,
ASH.BLOCKING_SESSION,
ASH.QC_SESSION_ID,
ASH.SQL_PLAN_HASH_VALUE,
TO_CHAR(SUBSTR(S.SQL_TEXT, 1, 400)) SQL_TEXT,
ASH.SQL_PLAN_LINE_ID,
ASH.IN_CONNECTION_MGMT,
ASH.IN_PARSE,
ASH.IN_HARD_PARSE,
ASH.IN_SQL_EXECUTION,
ASH.IN_PLSQL_EXECUTION,
ASH.IN_PLSQL_RPC,
ASH.IN_PLSQL_COMPILATION,
ASH.IN_JAVA_EXECUTION,
ASH.IN_BIND,
ASH.IN_CURSOR_CLOSE,
ASH.IN_SEQUENCE_LOAD,
ASH.PGA_ALLOCATED,
ASH.TEMP_SPACE_ALLOCATED
FROM
DBA_HIST_ACTIVE_SESS_HISTORY ASH,
DBA_HIST_SQLTEXT S,
DATAFILES DF,
DBA_OBJECTS O,
DBA_HIST_SEG_STAT_OBJ SSO,
SNAPSHOTS SS,
BASIS_INFO BI
WHERE
SS.DBID = ASH.DBID AND
ASH.DBID = S.DBID (+) AND
ASH.DBID = SSO.DBID (+) AND
ASH.SNAP_ID BETWEEN SS.BEGIN_SNAP_ID AND SS.END_SNAP_ID AND
NVL(ASH.SQL_ID, ' ') = S.SQL_ID (+) AND
ASH.CURRENT_OBJ# = O.OBJECT_ID (+) AND
ASH.CURRENT_OBJ# = SSO.OBJ# (+) AND
ASH.SAMPLE_TIME BETWEEN BI.BEGIN_TIME AND BI.END_TIME AND
NVL(ASH.SQL_ID, ' ') LIKE BI.SQL_ID AND
( BI.SQL_EXEC_ID = -1 OR
BI.SQL_EXEC_ID = ASH.SQL_EXEC_ID ) AND
( BI.PLAN_HASH = -1 OR
NVL(ASH.SQL_PLAN_HASH_VALUE, 0) = BI.PLAN_HASH ) AND
( BI.PLAN_ID = -1 OR
NVL(ASH.SQL_PLAN_LINE_ID, 0) = BI.PLAN_ID ) AND
NVL(ASH.EVENT, 'CPU') LIKE BI.EVENT AND
( BI.INSTANCE_NUMBER = -2 OR
BI.INSTANCE_NUMBER = ASH.INSTANCE_NUMBER ) AND
( BI.SESSION_ID = -1 OR
BI.SESSION_ID = ASH.SESSION_ID ) AND
( BI.ONLY_PARALLEL = ' ' OR ASH.QC_SESSION_ID IS NOT NULL) AND
NVL(ASH.PROGRAM, ' ') LIKE BI.PROGRAM AND
NVL(ASH.MODULE, ' ') LIKE BI.MODULE AND
NVL(ASH.CLIENT_ID, ' ') LIKE BI.CLIENT_ID AND
( ASH.XID IS NULL AND BI.XID = '%' OR ASH.XID LIKE BI.XID ) AND
( BI.MIN_PGA_MB = -1 OR
BI.MIN_PGA_MB <= NVL(ASH.PGA_ALLOCATED, 0) / 1024 / 1024 ) AND
( BI.MIN_TEMP_MB = -1 OR
BI.MIN_TEMP_MB <= NVL(ASH.TEMP_SPACE_ALLOCATED, 0) / 1024 / 1024 ) AND
ASH.P1 = DF.FILE_ID (+) AND
( BI.TIME_WAITED_MS = -1 OR
ASH.TIME_WAITED >= BI.TIME_WAITED_MS * 1000 ) AND
( BI.NUM_RECORDS = -1 OR ROWNUM <= BI.NUM_RECORDS ) AND
BI.DATA_SOURCE = 'AWR'
UNION ALL
( SELECT DISTINCT
ASH.SAMPLE_TIME,
ASH.INST_ID INSTANCE_NUMBER,
ASH.SESSION_ID,
ASH.SQL_ID,
ASH.SQL_EXEC_ID,
ASH.SESSION_STATE,
ASH.EVENT,
ASH.TIME_WAITED,
ASH.WAIT_CLASS,
O.OBJECT_NAME,
SSO.OBJECT_NAME SEGSTAT_OBJECT_NAME,
ASH.CURRENT_OBJ#,
DF.FILE_NAME,
ASH.SQL_OPNAME NAME,
ASH.PROGRAM,
ASH.MODULE,
ASH.CLIENT_ID,
ASH.XID,
ASH.P1,
ASH.P2,
ASH.P3,
ASH.BLOCKING_SESSION,
ASH.QC_SESSION_ID,
ASH.SQL_PLAN_HASH_VALUE,
S.SQL_TEXT,
ASH.SQL_PLAN_LINE_ID,
ASH.IN_CONNECTION_MGMT,
ASH.IN_PARSE,
ASH.IN_HARD_PARSE,
ASH.IN_SQL_EXECUTION,
ASH.IN_PLSQL_EXECUTION,
ASH.IN_PLSQL_RPC,
ASH.IN_PLSQL_COMPILATION,
ASH.IN_JAVA_EXECUTION,
ASH.IN_BIND,
ASH.IN_CURSOR_CLOSE,
ASH.IN_SEQUENCE_LOAD,
ASH.PGA_ALLOCATED,
ASH.TEMP_SPACE_ALLOCATED
FROM
GV$ACTIVE_SESSION_HISTORY ASH,
GV$SQLTEXT S,
DATAFILES DF,
DBA_OBJECTS O,
DBA_HIST_SEG_STAT_OBJ SSO,
BASIS_INFO BI
WHERE
NVL(ASH.SQL_ID, ' ') = S.SQL_ID (+) AND
S.PIECE (+) = 0 AND
ASH.CURRENT_OBJ# = O.OBJECT_ID (+) AND
ASH.CURRENT_OBJ# = SSO.OBJ# (+) AND
ASH.SAMPLE_TIME BETWEEN BI.BEGIN_TIME AND BI.END_TIME AND
NVL(ASH.SQL_ID, ' ') LIKE BI.SQL_ID AND
( BI.SQL_EXEC_ID = -1 OR
BI.SQL_EXEC_ID = ASH.SQL_EXEC_ID ) AND
( BI.PLAN_HASH = -1 OR
NVL(ASH.SQL_PLAN_HASH_VALUE, 0) = BI.PLAN_HASH ) AND
( BI.PLAN_ID = -1 OR
NVL(ASH.SQL_PLAN_LINE_ID, 0) = BI.PLAN_ID ) AND
NVL(ASH.EVENT, 'CPU') LIKE BI.EVENT AND
( BI.INSTANCE_NUMBER = -2 OR
BI.INSTANCE_NUMBER = ASH.INST_ID ) AND
( BI.SESSION_ID = -1 OR
BI.SESSION_ID = ASH.SESSION_ID ) AND
( BI.ONLY_PARALLEL = ' ' OR ASH.QC_SESSION_ID IS NOT NULL) AND
NVL(ASH.PROGRAM, ' ') LIKE BI.PROGRAM AND
NVL(ASH.MODULE, ' ') LIKE BI.MODULE AND
NVL(ASH.CLIENT_ID, ' ') LIKE BI.CLIENT_ID AND
( ASH.XID IS NULL AND BI.XID = '%' OR ASH.XID LIKE BI.XID ) AND
( BI.MIN_PGA_MB = -1 OR
BI.MIN_PGA_MB <= NVL(ASH.PGA_ALLOCATED, 0) / 1024 / 1024 ) AND
( BI.MIN_TEMP_MB = -1 OR
BI.MIN_TEMP_MB <= NVL(ASH.TEMP_SPACE_ALLOCATED, 0) / 1024 / 1024 ) AND
ASH.P1 = DF.FILE_ID (+) AND
( BI.TIME_WAITED_MS = -1 OR
ASH.TIME_WAITED >= BI.TIME_WAITED_MS * 1000 ) AND
( BI.NUM_RECORDS = -1 OR ROWNUM <= BI.NUM_RECORDS ) AND
BI.DATA_SOURCE = 'CURRENT'
)
)
ORDER BY
SAMPLE_TIME DESC,
INST,
SID
));