SQL Queries to Check ACTIVE / INACTIVE Sessions

SQL Queries to Check ACTIVE / INACTIVE Sessions

Total Count of sessions

SELECT Count(s.status) TOTAL_SESSIONS
FROM   gv$session s;

 

Total Count of Inactive sessions

SELECT Count(s.status) INACTIVE_SESSIONS
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’;

 

SESSIONS WHICH ARE IN INACTIVE STATUS FROM MORE THAN 1HOUR

SELECT Count(s.status) “INACTIVE SESSIONS > 1HOUR “
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.last_call_et > 3600
AND s.status = ‘INACTIVE’;

 

COUNT OF ACTIVE SESSIONS

SELECT Count(s.status) ACTIVE_SESSIONS
FROM   gv$session s,
$process p
WHERE  p.addr = s.paddr
AND s.status = ‘ACTIVE’;

 

TOTAL SESSIONS COUNT ORDERED BY PROGRAM

col program FOR a30
SELECT s.program,
Count(s.program) Total_Sessions
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
GROUP  BY s.program;

 

TOTAL COUNT OF SESSIONS ORDERED BY MODULE

col MODULE FOR a30
prompt total sessions
SELECT s.MODULE,
Count(s.sid) Total_Sessions
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
GROUP  BY s.MODULE;

 

TOTAL COUNT OF SESSIONS ORDERED BY ACTION

col action FOR a30
prompt total sessions
SELECT s.action,
Count(s.sid) Total_Sessions
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
GROUP  BY s.action;

 

INACTIVE SESSIONS

prompt inactive sessions
SELECT p.spid,
s.sid,
s.last_call_et / 3600 last_call_et,
s.status,
s.action,
s.MODULE,
s.program
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’;

 

INACTIVE

prompt inactive sessions
SELECT Count(s.status) INACTIVE
FROM   gv$session s,
gv$sqlarea t,
v$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’;

 

INACTIVE PROGRAMS

col MODULE FOR a40
prompt inactive sessions
col inactive_programs FOR a40
SELECT DISTINCT ( s.program ) INACTIVE_PROGRAMS,
s.MODULE
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’;

 

INACTIVE PROGRAMS with disk reads

prompt inactive sessions
SELECT DISTINCT ( s.program ) INACTIVE_PROGRAMS,
SUM(T.disk_reads)
FROM   gv$session s,
gv$sqlarea t,
v$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’
GROUP  BY S.program;

 

INACTIVE SESSIONS COUNT WITH PROGRAM

col program FOR a30
prompt total inactive sessions
col inactive_programs FOR a40
SELECT s.program,
Count(s.program) Total_Inactive_Sessions
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’
GROUP  BY s.program
ORDER  BY 2 DESC;

 

TOTAL INACTIVE SESSIONS MORE THAN 1HOUR

col program FOR a30
col inactive_programs FOR a40
SELECT s.program,
Count(s.program) Inactive_Sessions_from_1Hour
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.last_call_et > ( 3600 )
GROUP  BY s.program
ORDER  BY 2 DESC;

 

TOTAL INACTIVE SESSIONS GROUP BY  MODULE

col program FOR a30
col inactive_programs FOR a40
SELECT s.program,
Count(s.program) Inactive_Sessions_from_1Hour
FROM   gv$session s,
v$process p
WHERE  p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.last_call_et > ( 3600 )
GROUP  BY s.program
ORDER  BY 2 DESC;

 

INACTIVE SESSION DETAILS MORE THAN 1 HOUR

set pagesize 40
col inst_id FOR 99
col spid FOR a10
set linesize 150
col program FOR a10
col action format a10
col logon_time format a16
col MODULE format a13
col cli_process format a7
col cli_mach FOR a15
col status format a10
col username format a10
col last_call_et_hrs FOR 9999.99
col sql_hash_value FOR 9999999999999col username FOR a10
set linesize 152
set pagesize 80
col “Last SQL” FOR a60
col elapsed_time FOR 999999999999
SELECT p.spid,
s.sid,
s.last_call_et / 3600 last_call_et_Hrs,
s.status,
s.action,
s.MODULE,
s.program,
t.disk_reads,
Lpad(t.sql_text, 30)  “Last SQL”
FROM   gv$session s,
gv$sqlarea t,
gv$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.last_call_et > ( 3600 )
ORDER  BY last_call_et;

 

INACTIVE PROGRAM 

SELECT p.spid,
s.sid,
s.last_call_et / 3600 last_call_et_Hrs,
s.status,
s.action,
s.MODULE,
s.program,
t.disk_reads,
Lpad(t.sql_text, 30)  “Last SQL”
FROM   gv$session s,
gv$sqlarea t,
gv$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.program = ‘&PROGRAM_NAME’
ORDER  BY last_call_et;

 

INACTIVE MODULES 

SELECT p.spid,
s.sid,
s.last_call_et / 3600 last_call_et_Hrs,
s.status,
s.action,
s.MODULE,
s.program,
t.disk_reads,
Lpad(t.sql_text, 30)  “Last SQL”
FROM   gv$session s,
gv$sqlarea t,
gv$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.MODULE LIKE ‘%order_cleanup_hazmat_v3.sql’
ORDER  BY last_call_et;

 

INACTIVE JDBC SESSIONS

set pagesize 40
col inst_id FOR 99
col spid FOR a10
set linesize 150
col program FOR a10
col action format a10
col logon_time format a16
col MODULE format a13
col cli_process format a7
col cli_mach FOR a15
col status format a10
col username format a10
col last_call_et FOR 9999.99
col sql_hash_value FOR 9999999999999col username FOR a10
set linesize 152
set pagesize 80
col “Last SQL” FOR a60
col elapsed_time FOR 999999999999
SELECT p.spid,
s.sid,
s.last_call_et / 3600 last_call_et,
s.status,
s.action,
s.MODULE,
s.program,
t.disk_reads,
Lpad(t.sql_text, 30)  “Last SQL”
FROM   gv$session s,
gv$sqlarea t,
gv$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.program = ‘JDBC Thin Client’
AND s.last_call_et > 3600
ORDER  BY last_call_et;

 

COUNT OF INACTIVE SESSIONS MORE THAN ONE HOUR

SELECT Count(P.spid)
FROM   gv$session s,
gv$sqlarea t,
gv$process p
WHERE  s.sql_address = t.address
AND s.sql_hash_value = t.hash_value
AND p.addr = s.paddr
AND s.status = ‘INACTIVE’
AND s.program = ‘JDBC Thin Client’
AND s.last_call_et > 3600
ORDER  BY last_call_et;

 

 

 

About Syed Saad

With 13 years of experience as a certified and skilled Oracle Database Administrator, I possess the expertise to handle various levels of database maintenance tasks and proficiently perform Oracle updates. Throughout my career, I have honed my analytical abilities, enabling me to swiftly diagnose and resolve issues as they arise. I excel in planning and executing special projects within time-sensitive environments, showcasing exceptional organizational and time management skills. My extensive knowledge encompasses directing, coordinating, and exercising authoritative control over all aspects of planning, organization, and successful project completions. Additionally, I have a strong aptitude for resolving customer relations matters by prioritizing understanding and effective communication. I am adept at interacting with customers, vendors, and management, ensuring seamless communication and fostering positive relationships.

Check Also

How to Get Apps Password From Backend

How to Get Apps Password From Backend   STEP 1.  First login to Database through …

Leave a Reply