Long running SQL and verify database locks


CPU usage

SELECT s.sid, s.serial#, p.spid as "OS PID",s.username, s.module, st.value/100 as "CPU sec" 
FROM v$sesstat st, v$statname sn, v$session s, v$process p WHERE sn.name = 'CPU used by this session' -- CPU 
AND st.statistic# = sn.statistic#
AND st.sid = s.sid
AND s.paddr = p.addr
AND s.last_call_et < 1800 -- active within last 1/2 hour
AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours

ORDER BY st.value;


SET ECHO OFF
COL HOURS          FORMAT 999,990.99
COL MESSAGE        FORMAT A22
COL OPNAME         FORMAT A16        HEA "OPERATION"
COL PCT_COMPLETE   FORMAT 99.9        HEA "PCT" 
COL SERIAL#        FORMAT 99999
COL SID            FORMAT 9999
COL STARTED        FORMAT A16        HEA "START TIME"
COL TARGET         FORMAT A16
COL TARGET_DESC    FORMAT A16
COL REMAIN_MIN     FORMAT 99,999,999
COL ELASPSED_MIN   FORMAT 99,999,999
COL UNITS          FORMAT A10
COL USERNAME       FORMAT A15
set linesize 120
-- SET ECHO ON
SELECT SID
--      ,SERIAL#
      ,USERNAME
      ,OPNAME
      ,TO_CHAR(START_TIME,'MM/DD HH24:MI:SS') STARTED
      , decode(totalwork, 0, 100,SOFAR/TOTALWORK*100)   PCT_COMPLETE
      ,ELAPSED_SECONDS/60       ELASPSED_MIN
--     ,TOTALWORK
--      ,UNITS
     ,TIME_REMAINING/60         REMAIN_MIN
   FROM gV$SESSION_LONGOPS
   WHERE  USERNAME != 'SYS'
--    and SOFAR/TOTALWORK*100 !=100
   and  TIME_REMAINING/60 !=0 
   ORDER BY ELAPSED_SECONDS DESC
;



Jobs

set lines 130
col LOG_USER from a15
select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,LAST_DATE,NEXT_DATE,BROKEN from dba_jobs;
SELECT JOB,WHAT,BROKEN,TO_CHAR(NEXT_DATE,'YY-MM-DD HH24:MI:SS') FROM DBA_JOBS;

lock

SELECT a.serial# as serial,a.sid,a.username,b.type,b.ctime,lmode,a.osuser,c.sql_text
FROM v$session a,v$lock b, v$sqlarea c
WHERE b.type in ('TM','TX','UL') and a.sid=b.sid and lmode > 0 and ((a.PREV_HASH_VALUE = c.hash_value and a.prev_sql_addr = c.address and a.sql_hash_value = 0) or (c.hash_value=a.sql_hash_value and c.address = a.sql_address))
;



sleep 30
SELECT job_name, job_class, operation, status, to_char(log_date, 'Dy DD-Mon-YYYY HH24:MI:SS')  FROM DBA_SCHEDULER_JOB_LOG where log_date>=sysdate-1 and owner in('XXX','XXX') and status!='SUCCEEDED';

Comments

Popular posts from this blog

QUERY DATAGUARD AND STANDBY STATUS

Blocking session on RAC database

Finding object size in Oracle database