Friday, April 5, 2019

Check long running queries on oracle 18c or 12.2 database

Question : How to check  long running queries on oracle 18c or 12.2 database

Query : Use below query to get long running quires on databases.

set lines 300
set pages 300
col session# for a15
col sql_text for a40
col spid for a7
col sid for 999999
col username format a15
col machine format a20
col Elapsed for 9999,9999
select substr(machine,instr(machine,'\')+1) machine,s.last_call_et as Elapsed,s.username,t.SQL_ID,t.sql_text,s.sid,s.serial#,s.inst_id from gv$session s, gv$sqlarea t, gv$process p
where (s.username is not null )
and s.status='ACTIVE' 
and s.sql_address = t.address
and s.sql_address = t.address
and s.sql_hash_value = t.hash_value
and s.inst_id = t.inst_id
and p.addr=s.paddr
and p.inst_id = s.inst_id
and s.last_call_et>1
order by s.last_call_et
/

Output:

MACHINE                 ELAPSED USERNAME        SQL_ID                                  SQL_TEXT                                     SID    SERIAL#    INST_ID
-------------------- ---------- --------------- --------------------------------------- ---------------------------------------- ------- ---------- ----------
VM-ABC                   3 SCHEMA      73qrr5x5162nm                                select COUNT(ABC_ID), CUSTOMER,    4060      41920          1
                                                                                        PRODUCTION_OWNER,PRODUCTION_STATUS,DAYS_


No comments:

Post a Comment

How can I restore Cassandra snapshots?