Anda di halaman 1dari 9

cat sid.

sql

set verify off


col sid format 99999
col machine format a10
col program format a25 trunc
col username format a10
col logontime format a15
col osuser format a10 trunc
col proginfo format a50 trunc
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time,'mm/dd hh24:mi:ss') logontime,
s.sid,s.status,s.type,s.username,s.osuser,s.machine,
s.module || ' - ' || s.program proginfo,
s.process,p.spid, s.sql_hash_value, s.sql_id sql_id
from v$session s, v$process p
where sid = &trgtsid
and p.addr = s.paddr;

===================================================================

cat cmrun.sql

set lines 132


col os form A7 head AppProc
col spid form a6 head DBProc
col program form A43 trunc
set pages 38
col time form 9999.99 head Elapsed
col "Req Id" form 999999999
col "Parent" form a7
col "Prg Id" form 999999
col qname head "Concurrent Manager Queue" format a25 trunc
col sid format 99999 head SID
set recsep off
select q.concurrent_queue_name || ' - ' || target_node qname
,a.request_id "Req Id"
,decode(a.parent_request_id,-1,NULL,a.parent_request_id) "Parent"
,a.concurrent_program_id "Prg Id"
,a.phase_code,a.status_code
,b.os_process_id "OS"
,vs.sid
,vp.spid
,(nvl(actual_completion_date,sysdate)-actual_start_date)*1440 "Time"
,c.concurrent_program_name||' - '||
c2.user_concurrent_program_name "program"
from APPLSYS.fnd_Concurrent_requests a,APPLSYS.fnd_concurrent_processes b
,applsys.fnd_concurrent_queues q
,APPLSYS.fnd_concurrent_programs_tl c2
,APPLSYS.fnd_concurrent_programs c
,v$session vs
,v$process vp
where a.controlling_manager = b.concurrent_process_id
and a.concurrent_program_id = c.concurrent_program_id
and a.program_application_id = c.application_id
and c2.concurrent_program_id = c.concurrent_program_id
and a.phase_code in ('I','P','R','T')
and b.queue_application_id = q.application_id
and b.concurrent_queue_id = q.concurrent_queue_id
and c2.language = 'US'
and vs.process (+) = b.os_process_id
and vs.paddr = vp.addr (+)
order by 1,2
/

===================================================================

cat lock_waits.sql

set serveroutput on size 100000


declare
cursor c1 is
select * from v$lock where request != 0
order by id1, id2;
wid1 number := -999999;
wid2 number := -999999;
wholder_detail varchar2(200);
v_err_msg varchar2(80);
wsid number(5);
wstep number(2);
wtype varchar2(10);
wobject_name varchar2(180);
wobject_name1 varchar2(80);
wlock_type varchar2(50);
w_lastcallet varchar2(11);
h_lastcallet varchar2(11);
begin
for c1_rec in c1 loop
if c1_rec.id1 = wid1 and c1_rec.id2 = wid2 then
null;
else
wstep := 10;
select sid , type into wsid , wtype
from v$lock
where id1 = c1_rec.id1
and id2 = c1_rec.id2
and request = 0
and lmode != 4;
dbms_output.put_line(' ');
wstep := 20;
select 'Holder DBU: '||s.username ||' OSU: '||s.osuser ||' DBP:'||p.spid||'
APP: '|| s.process ||
' SID:' || s.sid || ' Status: ' || s.status ||
' (' || floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) ||
') Module:'|| module ||
' AppSrvr: ' || substr(replace(machine,'GEIPS-AMER\',null),1,15)
into wholder_detail
from v$session s, v$process p
where s.sid= wsid
and s.paddr = p.addr;
dbms_output.put_line(wholder_detail);

begin
select decode(wtype,'TX', 'Transaction',
'DL', 'DDL Lock',
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distributed Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalida-tion',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
'Un-Known Type of Lock')
into wlock_type
from dual;
declare
cursor c3 is
select object_id from v$locked_object
where session_id = wsid;
begin
wobject_name := '';
for c3_rec in c3 loop
select object_type||': '||owner||'.'||object_name
into wobject_name
from dba_objects
where object_id = c3_rec.object_id;
wobject_name := wobject_name ||' '||wobject_name1;
end loop;
exception
when others then
wobject_name := wobject_name ||' No Object Found';
end;
dbms_output.put_line('Lock Held: '||wlock_type||' for Object :'||
wobject_name);
exception
when no_data_found then
dbms_output.put_line('Lock Held: '||wlock_type||' No object found in DBA
Objects');
end;
end if;
wstep := 30;
select '.... Requestor DBU: '||s.username ||' OSU: '||s.osuser ||' DBP:'||
p.spid||' APP: '|| s.process ||
' SID:' || s.sid || ' Status: ' || s.status ||
' (' || floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) ||
') Module:'|| module ||
' AppSrvr: ' || substr(replace(machine,'GEIPS-AMER\',null),1,15)
into wholder_detail
from v$session s, v$process p
where s.sid= c1_rec.sid
and s.paddr = p.addr;
dbms_output.put_line(wholder_detail);
wid1 := c1_rec.id1;
wid2 := c1_rec.id2;
end loop;
if wid1 = -999999 then
wstep := 40;
dbms_output.put_line('No one requesting locks held by others');
end if;
exception
when others then
v_err_msg := (sqlerrm ||' '|| sqlcode||' step='||to_char(wstep));
DBMS_OUTPUT.PUT_LINE(v_err_msg);
end;
/

===================================================================

cat osproc.sql

/* osproc.sql
find the Oracle session info for a given OS process id
*/
col machine format a15 trunc
col program format a25 trunc
col LastCallET format a11
col status format a1 trunc
col module format a12 trunc
set verify off
accept trgtproc char default 0 prompt 'What is the OS process id : '
select s.sid,s.status,
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) "LastCallET",
s.machine,s.module,s.process,s.sql_hash_value
from v$session s, v$process p
where s.paddr = p.addr
and p.spid = '&trgtproc';

===================================================================

cat kgl.sql

alter session set optimizer_mode = rule;


col holder_module format a20 trunc
col locked_object format a30 trunc
col holder_srvr format a15 trunc
col ktype format a6 trunc
col holder format 99999
col requestor format 99999
col holder_wait format a35 trunc
select s.sid holder,
decode(x.kgllkmod,2,'S',3,'X',1,'N') "mode" ,
x.KGLLKTYPE ktype ,
w.sid requestor,
decode(w.reqmode,2,'S',3,'X',1,'N') "req" ,
w.wtype,
o.KGLNAOWN||'.'||o.KGLNAOBJ locked_object ,
o.KGLOBTYP ,
s.sql_hash_value holder_sql,
s.module holder_module,
s.machine holder_srvr,
hw.event || ' - ' || hw.wait_time holder_wait
from dba_kgllock x, x$kglob o, v$session s, v$session_wait hw,
(select sid, p1raw, trunc(p3/10) reqmode
,decode(substr(event,15),'pin','Pin','lock','Lock') wtype
from v$session_Wait
where event like 'library cache %' ) w
where x.kgllkHDL = w.p1raw
and x.kgllkMOD > 0
and x.kgllkuse = s.saddr
and x.kgllkHDL = o.kglhdadr
and x.KGLLKTYPE = wtype
and s.sid = hw.sid
order by 7,3,5;

======================================================================

cat hashsql.sql

set verify off


accept trgthash number default 0 prompt 'What is the SQL Hash Value : '
set linesize 500
select t.sql_text
from v$sqltext_with_newlines t
where t.hash_value + 0 = &trgthash
and &trgthash != 0
order by t.piece;

======================================================================

cat sql_plan.sql

set pagesize 600


set tab off
set linesize 160
set echo off
set long 4000
col TQID format A4
col "SLAVE SQL" format A95 WORD_WRAP
col address format A12
col sql_hash format A15
col exec format 9999
col sql_text format A75 WORD_WRAP
repfooter off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
#alter session set "_complex_view_merging"=false;
select hash_value||decode(child_number, 0, '', '/'||child_number) sql_hash,
sql_text
from v$sql
where child_number= 0 and hash_value= &hashvalue;

select '| Operation | Name | Starts | E-Rows | A-Rows | Buffers | Reads | Writes |
E-Time |' as "Plan Table" from dual
union all /* QWEKLOIPYRTJHH7 */
select
'----------------------------------------------------------------------------------
--------------------------------------'
from dual
union all
select rpad('| '||substr(lpad(' ',1*(depth))||operation|| decode(options, null,'','
'||options), 1, 33), 34, ' ')||'|'||
rpad(substr(object_name||' ',1, 19), 20, ' ')||'|'||
lpad(decode(starts,null,' ',
decode(sign(starts-1000), -1, starts||' ',
decode(sign(starts-1000000), -1, round(starts/1000)||'K',
decode(sign(starts-1000000000), -1,
round(starts/1000000)||'M',
round(starts/1000000000)||'G')))), 8, '
') || '|' ||
lpad(decode(cardinality,null,' ',
decode(sign(cardinality-1000), -1, cardinality||' ',
decode(sign(cardinality-1000000), -1,
round(cardinality/1000)||'K',
decode(sign(cardinality-1000000000), -1,
round(cardinality/1000000)||'M',
round(cardinality/1000000000)||'G')))),
8, ' ') || '|' ||
lpad(decode(outrows,null,' ',
decode(sign(outrows-1000), -1, outrows||' ',
decode(sign(outrows-1000000), -1,
round(outrows/1000)||'K',
decode(sign(outrows-1000000000), -1,
round(outrows/1000000)||'M',
round(outrows/1000000000)||'G')))), 8,
' ') || '|' ||
lpad(decode(crgets,null,' ',
decode(sign(crgets-10000000), -1, crgets||' ',
decode(sign(crgets-1000000000), -1,
round(crgets/1000000)||'M',
round(crgets/1000000000)||'G'))), 9, '
') || '|' ||
lpad(decode(reads,null,' ',
decode(sign(reads-10000000), -1, reads||' ',
decode(sign(reads-1000000000), -1,
round(reads/1000000)||'M',
round(reads/1000000000)||'G'))), 8, '
') || '|' ||
lpad(decode(writes,null,' ',
decode(sign(writes-10000000), -1, writes||' ',
decode(sign(writes-1000000000), -1,
round(writes/1000000)||'M',
round(writes/1000000000)||'G'))), 8, '
') || '|' ||
cost||
lpad(decode(etime,null,' ',
decode(sign(etime-10000000), -1, etime||' ',
decode(sign(etime-1000000000), -1,
round(etime/1000000)||'M',
round(etime/1000000000)||'G'))), 8, '
') || '|' as "Explain plan"
from
(select /*+ no_merge */
p.HASH_VALUE, p.ID, p.DEPTH, p.POSITION, p.OPERATION,
p.OPTIONS, p.COST COST, p.CARDINALITY CARDINALITY,
p.BYTES BYTES, p.OBJECT_NODE, p.OBJECT_OWNER,
p.OBJECT_NAME, p.OTHER_TAG, p.PARTITION_START,
p.PARTITION_STOP, p.DISTRIBUTION, pa.starts,
pa.OUTPUT_ROWS outrows, pa.CR_BUFFER_GETS crgets,
pa.DISK_READS reads, pa.DISK_WRITES writes,
pa.ELAPSED_TIME etime
from v$sql_plan_statistics_all pa,
V$sql_plan p
where p.hash_value = &hashvalue
and p.CHILD_NUMBER= 0
and p.hash_value = pa.hash_value(+)
and pa.child_number(+) = 0 )
union all
select
'----------------------------------------------------------------------------------
--------------------------------------' from dual;
REM
REM Print slave sql
REM
select /* QWEKLOIPYRTJHH7 */
decode(object_node,null,'', substr(object_node,length(object_node)-3,1)
|| ',' ||
substr(object_node,length(object_node)-1,2)) TQID,
other "SLAVE SQL"
from v$sql_plan vp
where other is not NULL
and hash_value = &hash_value
and CHILD_NUMBER= 0;

===================================================================================
=====

cat longops.sql

set verify off


col opname format a40 trunc
col pctdone format 999
col mintogo format 999,999.90
accept trgtsid number default 0 prompt 'Limit to which SID : '
select s.sid,o.opname,s.sql_hash_value,o.sofar,o.totalwork,o.elapsed_seconds,
round(o.time_remaining/60,2) mintogo,
round(o.sofar/o.totalwork * 100,0) pctdone, o.message
from v$session_longops o, v$session s
where o.sid = s.sid
and sofar < totalwork
and (o.sid = &trgtsid or &trgtsid = 0)
/

===================================================================================
=======

cat top10active.sql

/* top10active.sql
shows the top 10 longest-active user sessions
*/
col osuser format a10 trunc
col LastCallET format 99,999
col sid format 9999
col username format a10 trunc
col uprogram format a55 trunc
col machine format a10 trunc
set linesize 300
set verify off
accept trgtuser char default ALL prompt 'Limit to what userid <ALL> : '
select * from (
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram,
s.machine, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.type = 'USER'
and s.username is not null
and s.status = 'ACTIVE'
and (s.username = upper('&trgtuser') or upper('&trgtuser') = 'ALL')
order by 4 desc)
where rownum < 10;

===================================================================================
=======================

-------------------------------------------------------------------------------
-- Query to find runtime for a concurrent program
-------------------------------------------------------------------------------

SELECT /*+ rule */


rq.parent_request_id "Parent Req. ID",
rq.request_id "Req. ID",
tl.user_concurrent_program_name "Program Name",
rq.actual_start_date "Start Date",
rq.actual_completion_date "Completion Date",
ROUND((rq.actual_completion_date -
rq.actual_start_date) * 1440, 2) "Runtime (in Minutes)"
FROM applsys.fnd_concurrent_programs_tl tl,
applsys.fnd_concurrent_requests rq
WHERE tl.application_id = rq.program_application_id
AND tl.concurrent_program_id = rq.concurrent_program_id
AND tl.LANGUAGE = USERENV('LANG')
AND rq.actual_start_date IS NOT NULL
AND rq.actual_completion_date IS NOT NULL
AND tl.user_concurrent_program_name = '&Program_Name'
-- AND TRUNC(rq.actual_start_date) = '&start_date';

===================================================================================
=======================

---- Cancell Scheduled Requests ----


UPDATE fnd_concurrent_requests
SET
hold_flag = 'Y',
last_update_date = sysdate
WHERE phase_code = 'P'
AND status_code in ('Q','I');

===================================================================================
=======================

Anda mungkin juga menyukai