Saturday, September 24, 2016

Script to find BROKEN JOBS

Broken Jobs
--------------

SQL> select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,FAILURES,WHAT from dba_jobs where BROKEN='Y';

       JOB LOG_USER   PRIV_USER  SCHEMA_USE   FAILURES WHAT
---------- ---------- ---------- ---------- ---------- ----------------------------------------
        55 SYS        SYS        SYS                16    DAILY_PRODUCT_MOVEMENT_LOAD(50000);



col what for a45
set linesize 200
select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,FAILURES,WHAT from dba_jobs where BROKEN='Y';

       JOB LOG_USER        PRIV_USER       SCHEMA_USER       FAILURES WHAT
---------- --------------- --------------- --------------- ---------- --------------------
        26 SECADMIN        SECADMIN        SECADMIN                16 CLEAN_AUDIT;



Mark a job as not broken

If a job fails to successfully execute it will go into a broken state after 16 attempts. To reset, issue command:

EXEC dbms_ijob.broken(jobno, FALSE);----  to kill other users jobs as well
EXEC dbms_job.broken(jobno, FALSE);----  to kill only the users in which you gets connected









Script to check the blocking session



select    'SID ' || l1.sid ||' is blocking  ' || l2.sid blocking
from      v$lock l1, v$lock l2
where   l1.block =1 and l2.request > 0
and        l1.id1=l2.id1
and        l1.id2=l2.id2
/


Scripts to check the ASM disk and Diskgroup space details


select name,total_mb/1024,free_mb/1024 from v$asm_disk;

select name,total_mb/1024,free_mb/1024 from v$asm_diskgroup;

SELECT name, free_mb, total_mb, free_mb/total_mb*100 as Free   FROM v$asm_diskgroup;

select DISK_NUMBER,NAME,PATH,FAILGROUP,TOTAL_MB,FREE_MB from v$asm_disk;




Script to check the ASM Disks and Diskgroup SIZE details(Total / Free ) & status of the disks and location

 set pagesize 250 linesize 250 lines 250
  SET ECHO        OFF
 SET FEEDBACK    6
  SET HEADING     ON
 SET LINESIZE    180
 SET PAGESIZE    50000
SET TERMOUT     ON
SET TIMING      OFF
  SET TRIMOUT     ON
  SET TRIMSPOOL   ON
  SET VERIFY      OFF
  CLEAR COLUMNS
 columns cleared
  CLEAR BREAKS
 breaks cleared
  CLEAR COMPUTES
 computes cleared

  COLUMN disk_group_name        FORMAT a25           HEAD 'Disk Group Name'
   COLUMN disk_file_path         FORMAT a20           HEAD 'Path'
   COLUMN disk_file_name         FORMAT a20           HEAD 'File Name'
   COLUMN disk_file_fail_group   FORMAT a20           HEAD 'Fail Group'
   COLUMN total_mb               FORMAT 999,999,999   HEAD 'File Size (MB)'
   COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'
   COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'
 
  BREAK ON report ON disk_group_name SKIP 1
 COMPUTE sum LABEL ""              OF total_mb used_mb ON disk_group_name
 COMPUTE sum LABEL "Grand Total: " OF total_mb used_mb ON report

  SELECT  NVL(a.name, '[CANDIDATE]')    disk_group_name
    , b.path   disk_file_path
    , b.name    disk_file_name
    , b.failgroup   disk_file_fail_group
   , b.total_mb  total_mb,
  (b.total_mb - b.free_mb)   used_mb
  FROM
   v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
  ORDER BY
    b.failgroup   ;



ARCHIVE genataion script

SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300
SET VERIFY OFF

COL "Generation Date" FORMAT a20

SELECT TRUNC(completion_time)  "Generation Date" ,
   round(SUM(blocks*block_size)/1048576,0) "Total for the Day in MB"
FROM gv$archived_log
GROUP BY TRUNC(completion_time)
ORDER BY TRUNC(completion_time)
/




Script to check the ARCHIVES genearation HOURLY / DAILY

HOURLY
~~~~~~~~~~~~~~~~~~~~~~~~

set pages 1000
select trunc(COMPLETION_TIME,'HH') Hour,thread# , round(sum(BLOCKS*BLOCK_SIZE)/1048576) MB,count(*) Archives from v$archived_log
group by trunc(COMPLETION_TIME,'HH'),thread#  order by 1 ;



Daily
~~~~~~~~~~~~~~~~~~~~~~~~~
set pages 1000
select trunc(COMPLETION_TIME,'DD') Day, thread#, round(sum(BLOCKS*BLOCK_SIZE)/1048576) MB,count(*) Archives_Generated from v$archived_log
group by trunc(COMPLETION_TIME,'DD'),thread# order by 1;


1week hourly basis switch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT to_date(first_time) DAY,
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') "00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') "01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') "02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') "03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') "04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') "05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') "06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') "07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') "08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') "09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') "10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') "11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') "12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') "13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') "14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') "15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') "16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') "17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') "18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') "19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') "20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') "21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') "22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') "23"
from
v$log_history
where to_date(first_time) > sysdate -8
GROUP by
to_char(first_time,'YYYY-MON-DD'), to_date(first_time)
order by to_date(first_time)
/


Archive backup and DELETE scripts

Script to delete archives, which are backed up tape

rman target /
DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE' BACKED UP 1 TIMES TO DEVICE TYPE 'SBT';

crosscheck archivelog all;

delete archivelog all backed up 1 times to device type sbt completed before 'sysdate-2/24';

delete archivelog all backed up 1 times to device type sbt;






Backup Archive scripts to tape and tape


run {
allocate channel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup
filesperset 100
format '%t_%s_%r.arc'
archivelog all delete input skip inaccessible;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}



Backup Archive scripts to tape and disk

run {
allocate channel t1 type 'disk';
allocate channel t2 type 'disk';
allocate channel t3 type 'disk';
allocate channel t4 type 'disk';
backup
filesperset 100
format '%t_%s_%r.arc'
archivelog all delete input skip inaccessible;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}

Add a disk to existing Diskgroup in ASM and some DISKGROUP scripts


sqlplus / as sysasm

alter diskgroup DATA add disk '/dev/ora_Data13','/dev/ora_Data14','/dev/ora_Data15','/dev/ora_Data16' rebalance power 9 ;


 Diskgroup altered.
 

Beow query is to check the disk addtion process


   select * from V$asm_operation ;
 
 GROUP_NUMBER OPERA STAT      POWER     ACTUAL      SOFAR   EST_WORK   EST_RATE EST_MINUTES
 
 ------------ ----- ---- ---------- ---------- ---------- ---------- ---------- -----------
 
            1 REBAL RUN           9          9       3079     299726      10511          28


ALTER DISKGROUP disk_group_1 ADD DISK  '/devices/disk*3',  '/devices/disk*4';


DROP diskgroup

ALTER DISKGROUP disk_group_1 DROP DISK diska2;

-- Resize a specific disk.
ALTER DISKGROUP disk_group_1  RESIZE DISK diska1 SIZE 100G;



-- Resize all disks in a failure group.
ALTER DISKGROUP disk_group_1  RESIZE DISKS IN FAILGROUP failure_group_1 SIZE 100G;



-- Resize all disks in a disk group.
ALTER DISKGROUP disk_group_1  RESIZE ALL SIZE 100G;





-- Create a directory.
ALTER DISKGROUP disk_group_1 ADD DIRECTORY '+disk_group_1/my_dir';

-- Rename a directory.
ALTER DISKGROUP disk_group_1 RENAME DIRECTORY '+disk_group_1/my_dir' TO '+disk_group_1/my_dir_2';

-- Delete a directory and all its contents.
ALTER DISKGROUP disk_group_1 DROP DIRECTORY '+disk_group_1/my_dir_2' FORCE;

-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';

-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';

-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';





CREATE TABLESPACE my_ts DATAFILE '+disk_group_1' SIZE 100M AUTOEXTEND ON;




scripts to add database and resize database and autoextend on in ASM




alter tablespace USERS add datafile '+DATA' size 3G ;


alter tablespace DATA  add datafile '+DATA' size 30G autoextend on  maxsize 50G;



ALTER DATABASE DATAFILE '+DATA/pr599/datafile/jet_data_03.366.862104147' resize 50G;



ALTER DATABASE DATAFILE '+DATA/pr599/datafile/jet_data_03.366.862104147' AUTOEXTEND ON maxsize 50G;



alter tablespace MGMT_TABLESPACE add datafile '+DATA' size 5G;

alter database datafile  '+DATA/pr746/datafile/users.257.861050819' autoextend on  maxsize 5G;


Above scripts is for ASM,

We can use the same for NON-ASM also, but while adding database we need to mention full datafile path and name



alter tablespace MGMT_TABLESPACE add datafile '/u01/test/test1.dbf' size 5G;


















Script to find active sql for specific users

SELECT a.username, b.sql_text,a.status from v$session a INNER JOIN v$sqlarea b ON a.sql_id = b.sql_id where a.username in ('USERNAME')  and a.status='ACTIVE';





Scripts for finding session details

SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time
FROM V$Session
WHERE
Status='ACTIVE' AND
UserName IS NOT NULL;


SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time FROM V$Session WHERE Status='INACTIVE' AND UserName IS NOT NULL;



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, v$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 a60
COL MODULE FOR A30
prompt TOTAL SESSIONS
col INACTIVE_PROGRAMS FOR A40
select s.module,count(s.module) Total_Inactive_Sessions
from gv$session s,v$process p
where     p.addr=s.paddr  AND
s.status='INACTIVE'
group by s.module;




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  --ANY--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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  --ANY--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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;




TOTAL FORM SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT COUNT(S.SID) INACTIVE_FORM_SESSIONS FROM V$SESSION S
WHERE S.STATUS='INACTIVE' and
s.action like ('%FRM%');




FORMS SESSIONS DETAILS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col "Last SQL" for a30
select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,
s.sid,t.disk_reads, t.elapsed_time,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.action like ('FRM%') and
s.last_call_et > 3600
order by spid;                    


col machine for a15
col "Last SQL" for a30
select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,
S.ACTION,s.process Client_Process,s.machine
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.action like ('FRM%') and
s.last_call_et > 3600;       
order by 4;                         




INACTIVE FORMS SESSIONS DETAILS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a15
col last_call_et for 999.99
select p.spid, s.sid, s.process,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.action like 'FRM:%'
and s.last_call_et > 3600
order by last_call_et desc;



UNIQUE SPID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select unique(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.action like 'FRM:%'
and s.last_call_et > 3600;




COUNT FORMS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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.action like 'FRM:%'
and s.last_call_et > 3600;



ZERO HASH VALUE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select COUNT(p.spid)
from gv$session s,gv$process p
where
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600
AND S.SQL_HASH_VALUE=0;




INACTIVE FORM BY NAME
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.sid) from v$session S
where s.action like ('%&ACTION%')
AND S.STATUS='INACTIVE';



GROUP BY ACTION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT S.ACTION,COUNT(S.SID) FROM V$SESSION S
WHERE S.STATUS='INACTIVE' and
s.action like ('%FRM%')
group by s.action;



FROM A SPECIFIC USERNAME
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SET LINSIZE 152
col spid for a10
col process_spid for a10
col user_name for a20
col form_name for a20
select a.pid,a.spid,a.process_spid, c.user_name,to_char(a.start_time,'DD-MON-YYYY HH24:MI:SS') "START_TIME" ,
d.user_form_name "FORM_NAME"
from apps.fnd_logins a, apps.fnd_login_resp_forms b, apps.fnd_user c,
apps.fnd_form_tl d
where
a.login_id=b.login_id
and c.user_name like 'JROMO'
and a.user_id=c.user_id
and trunc(b.start_time) >trunc(sysdate -11)
and trunc(b.end_time) is null
and b.form_id=d.form_id
and d.language='US';



INACTIVE FORM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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 a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,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.action like ('FRM%')
and s.last_call_et > (3600*3)
order by last_call_et;





INACTIVE FORM SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col cli_proc for a9
COL AUDSID FOR A6
COL PID FOR A6
COL SID FOR A5
COL FORM_NAME FOR A25
COL USER_NAME FOR A15
col last_call_et for 9999.99
SELECT
-- /*+ ORDERED FULL(fl) FULL(vp) USE_HASH(fl vp) */
( SELECT SUBSTR ( fu.user_name, 1, 20 )
FROM apps.fnd_user fu
WHERE fu.user_id = fl.user_id
) user_name,vs.status,
TO_CHAR ( fl.start_time, 'DD-MON-YYYY HH24:MI' ) login_start_time,
TO_CHAR ( fl.end_time, 'DD-MON-YYYY HH24:MI' ) login_end_time,
vs.last_call_et/3600 last_call_et,
SUBSTR ( fl.process_spid, 1, 6 ) spid,
SUBSTR ( vs.process, 1, 8 ) cli_proc,
SUBSTR ( TO_CHAR ( vs.sid ), 1, 3 ) sid,
SUBSTR ( TO_CHAR ( vs.serial#), 1, 7 ) serial#,
SUBSTR ( TO_CHAR ( rf.audsid ), 1, 6 ) audsid,
SUBSTR ( TO_CHAR ( fl.pid ), 1, 3 ) pid,
SUBSTR ( vs.module || ' - ' ||
( SELECT SUBSTR ( ft.user_form_name, 1, 40 )
FROM apps.fnd_form_tl ft
WHERE ft.application_id = rf.form_appl_id
AND ft.form_id        = rf.form_id
AND ft.language       = USERENV('LANG')
), 1, 40 ) form_name
FROM apps.fnd_logins           fl,
gv$process            vp,
apps.fnd_login_resp_forms rf,
gv$session            vs
WHERE fl.start_time   > sysdate - 7 /* login within last 7 days */
AND fl.login_type   = 'FORM'
AND fl.process_spid = vp.spid
AND fl.pid          = vp.pid
AND fl.login_id     = rf.login_id
AND rf.end_time    IS NULL
AND rf.audsid       = vs.audsid
and vs.status='INACTIVE'
ORDER BY
vs.process,
fl.process_spid;



ACTIVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt ACTIVE SESSIONS
select count(s.status) ACTIVE
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='ACTIVE';



MODULE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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 a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,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.MODULE like ('&MODULE_NAME_1HR%')
and s.last_call_et > ('&TIME_HRS' * 3600)
order by last_call_et;

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
p.addr=s.paddr
and s.MODULE like ('%TOAD%')
Order by last_call_et;



TOAD SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program
from gv$session s, gv$process p
where
p.addr=s.paddr
and s.MODULE like ('%TOAD%')
Order by last_call_et;




CLIENT MACHINE SESSIONS COUNT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.process) TOTAL from v$session S
where s.machine like ('%&CLIENT_MACHINE%');

select count(s.process) INACTIVE from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
and s.status='INACTIVE';



hash value=0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.process) from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
AND S.SQL_HASH_VALUE=0;

select count(s.process) from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
AND S.SQL_HASH_VALUE=0
AND S.LAST_CALL_ET > 3600;




Unique Actions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col module for a40           
prompt INACTIVE SESSIONS
col INACTIVE_PROGRAMS FOR A40
select distinct (s.program) INACTIVE_PROGRAMS,s.module
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
s.machine like ('%&CLIENT_MACHINE%') AND
p.addr=s.paddr and
s.status='INACTIVE';




GROUP BY  program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a60
prompt TOTAL SESSIONS
col INACTIVE_PROGRAMS FOR A40
select s.program,count(s.program) Total_Inactive_Sessions
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.machine like ('%&CLIENT_MACHINE%') AND
s.status='INACTIVE'
group by s.program;