1. Session Wise Latest Running SQL Statement.
SELECT T.INST_ID,S.USERNAME, S.SID, S.SERIAL#,T.SQL_ID,T.SQL_TEXT "Last SQL"
FROM GV$SESSION S, GV$SQLAREA T
WHERE S.SQL_ADDRESS =T.ADDRESS
AND S.SQL_HASH_VALUE =T.HASH_VALUE;
2. Currently Executing SQL Statements.
SELECT I.INST_ID,S.SID,SERIAL#,A.SQL_ID,S.EVENT,A.SQL_TEXT,A.SQL_FULLTEXT,S.USERNAME,I.HOST_NAME,MACHINE,S.SECONDS_IN_WAIT SEC_WAIT,
TO_CHAR(LOGON_TIME,'DD-MON-RR HH24:MI') "Session Login Time"
FROM GV$SESSION S,GV$SQLAREA A,GV$INSTANCE I
WHERE S.USERNAME IS NOT NULL
AND S.STATUS='ACTIVE'
AND S.SQL_ADDRESS=A.ADDRESS
AND S.INST_ID=A.INST_ID
AND I.INST_ID = A.INST_ID
AND SQL_TEXT NOT LIKE 'SELECT SID,SERIAL#,A.SQL_ID,A.SQL_TEXT%';
3. Currently Waiting Session With SQL Statements.
SELECT W.SID, W.EVENT, W.WAIT_CLASS_ID, W.WAIT_CLASS, W.WAIT_TIME, W.SECONDS_IN_WAIT, W.WAIT_TIME_MICRO, Q.SQL_ID, Q.PLAN_HASH_VALUE,
SQL_TEXT, SQL_FULLTEXT
FROM V$SESSION_WAIT W, V$SESSION S, V$SQL Q
WHERE W.SID=S.SID
AND S.SQL_ID=Q.SQL_ID
AND W.WAIT_TIME =0
AND W.EVENT<>'SQL*Net message from client'
AND W.WAIT_CLASS<>'Idle'
ORDER BY W.SID;
Note :
W.WAIT_TIME > 0 - Value is the duration of the last wait in hundredths of a second
W.WAIT_TIME =-1 - Duration of the last wait was less than a hundredth of a second
W.WAIT_TIME =-2 - Parameter TIMED_STATISTICS was set to false
4. Latest Running SQL Statements.
SELECT H.INST_ID,H.SAMPLE_TIME,H.SESSION_ID,H.SESSION_SERIAL#,H.SQL_ID
FROM GV$ACTIVE_SESSION_HISTORY H
WHERE H.SQL_ID IS NOT NULL
ORDER BY 1 DESC;
5. Long Time Running SQL Statements.
SELECT SID,OPNAME,SQL_ID, SQL_PLAN_HASH_VALUE, SQL_EXEC_START,TARGET,ROUND(SOFAR/TOTALWORK*100,2) "Percent Done" ,
START_TIME,LAST_UPDATE_TIME,TIME_REMAINING
FROM V$SESSION_LONGOPS;
6. Active Session Running More Then 30 Min.
SELECT USERNAME,MACHINE,INST_ID,SID,SERIAL#,PROGRAM,TO_CHAR(LOGON_TIME,'dd-mm-yy hh:mi:ss AM')"Logon Time",
ROUND((SYSDATE-LOGON_TIME)*(24*60),1) MINUTES_LOG_ON,ROUND(LAST_CALL_ET/60,1) MINUTES_CURRENT_SQL
FROM GV$SESSION
WHERE STATUS='ACTIVE'
AND USERNAME IS NOT NULL
AND ROUND((SYSDATE-LOGON_TIME)*(24*60),1) > 30
ORDER BY MINUTES_LOG_ON DESC;
7. Active Transaction Details with SQL ID.
SELECT SQL_ADDRESS, SQL_HASH_VALUE, SQL_ID,T.STATUS, START_TIME,USERNAME, T.USED_UBLK, T.USED_UREC
FROM V$TRANSACTION T, V$SESSION S
WHERE T.ADDR = S.TADDR;
SELECT T.INST_ID,S.USERNAME, S.SID, S.SERIAL#,T.SQL_ID,T.SQL_TEXT "Last SQL"
FROM GV$SESSION S, GV$SQLAREA T
WHERE S.SQL_ADDRESS =T.ADDRESS
AND S.SQL_HASH_VALUE =T.HASH_VALUE;
2. Currently Executing SQL Statements.
SELECT I.INST_ID,S.SID,SERIAL#,A.SQL_ID,S.EVENT,A.SQL_TEXT,A.SQL_FULLTEXT,S.USERNAME,I.HOST_NAME,MACHINE,S.SECONDS_IN_WAIT SEC_WAIT,
TO_CHAR(LOGON_TIME,'DD-MON-RR HH24:MI') "Session Login Time"
FROM GV$SESSION S,GV$SQLAREA A,GV$INSTANCE I
WHERE S.USERNAME IS NOT NULL
AND S.STATUS='ACTIVE'
AND S.SQL_ADDRESS=A.ADDRESS
AND S.INST_ID=A.INST_ID
AND I.INST_ID = A.INST_ID
AND SQL_TEXT NOT LIKE 'SELECT SID,SERIAL#,A.SQL_ID,A.SQL_TEXT%';
3. Currently Waiting Session With SQL Statements.
SELECT W.SID, W.EVENT, W.WAIT_CLASS_ID, W.WAIT_CLASS, W.WAIT_TIME, W.SECONDS_IN_WAIT, W.WAIT_TIME_MICRO, Q.SQL_ID, Q.PLAN_HASH_VALUE,
SQL_TEXT, SQL_FULLTEXT
FROM V$SESSION_WAIT W, V$SESSION S, V$SQL Q
WHERE W.SID=S.SID
AND S.SQL_ID=Q.SQL_ID
AND W.WAIT_TIME =0
AND W.EVENT<>'SQL*Net message from client'
AND W.WAIT_CLASS<>'Idle'
ORDER BY W.SID;
Note :
W.WAIT_TIME > 0 - Value is the duration of the last wait in hundredths of a second
W.WAIT_TIME =-1 - Duration of the last wait was less than a hundredth of a second
W.WAIT_TIME =-2 - Parameter TIMED_STATISTICS was set to false
4. Latest Running SQL Statements.
SELECT H.INST_ID,H.SAMPLE_TIME,H.SESSION_ID,H.SESSION_SERIAL#,H.SQL_ID
FROM GV$ACTIVE_SESSION_HISTORY H
WHERE H.SQL_ID IS NOT NULL
ORDER BY 1 DESC;
5. Long Time Running SQL Statements.
SELECT SID,OPNAME,SQL_ID, SQL_PLAN_HASH_VALUE, SQL_EXEC_START,TARGET,ROUND(SOFAR/TOTALWORK*100,2) "Percent Done" ,
START_TIME,LAST_UPDATE_TIME,TIME_REMAINING
FROM V$SESSION_LONGOPS;
6. Active Session Running More Then 30 Min.
SELECT USERNAME,MACHINE,INST_ID,SID,SERIAL#,PROGRAM,TO_CHAR(LOGON_TIME,'dd-mm-yy hh:mi:ss AM')"Logon Time",
ROUND((SYSDATE-LOGON_TIME)*(24*60),1) MINUTES_LOG_ON,ROUND(LAST_CALL_ET/60,1) MINUTES_CURRENT_SQL
FROM GV$SESSION
WHERE STATUS='ACTIVE'
AND USERNAME IS NOT NULL
AND ROUND((SYSDATE-LOGON_TIME)*(24*60),1) > 30
ORDER BY MINUTES_LOG_ON DESC;
7. Active Transaction Details with SQL ID.
SELECT SQL_ADDRESS, SQL_HASH_VALUE, SQL_ID,T.STATUS, START_TIME,USERNAME, T.USED_UBLK, T.USED_UREC
FROM V$TRANSACTION T, V$SESSION S
WHERE T.ADDR = S.TADDR;
No comments:
Post a Comment