0% found this document useful (0 votes)
100 views20 pages

SQL Collection

sql collection
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views20 pages

SQL Collection

sql collection
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 20

SELECT username U_NAME, owner OBJ_OWNER,

object_name, object_type, s.osuser,s.sid,


DECODE(l.block,
0, 'Not Blocking',
1, 'Blocking',
2, 'Global') STATUS,
DECODE(v.locked_mode,
0, 'None',
1, 'Null',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share',
5, 'S/Row-X (SSX)',
6, 'Exclusive', TO_CHAR(lmode)
) MODE_HELD
FROM gv$locked_object v, dba_objects d,
gv$lock l, gv$session s
WHERE v.object_id = d.object_id
AND (v.object_id = l.id1)
AND v.session_id = s.sid
ORDER BY username, session_id;

select
p.user_concurrent_program_name Program_name,
to_char(r.actual_start_date,'DD-MON-YYYY HH24') Date_of_exec,
count(r.request_id) Executions,
avg((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Avg_run_time,
min((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Min_run_time,
max((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Max_run_time
from
apps.fnd_concurrent_requests r,
apps.fnd_concurrent_processes c,
apps.fnd_concurrent_queues q,
apps.fnd_concurrent_programs_vl p
where
p.concurrent_program_id = r.concurrent_program_id
and p.application_id = r.program_application_id
and c.concurrent_process_id = r.controlling_manager
and q.concurrent_queue_id = c.concurrent_queue_id
-- and p.application_id = '&appl_id'
and r.status_code = 'C'
and r.phase_code = 'C'
and to_char(r.actual_start_date,'DD-MON-YYYY')> sysdate -1
group by p.user_concurrent_program_name,to_char(r.actual_start_date,'DD-MON-YYYY
HH24')
order by to_char(r.actual_start_date,'DD-MON-YYYY HH24') asc;

SELECT
i.instance_name instance_name
, l.session_id || ' / ' || s.serial# sid_serial
, s.status session_status
, l.oracle_username locking_oracle_user
, o.owner object_owner
, o.object_name object_name
, o.object_type object_type
, DECODE ( l.locked_mode
, 0,
'None' /* Mon Lock equivalent */
, 1,
'NoLock' /* N */
, 2,
'Row-Share (SS)' /* L */
, 3,
'Row-Exclusive (SX)' /* R */
, 4,
'Share-Table' /* S */
, 5,
'Share-Row-Exclusive (SSX)' /* C */
, 6,
'Exclusive' /* X */
, '[Nothing]'
) locked_mode
, s.client_identifier,s.program,action,module
FROM
dba_objects o
, gv$session s
, gv$locked_object l
, gv$instance i
WHERE
i.inst_id = l.inst_id
AND s.inst_id = l.inst_id
AND s.sid = l.session_id
AND o.object_id = l.object_id
ORDER BY
i.instance_name
, l.session_id;

SELECT SUBSTR(DECODE(request,0,'Holder: ','Waiter: ')


||sid,1,12) sess,
id1,
id2,
lmode,
request,
type
FROM gV$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM gV$LOCK WHERE request>0
)
ORDER BY id1;

select * from gv$session where sid=2979;

select * from gv$lock;

select * from gv$session;

select s1.sid as blocker_sid,


s1.username || '@' || s1.machine as blocker_user,
s2.sid || ':' || s2.username || '@' || s2.machine as blocked
from gv$lock l1, gv$session s1, gv$lock l2, gv$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.block=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2;
-- group by s1.sid, s1.username, s1.machine;

select sid as blocker_sid, wm_concat(sql_text) as blocker_sql


from (select s.sid, txt.sql_text
from gv$sqltext txt, gv$session s, gv$lock l
where txt.address = s.sql_address
and s.sid = l.sid
and l.block = 1
order by s.sid, txt.piece)
group by sid order by sid;

To find a tablespace freespace size:


select a.tablespace_name "Tablespace",
a.avail,
a.avail-b.free used,
b.free,
round(nvl((a.avail-b.free)/a.avail*100,0)) "Pct"
from
(select tablespace_name, round(sum(bytes)/1048576) avail
from sys.dba_data_files
group by tablespace_name
UNION
select tablespace_name,round(sum(bytes_free+bytes_used)/1048576)
from v$temp_space_header
group by tablespace_name) a,
(select tablespace_name, round(sum(bytes)/1048576) free
from sys.dba_free_space
group by tablespace_name
UNION
select tablespace_name,round(sum(bytes_free)/1048576)
from v$temp_space_header
group by tablespace_name) b
where a.TABLESPACE_NAME = B.TABLESPACE_NAME (+)
order by 5;

select * from (SELECT (undoblks*8192)/1024/1024/1024,snap_id,


maxquerylen,
maxquerysqlid,
TO_CHAR(begin_time,'yyyy/mm/dd hh24:mi') BEGIN,
TO_CHAR(end_time,'yyyy/mm/dd hh24:mi')
END
FROM dba_hist_undostat-- where trunc(begin_time) > sysdate -30-- and rownum
<=10
order by undoblks desc) where rownum <=20;

Database Growth:

SELECT
TO_CHAR(creation_time, 'RRRR-MM-DD') "Month",
SUM(bytes/1024/1024) "growth in MB",TS#
FROM sys.v_$datafile where ts# in (1,22)
GROUP BY TO_CHAR(creation_time, 'RRRR-MM-DD'),ts#
order by to_char(creation_time, 'RRRR-MM-DD');

select sql_text from v$sqlarea where sql_id in (select


/**spid,s.program,osuser,machine,**/sql_id
from v$session s ,v$process p where s.sid=888 and s.paddr=p.addr);

Wofkflow related:

select *
from APPLSYS.AQ$WF_NOTIFICATION_OUT
where CORR_ID like 'APPS:ALR%' and msg_state in ('READY','WAIT');
select * from wf_notification_out where CORRID like 'APPS:ALR%' and state<>2;

select * from wf_notifications where recipient_role like 'RATHINA%' order by


begin_date desc;

select decode(wno.state,
0, '0 = Pending in mailer queue',
1, '1 = Pending in mailer queue',
2, '2 = Sent by mailer on '||to_char(DEQ_TIME),
3, '3 = Exception', 4,'4 = Wait', to_char(state)) State,
to_char(DEQ_TIME),
wno.user_data.TEXT_VC
from wf_notification_out wno
where corrid like 'APPS:ALR%'
order by 2 desc;
and **/ upper(wno.user_data.TEXT_VC) like '%15762%';;

select * from apps.wf_notification_out


where trunc(ENQ_TIME) = trunc(sysdate)-1 and corrid like '%ALR%'
order by enq_time desc ;

select * from alr_alerts order by last_update_date desc;

select decode(wno.state,
0, '0 = Pending in mailer queue',
1, '1 = Pending in mailer queue',
2, '2 = Sent by mailer on '||to_char(DEQ_TIME),
3, '3 = Exception', 4,'4 = Wait', to_char(state)) State,
to_char(DEQ_TIME),
wno.user_data.TEXT_VC
from wf_notification_out wno
where corrid like '%ALR%'
--and wno.user_data.TEXT_VC like '%Raghavan%'
order by 2 desc
;

select count(*) from apps.wf_notification_out


where trunc(ENQ_TIME) = trunc(sysdate) and corrid like '%ALR%' and state<>2
order by enq_time desc ;

SELECT COUNT(*),mail_status
FROM wf_notifications
WHERE-- mail_status ='MAIL'
--AND
TRUNC(begin_date)=TRUNC(sysdate)
--and trunc(begin_date) > sysdate -2
group by mail_status;

select * from wf_notifications


WHERE mail_status ='MAIL'
AND
TRUNC(begin_date)=TRUNC(sysdate)
order by begin_date desc;

SELECT n.notification_id,
n.recipient_role,
ln.email_address,
n.status,
n.mail_status,
n.message_type,
n.message_name,
n.begin_date,
ln.notification_preference,
de.def_enq_time,
de.def_deq_time,
de.def_state,
ou.out_enq_time,
ou.out_deq_time,
ou.out_state
FROM applsys.wf_notifications n,
(SELECT d.enq_time def_enq_time,
d.deq_time def_deq_time,
TO_NUMBER(
(SELECT VALUE
FROM TABLE(d.user_data.parameter_list)
WHERE NAME = 'NOTIFICATION_ID'
)) d_notification_id,
msg_state def_state
FROM applsys.aq$wf_deferred d
WHERE d.corr_id = 'APPS:oracle.apps.wf.notification.send'
) de,
(SELECT o.deq_time out_deq_time,
o.enq_time out_enq_time,
TO_NUMBER(
(SELECT str_value
FROM TABLE(o.user_data.header.properties)
WHERE NAME = 'NOTIFICATION_ID'
)) o_notification_id,
msg_state out_state
FROM applsys.aq$wf_notification_out o
) ou,
(SELECT *
FROM wf_local_roles
WHERE name IN
(SELECT recipient_role FROM apps.wf_notifications
)
) ln
WHERE n.notification_id =
&NOTIFICATION_ID
/** IN
(SELECT notification_id
FROM apps.wf_notifications
WHERE mail_status ='MAIL'
AND status ='OPEN'
AND TRUNC(begin_date) between '01-NOV-13' and '07-NOV-13'
)**/
AND ln.name =n.recipient_role
AND n.notification_id = de.d_notification_id(+)
AND n.notification_id = ou.o_notification_id(+)
ORDER BY n.begin_date;

select substr(wfd.corrid,1,40) corrid,


decode(wfd.state,
0, '0 = Ready',
1, '1 = Delayed',
2, '2 = Retained',
3, '3 = Exception',
to_char(substr(wfd.state,1,12))) State,
count(*) COUNT
from applsys.wf_notification_out wfd
where WFD.STATE=0
group by wfd.corrid, wfd.state;

select name, status from wf_events


where GUID in (select EVENT_FILTER_GUID from WF_EVENT_SUBSCRIPTIONS where
system_guid <> wf_core.translate('WF_SYSTEM_GUID'));
===================================================================================
select dbms_stats.get_stats_history_retention,
dbms_stats.get_stats_history_availability from dual;

select sum(bytes)/1024/1024/1024 from dba_free_space where tablespace_name like


upper('%sysaux%');

select * from ad_bugs where bug_number in (16000686,17395845,14069503,8919491);

SELECT D.PATCH_NAME,
B.APPLICATIONS_SYSTEM_NAME,
B.NAME,
c.patch_abstract,
C.DRIVER_FILE_NAME,
-- A.PATCH_DRIVER_ID,
-- A.PATCH_RUN_ID,
-- A.SESSION_ID,
a.patch_top,
to_char(a.start_date , 'DD-Mon-yyyy HH24:MI:SS') startdate ,
to_char(A.END_DATE, 'DD-Mon-yyyy HH24:MI:SS') enddate,
FLOOR(((a.end_date-a.start_date)*24*60*60)/3600)||':'||
FLOOR((((a.end_date-a.start_date)*24*60*60) -
FLOOR(((a.end_date-a.start_date)*24*60*60)/3600)*3600)/60)||':'||
round((((a.end_date-a.start_date)*24*60*60) -
FLOOR(((a.end_date-a.start_date)*24*60*60)/3600)*3600 -
(FLOOR((((a.end_date-a.start_date)*24*60*60) -
FLOOR(((a.end_date-a.start_date)*24*60*60)/3600)*3600)/60)*60) ))
"HOURS:MINUTES:SECONDS"
--A.SUCCESS_FLAG,
-- A.FAILURE_COMMENTS
FROM AD_PATCH_RUNS A,
AD_APPL_TOPS B,
AD_PATCH_DRIVERS C,
AD_APPLIED_PATCHES D
WHERE A.APPL_TOP_ID = B.APPL_TOP_ID
AND A.PATCH_DRIVER_ID = C.PATCH_DRIVER_ID
AND C.APPLIED_PATCH_ID = D.APPLIED_PATCH_ID
--and upper(b.name) in (select node_name from fnd_nodes)
--and b.name like '%tst003kkkmaaind%'
and trunc(a.start_date) > (select trunc(resetlogs_time) from v$database)
AND A.PATCH_DRIVER_ID IN
(SELECT PATCH_DRIVER_ID
FROM AD_PATCH_DRIVERS
WHERE APPLIED_PATCH_ID IN
(SELECT APPLIED_PATCH_ID
FROM AD_APPLIED_PATCHES
WHERE PATCH_NAME IN (16000686,17395845,14069503,8919491,9239089,17203944)
)
) ORDER BY 6;

Concurrent request related:

SELECT request_id,
parent_request_id,
phase_code,
status_code,
---- responsibility_application_id,
-- responsibility_id,
request_date,
actual_start_date,
actual_completion_date,
program,
requestor,
--user_concurrent_program_name,16000686
round (((actual_completion_date-actual_start_date)*24)) diff,
completion_text,argument_text
FROM fnd_conc_req_summary_v
WHERE user_concurrent_program_name LIKE 'OP3: Update Project(s)'
and round (((actual_completion_date-actual_start_date)*24)) >5
--and trunc(request_date) = trunc(sysdate)
ORDER BY 8 desc ;

select * from fnd_conc_req_summary_v where request_id=17524214;SELECT request_id,


phase_code,
status_code,
request_date,
responsibility_application_id,
responsibility_id,
parent_request_id,
actual_start_date,
actual_completion_date,
program,
requestor,
user_concurrent_program_name
FROM fnd_conc_req_summary_v
WHERE user_concurrent_program_name LIKE 'OP3: Update Project(s)'
ORDER BY requested_start_date DESC;

select * from fnd_conc_req_summary_v where request_id=17524214;

select /*+ ordered */


fcp.user_concurrent_program_name
, fcr.request_id
, round(24*60*( sysdate - actual_start_date )) elapsed
, actual_start_date,request_date
, fu.user_name
, fcr.oracle_process_id
, sess.sid
, sess.serial#
, inst.inst_name
, sa.sql_text
, sess.sql_id
--, cp.plsql_dir || '/' || cp.plsql_out outfile_tmp
--, cp.plsql_dir || '/' || cp.plsql_log logfile_tmp
from apps.fnd_concurrent_requests fcr
, apps.fnd_concurrent_programs_tl fcp
, apps.fnd_concurrent_processes cp
, apps.fnd_user fu
, gv$process pro
, gv$session sess
, gv$sqlarea sa
, sys.v_$active_instances inst
where fcp.concurrent_program_id = fcr.concurrent_program_id
and fcp.application_id = fcr.program_application_id
and fcr.controlling_manager = cp.concurrent_process_id
and fcr.requested_by = fu.user_id (+)
and fcr.oracle_process_id = pro.spid (+)
and pro.addr = sess.paddr (+)
and pro.inst_id = sess.inst_id (+)
and sess.sql_address = sa.address (+)
and sess.sql_hash_value = sa.hash_value (+)
and sess.inst_id = inst.inst_number (+)
and fcr.phase_code = 'R' /* only running requests */
order by 3;

select
r.request_id ,
--R.PHASE_CODE ,
--R.STATUS_CODE ,
--R.REQUEST_DATE ,
--R.REQUESTED_BY ,
--R.REQUESTED_START_DATE ,
-- R.PARENT_REQUEST_ID ,
--R.CONTROLLING_MANAGER ,
r.actual_start_date ,
--R.ACTUAL_COMPLETION_DATE ,
(nvl(r.actual_completion_date,sysdate)-r.actual_start_date)*1440 "Duration in
Min",
avg((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
avg_run_time,
min((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
min_run_time,
max((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
max_run_time,
pt.user_concurrent_program_name
program ,
u.user_name requestor
from fnd_concurrent_programs_tl pt,
fnd_concurrent_programs pb,
fnd_user u,
fnd_concurrent_requests r
where pb.application_id = r.program_application_id
and pb.concurrent_program_id = r.concurrent_program_id
and pb.application_id = pt.application_id
and pb.concurrent_program_id = pt.concurrent_program_id
and u.user_id = r.requested_by
and r.phase_code='R'
and r.status_code='R'
and ((sysdate - r.actual_start_date) * 24 *60) > 60
--AND (SYSDATE - R.actual_start_date) * 24 > 24
--and to_char(r.actual_start_date,'DD-MON-YYYY')> sysdate -10
group by
r.request_id,/**R.PARENT_REQUEST_ID**/r.actual_start_date,r.actual_completion_date,
pt.user_concurrent_program_name,u.user_name;
SELECT oracle_username
|| ' ('
|| s.osuser
|| ')' username ,
s.sid
|| ',
'
|| s.serial# sess_id ,
owner
|| '.'
|| object_name object ,
object_type ,
DECODE( l.block , 0, 'Not Blocking' , 1, 'Blocking' , 2, 'Global') status ,
DECODE(v.locked_mode , 0, 'None' , 1, 'Null' , 2, 'Row-S (SS)' , 3, 'Row-X
(SX)' , 4, 'Share' , 5, 'S/Row-X (SSX)' , 6, 'Exclusive', TO_CHAR(lmode)) mode_held
FROM gv$locked_object v ,
dba_objects d ,
gv$lock l ,
gv$session s
WHERE v.object_id = d.object_id
AND v.object_id = l.id1
AND v.session_id = s.sid
and l.request>0
ORDER BY oracle_username ,
session_id;

SELECT sid
, serial#
, username
, osuser
, machine
FROM gv$sessionSELECT request_id,
phase_code,
status_code,
request_date,
actual_start_date,
actual_completion_date,
(NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440 "Duration in Min",
PROGRAM,
requestor
FROM fnd_conc_req_summary_v
WHERE status_code = 'R'
AND phase_code = 'R'
AND ((SYSDATE - actual_start_date) * 24 *60) > 60;

WHERE sid IN (select sid


from gv$lock
where block != 0
and type = 'TX');

dba_blockers;

SELECT request_id,
phase_code,
status_code,
request_date,
actual_start_date,
actual_completion_date,
(NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440 "Duration in Min",
PROGRAM,
requestor
FROM fnd_conc_req_summary_v
WHERE status_code = 'R'
AND phase_code = 'R'
AND ((SYSDATE - actual_start_date) * 24 *60) > 60;
select
p.user_concurrent_program_name Program_name,
to_char(r.actual_start_date,'DD-MON-YYYY HH24') Date_of_exec,
count(r.request_id) Executions,
avg((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Avg_run_time,
min((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Min_run_time,
max((nvl(r.actual_completion_date,sysdate) - r.actual_start_date) * 24 * 60)
Max_run_time
from
apps.fnd_concurrent_requests r,
apps.fnd_concurrent_processes c,
apps.fnd_concurrent_queues q,
apps.fnd_concurrent_programs_vl p
where
p.concurrent_program_id = r.concurrent_program_id
and p.application_id = r.program_application_id
and c.concurrent_process_id = r.controlling_manager
and q.concurrent_queue_id = c.concurrent_queue_id
--and p.application_id = '&appl_id'
and r.status_code = 'R'
and r.phase_code = 'R'
and to_char(r.actual_start_date,'DD-MON-YYYY') > sysdate -1
group by p.user_concurrent_program_name,to_char(r.actual_start_date,'DD-MON-YYYY
HH24')
order by to_char(r.actual_start_date,'DD-MON-YYYY HH24') asc;

select w.sid sid,


p.spid PID,
w.event event,
substr(s.username,1,10) username,
substr(s.osuser, 1,10) osuser,
w.state state,
w.wait_time wait_time,
w.seconds_in_wait wis,
substr(w.p1text||' '||to_char(w.P1)||'-'||
w.p2text||' '||to_char(w.P2)||'-'||
w.p3text||' '||to_char(w.P3), 1, 45) P1_P2_P3_TEXT
from v$session_wait w, v$session s, v$process p
where s.sid=w.sid
and p.addr = s.paddr
and w.event not in ('SQL*Net message from client', 'pipe get')
and s.username is not null;
select a.concurrent_queue_name
, substr(b.os_process_id,0,10) "OS Proc"
, b.oracle_process_id "Oracle ID"
, b.process_status_code
from fnd_concurrent_queues a
, fnd_concurrent_processes b
where a.concurrent_queue_id=b.concurrent_queue_id
and a.concurrent_queue_name='PFCCRTMGR'
and b.process_status_code='A'
order by b.process_status_code;
select

ptl.user_concurrent_program_name,qtl.user_concurrent_queue_name,t.request_id,t.phas
e_code,t.status_code
from fnd_concurrent_requests t,
fnd_concurrent_processes k,
fnd_concurrent_queues_tl qtl,
fnd_concurrent_programs_tl ptl
where k.concurrent_process_id = t.controlling_manager
and qtl.concurrent_queue_id = k.concurrent_queue_id
and ptl.concurrent_program_id=t.concurrent_program_id
and qtl.user_concurrent_queue_name like 'PFC CRT Account Manager'
and qtl.language='US';

select /*+ ordered */


fcp.user_concurrent_program_name
, fcr.request_id
, round(24*60*( sysdate - actual_start_date )) elapsed
, actual_start_date,request_date
, fu.user_name
, fcr.oracle_process_id
, sess.sid
, sess.serial#
, inst.inst_name
, sa.sql_text
, sess.sql_id,sess.machine,sess.program
, sess.event,sess.blocking_session_status,sess.wait_time,sess.module,sess.action
--, cp.plsql_dir || '/' || cp.plsql_out outfile_tmp
--, cp.plsql_dir || '/' || cp.plsql_log logfile_tmp
from apps.fnd_concurrent_requests fcr
, apps.fnd_concurrent_programs_tl fcp
, apps.fnd_concurrent_processes cp
, apps.fnd_user fu
, gv$process pro
, gv$session sess
, gv$sqlarea sa
, sys.v_$active_instances inst
where fcp.concurrent_program_id = fcr.concurrent_program_id
and fcp.application_id = fcr.program_application_id
and fcr.controlling_manager = cp.concurrent_process_id
and fcr.requested_by = fu.user_id (+)
and fcr.oracle_process_id = pro.spid (+)
and pro.addr = sess.paddr (+)
and pro.inst_id = sess.inst_id (+)
and sess.sql_address = sa.address (+)
and sess.sql_hash_value = sa.hash_value (+)
and sess.inst_id = inst.inst_number (+)
and fcr.phase_code = 'R' /* only running requests */
order by 3;
select * from gv$session where sid=2848 and serial#=5994;
SELECT SUBSTR(DECODE(request,0,'Holder: ','Waiter: ')
||sid,1,12) sess,
id1,
id2,
lmode,
request,
type
FROM gV$LOCK
WHERE (id1, id2, type) IN
(SELECT id1, id2, type FROM gV$LOCK WHERE request>0
)
order by id1;
select process,sid, blocking_session from gv$session where blocking_session is not
null;

select s.sid blocker, substr(s.program,1,40) program, w.username, w.sid blocked


from gv$session s, gv$session w
where w.blocking_session = s.sid
and w.blocking_session_status='VALID';

select * from gv$session where sid=2848;

select /*+ ordered */


fcp.user_concurrent_program_name
, fcr.request_id
, round(24*60*( sysdate - actual_start_date )) elapsed
, actual_start_date,request_date
, fu.user_name,
fcr.argument_text
, fcr.oracle_process_id
, sess.sid
, sess.serial#
, inst.inst_name
, sa.sql_text
, sess.sql_id,sess.machine,sess.program
, sess.event,sess.blocking_session_status,sess.wait_time,sess.module,sess.action
--, cp.plsql_dir || '/' || cp.plsql_out outfile_tmp
--, cp.plsql_dir || '/' || cp.plsql_log logfile_tmp
from apps.fnd_concurrent_requests fcr
, apps.fnd_concurrent_programs_tl fcp
, apps.fnd_concurrent_processes cp
, apps.fnd_user fu
, gv$process pro
, gv$session sess
, gv$sqlarea sa
, sys.v_$active_instances inst
where fcp.concurrent_program_id = fcr.concurrent_program_id
and fcp.application_id = fcr.program_application_id
and fcr.controlling_manager = cp.concurrent_process_id
and fcr.requested_by = fu.user_id (+)
and fcr.oracle_process_id = pro.spid (+)
and pro.addr = sess.paddr (+)
and pro.inst_id = sess.inst_id (+)
and sess.sql_address = sa.address (+)
and sess.sql_hash_value = sa.hash_value (+)
and sess.inst_id = inst.inst_number (+)
and parent_request_id=19105155
and fcr.phase_code = 'R' /* only running requests */
order by 3;
SELECT request_id,
-- parent_request_id,
phase_code,
status_code,
---- responsibility_application_id,
-- responsibility_id,
request_date,
actual_start_date,
-- actual_completion_date,
-- program,
requestor,
--user_concurrent_program_name,16000686
round (((actual_completion_date-actual_start_date)*24)) diff--,
--completion_text,
--argument_text
FROM fnd_conc_req_summary_v
WHERE parent_request_id=19105155
--user_concurrent_program_name like 'PFC Creditor Payment Listing Report'
--and status_code<>'C'
--and round (((actual_completion_date-actual_start_date)*24)) >5
--and trunc(request_date) = trunc(sysdate)
ORDER BY 7 desc ;

select /*+ ORDERED USE_NL(x fcr fcp fcptl)*/


fcr.request_id "Request ID",
fcr.requested_by "User",
substr(DECODE (FCR.DESCRIPTION, NULL,
FCPTL.USER_CONCURRENT_PROGRAM_NAME,
FCR.DESCRIPTION||' ('||
FCPTL.USER_CONCURRENT_PROGRAM_NAME||')'),1,80)"Program Name",
(fcr.actual_completion_date - fcr.actual_start_date)*1440 "Elapsed Time",
oracle_process_id "Trace File ID" ,
fcr.phase_code "Phase",
fcr.status_code "Status",
to_char(fcr.request_date,'DD-MON-YYYY HH24:MI:SS') "Submitted",
--(fcr.actual_start_date - fcr.request_date)*1440 "Delay",
to_char(fcr.actual_start_date,'DD-MON-YYYY HH24:MI:SS') "Start Time",
to_char(fcr.actual_completion_date, 'DD-MON-YYYY HH24:MI:SS') "End Time"--,
-- fcr.argument_text "Parameters"
from (select /*+ index (fcr1 FND_CONCURRENT_REQUESTS_N3) */
fcr1.request_id
from fnd_concurrent_requests fcr1
where 1=1
start with fcr1.request_id = &parent_request_id
connect by prior fcr1.request_id = fcr1.parent_request_id) x,
fnd_concurrent_requests fcr,
fnd_concurrent_programs fcp,
fnd_concurrent_programs_tl fcptl
where fcr.request_id = x.request_id
and fcr.concurrent_program_id = fcp.concurrent_program_id
and fcr.program_application_id = fcp.application_id
and fcp.application_id = fcptl.application_id
and fcp.concurrent_program_id = fcptl.concurrent_program_id
and fcptl.language = 'US'
order by 10;
select /*+ ORDERED USE_NL(x fcr fcp fcptl)*/
fcr.request_id "Request ID",
fcr.parent_request_id "Parent Reg ID",
fr.user_name "User",
substr(DECODE (FCR.DESCRIPTION, NULL,
FCPTL.USER_CONCURRENT_PROGRAM_NAME,
FCR.DESCRIPTION||' ('||
FCPTL.USER_CONCURRENT_PROGRAM_NAME||')'),1,80)"Program Name",
-- round(fcr.actual_completion_date - fcr.actual_start_date)*1440 "Elapsed
Time",
--oracle_process_id "Trace File ID" ,
fcr.phase_code "Phase",
fcr.status_code "Status",
to_char(fcr.request_date,'DD-MON-YYYY HH24:MI:SS') "Submitted",
--(fcr.actual_start_date - fcr.request_date)*1440 "Delay",
to_char(fcr.actual_start_date,'DD-MON-YYYY HH24:MI:SS') "Start Time",
to_char(fcr.actual_completion_date, 'DD-MON-YYYY HH24:MI:SS') "End Time",
round(((nvl(fcr.actual_completion_date,sysdate) - fcr.actual_start_date) *
24 * 60)) Elapsed,
fcr.argument_text "Parameters"
from (select
fcr1.request_id
from fnd_concurrent_requests fcr1
where 1=1
start with fcr1.request_id = &parent_request_id
connect by prior fcr1.request_id = fcr1.parent_request_id) x,
fnd_concurrent_requests fcr,
fnd_concurrent_programs fcp,
fnd_concurrent_programs_tl fcptl,
fnd_user fr
where fcr.request_id = x.request_id
and fr.user_id=fcr.requested_by
--and status_code='R'
--and phase_code='R'
and fcr.concurrent_program_id = fcp.concurrent_program_id
and fcr.program_application_id = fcp.application_id
and fcp.application_id = fcptl.application_id
and fcp.concurrent_program_id = fcptl.concurrent_program_id
and fcptl.language = 'US'
order by 10,8;

select * from fnd_concurrent_requests where request_id=19105155;


=============================
LOB Segement related:

SELECT SUM(bytes)/1024/1024/1024,
segment_name
FROM dba_segments
WHERE segment_name IN ('EC_SHJ_DM_HRT18_PROD_ALL','SYS_LOB0000700593C00020$
$','SYS_IL0000700593C00020$$')
GROUP BY segment_name
ORDER BY 1;

SELECT SUM(bytes)/1024/1024/1024,
segment_name,
owner,
segment_type,
tablespace_name
FROM dba_segments
WHERE segment_name in ('EC_SHJ_DM_HRT18_PROD_ALL','SYS_LOB0000700593C00020$
$','SYS_IL0000700593C00020$$')
GROUP BY segment_name,
owner,
segment_type,
tablespace_name
ORDER BY 1 DESC;
select * from v$database;

xxcnv.SYS_LOB0000700593C00020$$;

SELECT TABLE_NAME, column_name


FROM user_lobs
WHERE segment_name = (SELECT object_name
FROM user_objects
WHERE object_name = UPPER('&object_name')
AND object_type = 'LOB');

select * from dba_dependencies where owner='XXCNV';

SELECT *
FROM dba_lobs
WHERE segment_name = (select object_name from dba_objects where object_name like
'SYS_LOB0000700593C00020$$');

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

RMAN related:

SELECT TO_CHAR(start_time, 'DD-MM-YYYY HH24:MI:SS') Starttime,


TO_CHAR(end_time, 'DD-MM-YYYY HH24:MI:SS') Endtime,
output_device_type,
status,
input_type,
round(compression_ratio,2) compression,
INPUT_BYTES_DISPLAY inputbytes,
output_bytes_display outputbytes,input_bytes_per_sec_display
inputps,output_bytes_per_sec_display outputps,
time_taken_display
FROM V$RMAN_BACKUP_JOB_DETAILS
WHERE START_TIME > SYSDATE -7 ---AND INPUT_TYPE LIKE 'DB%'
ORDER BY START_TIME DESC;
REM RMAN Progress
alter session set nls_date_format='dd/mm/yy hh24:mi:ss'
/
select SID, START_TIME,TOTALWORK, sofar, (sofar/totalwork) * 100 done,
sysdate + TIME_REMAINING/3600/24 end_at
from v$session_longops
where totalwork > sofar
AND opname NOT LIKE '%aggregate%'
AND opname like 'RMAN%'
/

REM RMAN wiats


set lines 120
column sid format 9999
column spid format 99999
column client_info format a25
column event format a30
column secs format 9999
SELECT SID, SPID, CLIENT_INFO, event, seconds_in_wait secs, p1, p2, p3
FROM V$PROCESS p, V$SESSION s
WHERE p.ADDR = s.PADDR
and CLIENT_INFO like 'rman channel=%'
/

This script by Osama Mustafa will monitor the progress of a running RMAN job:

select
to_char(start_time,'DD-MON-YY HH24:MI') "BACKUP STARTED",
sofar,
totalwork,
elapsed_seconds/60 "ELAPSE (Min)",
round(sofar/totalwork*100,2) "Complete%"
from
sys.v_$session_longops
where compnam = 'dbms_backup_restore';
=================================================

===========================================
Undosizing related :

SELECT tablespace_name,
file_name,
bytes/(1024*1024) MB,
autoextensible,
maxbytes/(1024*1024) MaxMB
FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME IN
(SELECT UPPER(VALUE) FROM GV$PARAMETER WHERE NAME LIKE '%undo_tablespace%'
)
ORDER BY tablespace_name;

SELECT UPPER(VALUE),name FROM GV$PARAMETER WHERE NAME like '%undo%';

SELECT y.tablespace_name,
y.totmb "Total size MB",
ROUND(x.usedmb*100/y.totmb,2) "% Used"
FROM
(SELECT a.tablespace_name,
NVL(SUM(bytes),0)/(1024*1024) usedmb
FROM dba_undo_extents a
WHERE tablespace_name IN
(SELECT upper(value) FROM gv$parameter WHERE name='undo_tablespace'
)
AND status IN ('ACTIVE','UNEXPIRED')
GROUP BY a.tablespace_name
) x,
(SELECT b.tablespace_name,
SUM(bytes)/(1024*1024) totmb
FROM dba_data_files b
WHERE tablespace_name IN
(SELECT upper(value) FROM gv$parameter WHERE name='undo_tablespace'
)
GROUP BY b.tablespace_name
) y
WHERE y.tablespace_name=x.tablespace_name
ORDER BY y.tablespace_name;

select * from v$undostat order by undoblks desc;


SELECT SSOLDERRCNT FROM V$UNDOSTAT WHERE SSOLDERRCNT!=0 ORDER BY BEGIN_TIME;
select * from v$undostat where nospaceerrcnt !=0 order by begin_time;

SELECT TO_CHAR(MIN(BEGIN_TIME),'DD-MON-YYYY HH24:MI:SS') "Begin Time",


TO_CHAR(MAX(End_Time),'DD-MON-YYYY HH24:MI:SS') "End Time",
SUM(Undoblks) "Total Undo Blocks Used",
SUM(Txncount) "Total Num Trans Executed",
MAX(Maxquerylen) "Longest Query(in secs)",
MAX(Maxconcurrency) "Highest Concurrent Txn count",
SUM(Ssolderrcnt),
SUM(Nospaceerrcnt),
MAX(UNDOBLKS/((END_TIME-BEGIN_TIME)*3600*24)) "UNDO_BLOCK_PER_SEC"
FROM V$UNDOSTAT;

SELECT d.undo_size/(1024*1024) "ACTUAL UNDO SIZE [MByte]",


SUBSTR(e.value,1,25) "UNDO RETENTION [Sec]",
(TO_NUMBER(e.value) * TO_NUMBER(f.value) * g.undo_block_per_sec) / (1024*1024)
"NEEDED UNDO SIZE [MByte]"
FROM
(SELECT SUM(a.bytes) undo_size
FROM v$datafile a,
v$tablespace b,
dba_tablespaces c
WHERE c.contents = 'UNDO'
AND c.status = 'ONLINE'
AND b.name = c.tablespace_name
AND a.ts# = b.ts#
) d,
v$parameter e,
v$parameter f,
(SELECT MAX(undoblks/((end_time-begin_time)*3600*24)) undo_block_per_sec
FROM v$undostat
) g
WHERE E.NAME = 'undo_retention'
AND f.name = 'db_block_size';

SELECT sql_text
FROM dba_hist_sqltext
WHERE sql_id IN
(SELECT maxquerysqlid
FROM
(SELECT begin_time,
maxquerylen,
maxquerysqlid,
nospaceerrcnt,
ssolderrcnt,
tuned_undoretention
FROM dba_hist_undostat
WHERE TRUNC(BEGIN_TIME)>SYSDATE-10
ORDER BY 2 DESC
)
WHERE maxquerylen>3600
);

SELECT BEGIN_TIME,
MAXQUERYLEN,
MAXQUERYSQLID,
NOSPACEERRCNT,
SSOLDERRCNT,
TUNED_UNDORETENTION
FROM dba_hist_undostat
WHERE TRUNC(BEGIN_TIME)>SYSDATE-10
order by 2 desc;

SELECT tablespace_name,
status,
SUM(bytes)/1024/1024/1024
FROM dba_undo_extents
GROUP BY tablespace_name,
status
ORDER BY tablespace_name,
status;

Select To_Char(Begin_Time,'yyyymmdd hh24'),


Round(Max(Undoblks+ Expiredblks+Unexpiredblks+Activeblks)*8192/
(1024*1024*1024),2) Used_Gb,
Tuned_Undoretention
From Dba_Hist_Undostat
Where Trunc(Begin_Time)>Sysdate-&num_days
And Instance_Number =
&instance_Number
Group By To_Char(Begin_Time,'yyyymmdd hh24'),
Tuned_Undoretention
Order By To_Char(Begin_Time,'yyyymmdd hh24') Desc;

SELECT creation_time, metric_value, message_type, reason, suggested_action


From Dba_Outstanding_Alerts
WHERE object_name like '%APPS_UNDOTS%';

SELECT creation_time, metric_value, message_type, reason, suggested_action,


resolution
From Dba_Alert_History
WHERE object_name like '%APPS_UNDOTS%';

SELECT object_type, object_name, warning_value, critical_value


From Dba_Thresholds
WHERE object_type='TABLESPACE';

SELECT (UR * (UPS * DBS))/1024/1024/1024 AS "Bytes"


FROM
(SELECT value AS UR FROM v$parameter WHERE name = 'undo_retention'
),
(SELECT undoblks/((end_time-begin_time)*86400) AS UPS
FROM v$undostat
WHERE undoblks =
(SELECT MAX(undoblks) FROM v$undostat
)
),
(SELECT block_size AS DBS
FROM Dba_Tablespaces
WHERE tablespace_name =
(SELECT UPPER(value) FROM v$parameter WHERE name = 'undo_tablespace'
)
);

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

SELECT LPAD(' ', 2*level) || granted_role "USER PRIVS"


FROM (
SELECT NULL grantee, username granted_role
from dba_users
WHERE username LIKE UPPER('%&atsuser%')
UNION
SELECT grantee, granted_role
FROM dba_role_privs
UNION
SELECT grantee, privilege
FROM dba_sys_privs)
start with grantee is null
CONNECT BY grantee = prior granted_role;

select a.ksppinm name,


b.ksppstvl value,
b.ksppstdf deflt,
decode
(a.ksppity, 1,
'boolean', 2,
'string', 3,
'number', 4,
'file', a.ksppity) type,
a.ksppdesc description
from
sys.x$ksppi a,
sys.x$ksppcv b
where
a.indx = b.indx
and b.ksppstvl <> b.ksppstdf
and
a.ksppinm like '\_%' escape '\'
order by
name
===============================

Index analysis related:

select * from pay_assignment_link_usages_f ;

select * from dba_dependencies where name like 'PAY_ASSIGNMENT_LINK_USAGES_F';

select count(*) from PAY_ASSIGNMENT_LINK_USAGES_F;

select * from PAY_ASSIGNMENT_LINK_USAGES_F;

select table_name,round((blocks*8),2) "size (kb)" ,


round((num_rows*avg_row_len/1024),2) "actual_data
(kb)",
(ROUND((BLOCKS*8),2) -
ROUND((NUM_ROWS*AVG_ROW_LEN/1024),2)) "wasted_space (kb)"
FROM DBA_TABLES
WHERE (ROUND((BLOCKS*8),2) > ROUND((NUM_ROWS*AVG_ROW_LEN/1024),2)) and table_name
like 'PAY_ASSIGNMENT_LINK%'
order by 4 desc;
exec dbms_stats.gather_table_stats('HR','PAY_ASSIGNMENT_LINK_USAGES_F');

select owner,table_name,status,last_analyzed from dba_tables where table_name like


'PAY_ASSIGNMENT_LINK_USAGES_F';

select owner,index_name,table_name,status,last_analyzed from dba_indexes where


table_name like 'PAY_ASSIGNMENT_LINK_USAGES_F';

SELECT NAME, height, lf_rows, del_lf_rows,


(DEL_LF_ROWS / LF_ROWS) * 100 AS RATIO
FROM index_stats;

select * from index_stats;

select i.owner, i.index_name, s.tablespace_name,


i.initial_extent, i.next_extent, i.min_extents,
i.max_extents,
i.pct_increase, s.bytes
from sys.dba_segments s, sys.dba_indexes i
where s.segment_type = 'INDEX'
AND I.INDEX_NAME = S.SEGMENT_NAME
and i.table_name like 'PAY_ASSIGNMENT_LINK_USAGES_F';

You might also like