Monday, March 7, 2022

Orace DBA scripts: wait event scripts

 Orace DBA scripts: wait event scripts

-- sessions with highest CPU consumption

SELECT s.sid, s.serial#, p.spid as "OS PID",s.username, s.module, st.value/100 as "CPU sec"

FROM v$sesstat st, v$statname sn, v$session s, v$process p

WHERE sn.name = 'CPU used by this session' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND s.paddr = p.addr

AND s.last_call_et < 3600 -- active within last 1/2 hour

AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours


-- sessions with the highest time for a certain wait

SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, se.time_waited

FROM v$session_event se, v$session s, v$process p

WHERE se.event = '&event_name'

AND s.last_call_et < 1800 -- active within last 1/2 hour

AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND se.sid = s.sid

AND s.paddr = p.addr

ORDER BY se.time_waited;


-- sessions with highest DB Time usage

SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, st.value/100 as "DB Time (sec)"

, stcpu.value/100 as "CPU Time (sec)", round(stcpu.value / st.value * 100,2) as "% CPU"

FROM v$sesstat st, v$statname sn, v$session s, v$sesstat stcpu, v$statname sncpu, v$process p

WHERE sn.name = 'DB time' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND  sncpu.name = 'CPU used by this session' -- CPU

AND stcpu.statistic# = sncpu.statistic#

AND stcpu.sid = st.sid

AND s.paddr = p.addr

AND s.last_call_et < 1800 -- active within last 1/2 hour

AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND st.value > 0


--session statistics for a particular session :

 select  s.sid,s.username,st.name,se.value

from v$session s, v$sesstat se, v$statname st

where s.sid=se.SID and se.STATISTIC#=st.STATISTIC#

--and st.name ='CPU used by this session'

and s.username='&USERNAME'

order by s.sid,se.value desc


If non DBA user want to see its own statistics then it should grants as below:

grant select on sys.V_$SESSION to username;

grant select on sys.V_$STATNAME to username;

grant select on sys.V_$MYSTAT to username;


and replace view v$sesstat by v$mystat


another useful grants :

grant select on sys.V_$PROCESS to username;

grant select on sys.DBA_2PC_PENDING to username;

grant select on sys.v_$SQLTEXT to username;

grant select on sys.v_$SQL to username;



++++++++++++



Performance issue find highest resource consumption

Session with highest CPU consumption


SELECT s.sid, s.serial#, p.spid as "OS PID",s.username, s.module, st.value/100 as

"CPU sec"

FROM v$sesstat st, v$statname sn, v$session s, v$process p

WHERE sn.name = 'CPU used by this session' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND s.paddr = p.addr

AND s.last_call_et (SYSDATE - 240/1440) -- sessions logged on within 4 hours

ORDER BY st.value;


Sessions with the highest time for a certain wait


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, se.time_waited

FROM v$session_event se, v$session s, v$process p

WHERE se.event = '&event_name'

AND s.last_call_et (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND se.sid = s.sid

AND s.paddr = p.addr

ORDER BY se.time_waited;


Sessions with highest DB Time usage


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, st.value/100 as

"DB Time (sec)"

, stcpu.value/100 as "CPU Time (sec)", round(stcpu.value / st.value * 100,2) as "%

CPU"

FROM v$sesstat st, v$statname sn, v$session s, v$sesstat stcpu, v$statname sncpu, v

$process p

WHERE sn.name = 'DB time' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND sncpu.name = 'CPU used by this session' -- CPU

AND stcpu.statistic# = sncpu.statistic#

AND stcpu.sid = st.sid

AND s.paddr = p.addr

AND s.last_call_et (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND st.value > 0;


++++++++++++


O CHECK FOR TABLE LOCKS


set pagesize 400

set linesize 600

col USERNAME for a15

col OS_USER_NAME for a15

col TERMINAL for a15

col OBJECT_NAME for a30

SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal, b.object_id,substr(b.object_name,1,40) object_name

from v$session a, dba_objects b, v$locked_object c where a.sid = c.session_id and b.object_id = c.object_id;



Steps for releasing lock on a table:

Finding Locks



select session_id "sid",SERIAL# "Serial",

substr(object_name,1,20) "Object",

substr(os_user_name,1,10) "Terminal",

substr(oracle_username,1,10) "Locker",

nvl(lockwait,'active') "Wait",

decode(locked_mode,

2, 'row share',

3, 'row exclusive',

4, 'share',

5, 'share row exclusive',

6, 'exclusive', 'unknown') "Lockmode",

OBJECT_TYPE "Type"

FROM

SYS.V_$LOCKED_OBJECT A,

SYS.ALL_OBJECTS B,

SYS.V_$SESSION c

WHERE

A.OBJECT_ID = B.OBJECT_ID AND

C.SID = A.SESSION_ID

ORDER BY 1 ASC, 5 Desc


Finding Blocking sessions :


select l1.sid, ' IS BLOCKING ', l2.sid

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


select s1.username '@' s1.machine ' ( SID=' s1.sid ' ) is blocking '

s2.username '@' s2.machine ' ( SID=' s2.sid ' ) ' AS blocking_status

from v$lock l1, v$session s1, v$lock l2, v$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 ;


Sessions with highest CPU consumption :

SELECT s.sid, s.serial#, p.spid as "OS PID",s.username, s.module, st.value/100 as "CPU sec"

FROM v$sesstat st, v$statname sn, v$session s, v$process p

WHERE sn.name = 'CPU used by this session' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND s.paddr = p.addr

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

ORDER BY st.value;


Sessions with the highest time for a certain wait  :


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, se.time_waited

FROM v$session_event se, v$session s, v$process p

WHERE se.event = '&event_name'

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND se.sid = s.sid

AND s.paddr = p.addr

ORDER BY se.time_waited;


Sessions with highest DB Time usage :


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, st.value/100 as "DB Time (sec)"

, stcpu.value/100 as "CPU Time (sec)", round(stcpu.value / st.value * 100,2) as "% CPU"

FROM v$sesstat st, v$statname sn, v$session s, v$sesstat stcpu, v$statname sncpu, v$process p

WHERE sn.name = 'DB time' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND sncpu.name = 'CPU used by this session' -- CPU

AND stcpu.statistic# = sncpu.statistic#

AND stcpu.sid = st.sid

AND s.paddr = p.addr

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND st.value > 0; 

 



Step1:To verify the lock object Here is the import query:

---------------------------------------------------------------


SELECT o.owner, o.object_name, o.object_type, o.last_ddl_time, o.status, l.session_id, l.oracle_username, l.locked_mode

FROM dba_objects o, gv$locked_object l

WHERE o.object_id = l.object_id;


Step 2: Find the serial# for the sessions holding the lock:


SQL> select SERIAL# from v$session where SID=667;


SERIAL#

----------

21091


SQL> alter system kill session '667,21091';


System altered.



How to release a lock in Oracle


This mostly comes from two other sources Killing Oracle Session and What’s blocking my lock?

This involves the system tables v$lock and v$session, and using the ‘ALTER SYSTEM’ statement. This can all be done via sqlplus as the system user (you don’t need to be sysdba).


First, determine who’s holding the lock:


select

 s1.username || '@' || s1.machine

 || ' ( SID,S#=' || s1.sid || ',' || s1.serial# || ' )  is blocking '

 || s2.username || '@' || s2.machine

 || ' ( SID,S#=' || s2.sid || ',' || s2.serial# || ' )'

  AS blocking_status

from

 v$lock l1,

 v$session s1,

 v$lock l2,

 v$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;

 

 

The result set will look like this:


BLOCKING_STATUS

--------------------------------------------------------------------------------

BEN@INTWAREPOD2145 ( SID,S#=134,11102 )  is blocking BEN@INTWAREPOD2145 ( SID,S#=128,30076 )

 

 

Now that we know which session is doing the blocking, (134,11102) in this case, we can kill it.


SQL> alter system kill session '134,11102';

 

Note, the alter system statement is powerful stuff, so take care with it.





=++++++


Database Important Scripts

Hit Ratios


select Round(100*(cg.value+db.value-pr.value)/(cg.value+db.value),2) "Buffer Hit Ratio"

from v$sysstat db, v$sysstat cg, v$sysstat pr

where db.name = 'db block gets'

and cg.name = 'consistent gets'

and pr.name = 'physical reads'

/


Check the active process


ps -fu applmgr


Kill the Active process


kill -9 `ps -u applmgr -o "pid="`



Clear the whole content and remove all lines inside the file then :


Code:

cat /dev/null > your_file


Total TBS Size


SELECT space.tablespace_name, space.total_space, free.total_free,

ROUND(free.total_free/space.total_space*100) as pct_free,

ROUND((space.total_space-free.total_free),2) as total_used,

ROUND((space.total_space-free.total_free)/space.total_space*100) as pct_used,

free.max_free, next.max_next_extent

FROM

(SELECT tablespace_name, SUM(bytes)/1024/1024 total_space

FROM dba_data_files

GROUP BY tablespace_name) space,

(SELECT tablespace_name, ROUND(SUM(bytes)/1024/1024,2) total_free, ROUND(MAX(bytes)/1024/1024,2) max_free

FROM dba_free_space

GROUP BY tablespace_name) free,

(SELECT tablespace_name, ROUND(MAX(next_extent)/1024/1024,2) max_next_extent FROM dba_segments

GROUP BY tablespace_name) NEXT

WHERE space.tablespace_name = free.tablespace_name (+)

AND space.tablespace_name = next.tablespace_name (+)

AND (ROUND(free.total_free/space.total_space*100)<> free.max_free)

order by pct_used desc

/


Free Space Size


select tablespace_name, bytes/1024/1024 from dba_free_space

/


Last Analyzed


select max(last_analyzed) from dba_tables

/


TEMP TBS Size


select file_name, sum(bytes)/(1024*1024) from dba_temp_files

group by file_name

/


select tablespace_name, sum(bytes)/(1024*1024) TEMPSIZE from dba_temp_files

group by tablespace_name

/


Script: Listing Memory Used By All Sessions


select se.sid,n.name,

max(se.value) maxmem

from v$sesstat se,

v$statname n

where n.statistic# = se.statistic#

and n.name in ('session pga memory','session pga memory max',

'session uga memory','session uga memory max')

group by n.name,se.sid

order by 3

/


SCRIPT: How to Determine the Number of Disk Sorts vs Memory Sorts


select 'INIT.ORA sort_area_size: 'value

from v$parameter

where name like 'sort_area_size'

/


select a.name, value

from v$statname a, v$sysstat

where a.statistic# = v$sysstat.statistic#

and a.name in ('sorts (disk)', 'sorts (memory)', 'sorts (rows)')

/


This script lists all jobs that are currently running in the local database.


select

djr.sid sess,

djr.job jid,

dj.log_user subu,

dj.priv_user secd,

dj.what proc,

to_char(djr.last_date,'MM/DD') lsd,

substr(djr.last_sec,1,5) lst,

to_char(djr.this_date,'MM/DD') nrd,

substr(djr.this_sec,1,5) nrt,

djr.failures fail

from

sys.dba_jobs dj,

sys.dba_jobs_running djr

where

djr.job = dj.job

/


Lists all jobs that have been submitted to run in the local database job queue.


select

job jid,

log_user subu,

priv_user secd,

what proc,

to_char(last_date,'MM/DD') lsd,

substr(last_sec,1,5) lst,

to_char(next_date,'MM/DD') nrd,

substr(next_sec,1,5) nrt,

failures fail,

decode(broken,'Y','N','Y') ok

from

sys.dba_jobs

/


Compile


for

set heading off;

set pagesize 500;

spool c:\dba\compile.sql;

select 'alter ' object_type ' ' OBJECT_NAME ' compile ' ';' from dba_objects where object_type in ('FUNCTION','PACKAGE','PROCEDURE','TRIGGER','PACKAGE BODY','VIEW') AND STATUS ='INVALID';

spool off;


for running the script

@c:\dba\compile.sql


Section – A

This scripts is used to take a index rebuild


The following tables we have to recreate it, (FND_CONCURRENT_REQUESTS, FND_FILE_TEMP)



1) This scripts is used to take a index rebuild on following tables

(FND_CONCURRENT_REQUESTS, FND_FILE_TEMP)

(spool the following output)


select 'ALTER INDEX ' OWNER '.' INDEX_NAME ' REBUILD NOLOGGING;'

FROM DBA_INDEXES a

WHERE

a.TABLE_NAME in('FND_CONCURRENT_REQUESTS','FND_FILE_TEMP')

and partitioned= 'NO'

union

select 'ALTER INDEX ' a.OWNER '.' b.INDEX_NAME ' REBUILD PARTITION 'b.partition_name' NOLOGGING;'

from dba_indexes a,dba_ind_partitions b

where a.indeX_name = b.index_name

and a.TABLE_NAME in ('FND_CONCURRENT_REQUESTS','FND_FILE_TEMP')

and partitioned= 'YES'


2) ALTER TABLE APPLSYS.FND_CONCURRENT_REQUESTS move;

3) ALTER TABLE APPLSYS.FND_FILE_TEMP move;

3) run the index rebuild outuput scripts.

4) run the gather table statistics for mentioned tables

(FND_CONCURRENT_REQUESTS, FND_FILE_TEMP)





TABLE


select segment_name, owner, extents, max_extents

from dba_segments

where segment_type = 'TABLE'

and (extents +1) >= max_extents;


ALTER TABLE .table STORAGE ( MAXEXTENTS x);


where x is greater than max_extents and lesser than unlimited

(2147483645);


ALTER TABLE .table STORAGE ( MAXEXTENTS UNLIMITED);




INDEX


select segment_name, owner, extents, max_extents

from dba_segments

where segment_type = 'INDEX' and

(extents +1) >= max_extents;




ALTER INDEX .index STORAGE ( MAXEXTENTS integer);


ALTER INDEX .index STORAGE ( MAXEXTENTS UNLIMITED);




Section B


The following script's output is used to run a index rebuild on weekly basis


select 'ALTER INDEX ' OWNER '.' INDEX_NAME ' REBUILD NOLOGGING;'

FROM DBA_INDEXES a

WHERE OWNER NOT IN ('SYS','SYSTEM')

AND a.INDEX_TYPE='NORMAL'

AND NOT EXISTS (SELECT INDEX_NAME FROM DBA_IND_PARTITIONS

WHERE INDEX_OWNER NOT IN ('SYS','SYSTEM')

AND INDEX_NAME = a.INDEX_NAME)

AND TABLE_NAME NOT IN (SELECT TABLE_NAME from dba_tables c

where TEMPORARY='Y'

and a.table_name = c.table_name)

ORDER BY OWNER,INDEX_NAME;

/




for

set heading off;

set pagesize 500;

spool c:\dba\compile.sql;


select 'alter ' object_type ' ' OBJECT_NAME ' compile ' ';' from dba_objects where object_type in ('FUNCTION','PACKAGE','PROCEDURE','TRIGGER','VIEW') AND STATUS ='INVALID';

spool off;

for running the script

select 'alter ' 'PACKAGE ' OBJECT_NAME ' compile body' ';' from dba_objects where object_type in ('PACKAGE BODY') AND STATUS ='INVALID';

/




spool runts.sql

select 'alter database datafile '''file_name''''' autoextend on;' from dba_data_files;

/

@runts




The biggest portion of a database's size comes from the datafiles. To find out how many megabytes are allocated to ALL datafiles:



select sum(bytes)/1024/1024 "Meg" from dba_data_files;


To get the size of all TEMP files:


select nvl(sum(bytes),0)/1024/1024 "Meg" from dba_temp_files;


To get the size of the on-line redo-logs:


select sum(bytes)/1024/1024 "Meg" from sys.v_$log;


Putting it all together into a single query:


select a.data_size+b.temp_size+c.redo_size "total_size"

from ( select sum(bytes) data_size

from dba_data_files ) a,

( select nvl(sum(bytes),0) temp_size

from dba_temp_files ) b,

( select sum(bytes) redo_size

from sys.v_$log ) c

/


select to_char(creation_time, 'RRRR Month') "Month",

sum(bytes)/1024/1024 "Growth in Meg"

from sys.v_$datafile

where creation_time > SYSDATE-365

group by to_char(creation_time, 'RRRR Month')


/



SESSION_WAITS


SELECT NVL(s.username, '(oracle)') AS username,

s.sid,

s.serial#,

sw.event,

sw.wait_time,

sw.seconds_in_wait,

sw.state

FROM v$session_wait sw,

v$session s

WHERE s.sid = sw.sid

ORDER BY sw.seconds_in_wait DESC;

/



To select the username and the process status


select a.requested_start_date,a.last_update_date,a.status_code,b.user_name

from fnd_concurrent_requests a,fnd_user b where a.requested_by = b.user_id and a.request_id = 677224



selecta.requested_start_date,a.last_update_date,a.status_code,b.user_name ,a.argument_text from fnd_concurrent_requests a,fnd_user b where a.requested_by = b.user_id and a.request_id = 677224



To select the username,process,status,Terminal name using SID


select a.status,p.spid, a.sid, a.serial#, a.username, a.terminal,

a.osuser, c.Consistent_Gets, c.Block_Gets, c.Physical_Reads,

(100*(c.Consistent_Gets+c.Block_Gets-c.Physical_Reads)/

(c.Consistent_Gets+c.Block_Gets)) HitRatio, c.Physical_Reads, b.sql_text

from v$session a, v$sqlarea b, V$SESS_IO c,v$process p

where a.sql_hash_value = b.hash_value

and a.SID = c.SID

and p.addr = a.paddr

and (c.Consistent_Gets+c.Block_Gets)>0

and a.Username is not null

Order By a.status asc, c.Consistent_Gets desc , c.Physical_Reads desc;

/



To see the currently updated archive log files


SQL>select name from v$archived_log where trunc(completion_time) >= trunc(sysdate)-5;


To find the BDUMP,UDUMP directory


select value from v$parameter where name = 'background_dump_dest'

select value from v$parameter where name = 'user_dump_dest'

select value from v$parameter where name in ('background_dump_dest','user_dump_dest', 'log_archive_dest')

/



Identify the user and session ID for a UNIX process


This quick process identifies the Oracle user and session ID of a UNIX process that is using up a large amount of CPU. It can also be used to help find inefficient queries. This query is placed inside of a script that I pass the UNIX process ID to.


select s.sid, s.username, s.osuser, s.serial#

from v$session s, v$process p

where s.paddr = p.addr

and p.spid = &1;

/


Tracing an Oracle session by SID


This code accepts an Oracle session ID [SID] as a parameter and will show you what SQL statement is running in that session and what event the session is waiting for. You simply create a SQL file of the code and run it from the SQL prompt.


prompt Showing running sql statements ...........................


select addr from v$process where spid='8419'


select * from v$session where PADDR='00000003B29F9388'



select a.sid Current_SID, a.last_call_et ,b.sql_text

from v$session a

,v$sqltext b

where a.sid = 14

and a.username is not null

and a.status = 'ACTIVE'

and a.sql_address = b.address

order by a.last_call_et,a.sid,b.piece;


prompt Showing what sql statement is doing.....................


select a.sid, a.value session_cpu, c.physical_reads,

c.consistent_gets,d.event,

d.seconds_in_wait

from v$sesstat a,v$statname b, v$sess_io c, v$session_wait d

where a.sid= 14

and b.name = 'CPU used by this session'

and a.statistic# = b.statistic#

and a.sid=c.sid

and a.sid=d.sid;

/


Check all active processes, the latest SQL, and the SQL hit ratio


select a.status, a.sid, a.serial#, a.username, a.terminal,

a.osuser, c.Consistent_Gets, c.Block_Gets, c.Physical_Reads,

(100*(c.Consistent_Gets+c.Block_Gets-c.Physical_Reads)/

(c.Consistent_Gets+c.Block_Gets)) HitRatio, c.Physical_Reads, b.sql_text

from v$session a, v$sqlarea b, V$SESS_IO c

where a.sql_hash_value = b.hash_value

and a.SID = c.SID

and (c.Consistent_Gets+c.Block_Gets)>0

and a.Username is not null

and a.status = 'ACTIVE'

Order By a.status asc, c.Consistent_Gets desc , c.Physical_Reads desc;


Monitoring Oracle processes


select p.spid "Thread ID", b.name "Background Process", s.username

"User Name",

s.osuser "OS User", s.status "STATUS", s.sid "Session ID",

s.serial# "Serial No.",

s.program "OS Program"

from v$process p, v$bgprocess b, v$session s

where s.paddr = p.addr and b.paddr(+) = p.addr

order by s.status,1;


/



Displays concurrent requests that have run times longer than one hour (3600 seconds)


SELECT REQUEST_ID,

TO_CHAR(ACTUAL_START_DATE,'MM/DD/YY HH:MI:SS') starttime,

TO_CHAR(ACTUAL_COMPLETION_DATE,'MM/DD/YY HH:MI:SS') endtime,

ROUND((ACTUAL_COMPLETION_DATE - ACTUAL_START_DATE)*(60*24),2) rtime,

OUTCOME_CODE,phase_code,status_code,

printer,print_style,description,

SUBSTR(completion_text,1,20) compl_txt

FROM fnd_concurrent_requests

WHERE to_date(ACTUAL_START_DATE,'DD-MON-RRRR') = to_date(sysdate,'DD-

MON-RRRR')

ORDER BY 2 desc

/


This script will map concurrent manager process information about current concurrent managers.


SELECT proc.concurrent_process_id concproc,

SUBSTR(proc.os_process_id,1,6) clproc,

SUBSTR(LTRIM(proc.oracle_process_id),1,15) opid,

SUBSTR(vproc.spid,1,10) svrproc,

DECODE(proc.process_status_code,'A','Active',

proc.process_status_code) cstat,

SUBSTR(concq.concurrent_queue_name,1,30) qnam,

-- SUBSTR(proc.logfile_name,1,20) lnam,

SUBSTR(proc.node_name,1,10) nnam,

SUBSTR(proc.db_name,1,8) dbnam,

SUBSTR(proc.db_instance,1,8) dbinst,

SUBSTR(vsess.username,1,10) dbuser

FROM fnd_concurrent_processes proc,

fnd_concurrent_queues concq,

v$process vproc,

v$session vsess

WHERE proc.process_status_code = 'A'

AND proc.queue_application_id = concq.application_id

AND proc.concurrent_queue_id = concq.concurrent_queue_id

AND proc.oracle_process_id = vproc.pid(+)

AND vproc.addr = vsess.paddr(+)

ORDER BY proc.queue_application_id,

proc.concurrent_queue_id


Show currently running concurrent requests


SELECT SUBSTR(LTRIM(req.request_id),1,15) concreq,

SUBSTR(proc.os_process_id,1,15) clproc,

SUBSTR(LTRIM(proc.oracle_process_id),1,15) opid,

SUBSTR(look.meaning,1,10) reqph,

SUBSTR(look1.meaning,1,10) reqst,

SUBSTR(vsess.username,1,10) dbuser,

SUBSTR(vproc.spid,1,10) svrproc,

vsess.sid sid,

vsess.serial# serial#

FROM fnd_concurrent_requests req,

fnd_concurrent_processes proc,

fnd_lookups look,

fnd_lookups look1,

v$process vproc,

v$session vsess

WHERE req.controlling_manager = proc.concurrent_process_id(+)

AND req.status_code = look.lookup_code

AND look.lookup_type = 'CP_STATUS_CODE'

AND req.phase_code = look1.lookup_code

AND look1.lookup_type = 'CP_PHASE_CODE'

AND look1.meaning = 'Running'

AND proc.oracle_process_id = vproc.pid(+)

AND vproc.addr = vsess.paddr(+);

/


To find the CPU consumption


select ss.sid,w.event,command,ss.value CPU ,se.username,se.program, wait_time, w.seq#, q.sql_text,command

from

v$sesstat ss, v$session se,v$session_wait w,v$process p, v$sqlarea q

where ss.statistic# in

(select statistic#

from v$statname

where name = 'CPU used by this session')

and se.sid=ss.sid

and ss.sid>6

and se.paddr=p.addr

and se.sql_address=q.address

order by ss.value desc,ss.sid

/


Script to show problem tablespaces


SELECT space.tablespace_name, space.total_space, free.total_free,

ROUND(free.total_free/space.total_space*100) as pct_free,

ROUND((space.total_space-free.total_free),2) as total_used,

ROUND((space.total_space-free.total_free)/space.total_space*100) as pct_used,

free.max_free, next.max_next_extent

FROM

(SELECT tablespace_name, SUM(bytes)/1024/1024 total_space

FROM dba_data_files

GROUP BY tablespace_name) space,

(SELECT tablespace_name, ROUND(SUM(bytes)/1024/1024,2) total_free, ROUND(MAX(bytes)/1024/1024,2) max_free

FROM dba_free_space

GROUP BY tablespace_name) free,

(SELECT tablespace_name, ROUND(MAX(next_extent)/1024/1024,2) max_next_extent FROM dba_segments

GROUP BY tablespace_name) NEXT

WHERE space.tablespace_name = free.tablespace_name (+)

AND space.tablespace_name = next.tablespace_name (+)

AND (ROUND(free.total_free/space.total_space*100)<> free.max_free)

order by pct_used desc



Oracle space monitoring scripts table space wise

This scripts gives warning indicator for all tablespaces that have less then 90% free space in them (with an asterisk in the last column).


select tbs.tablespace_name,

tot.bytes/(1024*1024) "Total Space in MB",

round(tot.bytes/(1024*1024)- sum(nvl(fre.bytes,0))/(1024*1024),2) "Used in MB",

round(sum(nvl(fre.bytes,0))/(1024*1024),2) "Free in MB",

round((1-sum(nvl(fre.bytes,0))/tot.bytes)*100,2) Pct,

decode(

greatest((1-sum(nvl(fre.bytes,0))/tot.bytes)*100, 90),

90, '', '*'

) Pct_warn

from dba_free_space fre,

(select tablespace_name, sum(bytes) bytes

from dba_data_files

group by tablespace_name) tot,

dba_tablespaces tbs

where tot.tablespace_name = tbs.tablespace_name

and fre.tablespace_name(+) = tbs.tablespace_name

group by tbs.tablespace_name, tot.bytes/(1024*1024), tot.bytes

order by 5 desc, 1 ;



Oracle space monitoring scripts (grand total table space)


select

sum(tot.bytes/(1024 *1024))"Total size",

sum(tot.bytes/(1024*1024)-sum(nvl(fre.bytes,0))/(1024*1024)) Used,

sum(sum(nvl(fre.bytes,0))/(1024*1024)) Free,

sum((1-sum(nvl(fre.bytes,0))/tot.bytes)*100) Pct

from dba_free_space fre,

(select tablespace_name, sum(bytes) bytes

from dba_data_files

group by tablespace_name) tot,

dba_tablespaces tbs

where tot.tablespace_name = tbs.tablespace_name

and fre.tablespace_name(+) = tbs.tablespace_name

group by tbs.tablespace_name, tot.bytes/(1024*1024), tot.bytes

/



What's holding up the system?


Poorly written SQL is another big problem. Use the following SQL to determine the UNIX pid:


Select

p.pid, s.sid, s.serial#,s.status, s.machine,s.osuser, p.spid, t.sql_text

From

v$session s,

v$sqltext t,

v$process p

Where

s.sql_address = t.address and

s.paddr = p.addr and

s.sql_hash_value = t.hash_value and

s.sid > 7 and

s.audsid != userenv ('SESSIONID')

Order By s.status,s.sid, s.osuser, s.process, t.piece ;

/


Script to display status of all the Concurrent Managers

select distinct Concurrent_Process_Id CpId, PID Opid,

Os_Process_ID Osid, Q.Concurrent_Queue_Name Manager,

P.process_status_code Status,

To_Char(P.Process_Start_Date, 'MM-DD-YYYY HH:MI:SSAM') Started_At

from Fnd_Concurrent_Processes P, Fnd_Concurrent_Queues Q, FND_V$Process

where Q.Application_Id = Queue_Application_ID

and Q.Concurrent_Queue_ID = P.Concurrent_Queue_ID

and Spid = Os_Process_ID

and Process_Status_Code not in ('K','S')

order by Concurrent_Process_ID, Os_Process_Id, Q.Concurrent_Queue_Name


Get current SQL from SGA


select sql_text

from V$session s , V$sqltext t

where s.sql_address=t.address

and sid=

order by piece;


You can find the SID from V$session.


What SQL is running and who is running it?


select a.sid,a.serial#,a.username,b.sql_text

from v$session a,v$sqltext b

where a.username is not null

and a.status = 'ACTIVE'

and a.sql_address = b.address

order by 1,2,b.piece;


---

select decode(sum(decode(s.serial#,l.serial#,1,0)),0,'No','Yes') " ",

s.sid "Session ID",s.status "Status",

s.username "Username", RTRIM(s.osuser) "OS User",

b.spid "OS Process ID",s.machine "Machine Name",

s.program "Program",c.sql_text "SQL text"

from v$session s, v$session_longops l,v$process b,

(select address,sql_text from v$sqltext where piece=0) c

where (s.sid = l.sid(+)) and s.paddr=b.addr and s.sql_address = c.address

group by s.sid,s.status,s.username,s.osuser,s.machine,

s.program,b.spid, b.pid, c.sql_text order by s.status,s.sid


TO FIND THE SORTING DETAILS


SELECT a.sid,a.value,b.name from

V$SESSTAT a, V$STATNAME b

WHERE a.statistic#=b.statistic#

AND b.name LIKE 'sort%'

ORDER BY 1;

/


Long running SQL statements


SELECT s.rows_processed, s.loads, s.executions, s.buffer_gets,

s.disk_reads, t.sql_text,s.module, s.ACTION

FROM v$sql /*area*/ s,

v$sqltext t

WHERE s.address = t.address

AND ((buffer_gets > 10000000) or

(disk_reads > 1000000) or

(executions > 1000000))

ORDER BY ((s.disk_reads * 100) + s.buffer_gets) desc, t.address, t.piece

/

Move a table from one tablespace to another


There are many ways to move a table from one tablespace to another. For example, you can create a duplicate table with dup_tab as select * from original_tab; drop the original table and rename the duplicate table as the original one.


The second option is exp table, drop it from the database and import it back. The third option (which is the one I am most interested in) is as follows.


Suppose you have a dept table in owner scott in the system tablespace and you want to move in Test tablespace.


connect as sys


SQL :> select table_name,tablespace_name from dba_tables where table_name='DEPT' and owner='SCOTT';


TABLE_NAME TABLESPACE_NAME

------------------------------ ------------------------------

DEPT SYSTEM


Elapsed: 00:00:00.50


You want to move DEPT table from system to say test tablespace.


SQL :> connect scott/tiger

Connected.

SQL :> alter table DEPT move tablespace TEST;


Table altered.



SQL :> connect

Enter user-name: sys

Enter password:

Connected.

SQL :> select table_name,tablespace_name from dba_tables where table_name='DEPT' and owner='SCOTT';


TABLE_NAME TABLESPACE_NAME

------------------------------ ------------------------------

DEPT TEST

/



To compile the procedure


Alter PROCEDURE JA_IN_BULK_PO_QUOTATION_TAXES compile


To compile the form


F60gen userid=apps/metroapps@dev module=

.fmb

output_file=/forms/US/form name.fmx

module_type=form batch=no compile_all=special





/


Run this sql statement to get package version :


select text from user_source where name='&package_name'

and text like '%$Header%';


prompt asks you the package name, in return it gives you two lines

corresponding to specifications and body creation files


You can also get pls version on database by running:


select name , text

from dba_source

where text like '%.pls%'

and line <>views


Sometimes version information is available in view definition.

Try the following sql statement :


col TEXT for a40 head "TEXT"

select VIEW_NAME, TEXT

from USER_VIEWS

where VIEW_NAME = '&VIEW_NAME';


workflow


Run wfver.sql (see §5.e) to get version of workflow packages and views.





Finding active and inactive sessions :



set linesize 132

col started format a15

col osuser format a10

col username format a13

col sid format 99999

select d.physical_reads, p.spid,a.sid, a.serial#, a.username, a.osuser,

TO_CHAR(a.logon_time, 'MM/DD HH24:MI') started, a.sql_hash_value,status

from sys.v_$session a, sys.v_$process p, sys.v_$sess_io d

where a.sid = d.sid and a.paddr = p.addr and a.type <> 'BACKGROUND'

and a.status = 'INACTIVE'

order by a.username,a.logon_time





Select 'alter system kill session '''sid','serial#''';' from

V$session where status='INACTIVE';


select p.spid,s.status,s.username,s.machine,s.sid,s.serial#,s.program,

s.osuser,s.sql_address from v$process p,v$session s

where s.paddr = p.addr and s.sid in(&sid)




Finding Locks



select session_id "sid",SERIAL# "Serial",

substr(object_name,1,20) "Object",

substr(os_user_name,1,10) "Terminal",

substr(oracle_username,1,10) "Locker",

nvl(lockwait,'active') "Wait",

decode(locked_mode,

2, 'row share',

3, 'row exclusive',

4, 'share',

5, 'share row exclusive',

6, 'exclusive', 'unknown') "Lockmode",

OBJECT_TYPE "Type"

FROM

SYS.V_$LOCKED_OBJECT A,

SYS.ALL_OBJECTS B,

SYS.V_$SESSION c

WHERE

A.OBJECT_ID = B.OBJECT_ID AND

C.SID = A.SESSION_ID

ORDER BY 1 ASC, 5 Desc


Finding Blocking sessions :


select l1.sid, ' IS BLOCKING ', l2.sid

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


select s1.username '@' s1.machine ' ( SID=' s1.sid ' ) is blocking '

s2.username '@' s2.machine ' ( SID=' s2.sid ' ) ' AS blocking_status

from v$lock l1, v$session s1, v$lock l2, v$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 ;




-- sessions with highest CPU consumption


SELECT s.sid, s.serial#, p.spid as "OS PID",s.username, s.module, st.value/100 as "CPU sec"

FROM v$sesstat st, v$statname sn, v$session s, v$process p

WHERE sn.name = 'CPU used by this session' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND s.paddr = p.addr

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

ORDER BY st.value;



-- sessions with the highest time for a certain wait


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, se.time_waited

FROM v$session_event se, v$session s, v$process p

WHERE se.event = '&event_name'

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND se.sid = s.sid

AND s.paddr = p.addr

ORDER BY se.time_waited;


-- sessions with highest DB Time usage


SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, st.value/100 as "DB Time (sec)"

, stcpu.value/100 as "CPU Time (sec)", round(stcpu.value / st.value * 100,2) as "% CPU"

FROM v$sesstat st, v$statname sn, v$session s, v$sesstat stcpu, v$statname sncpu, v$process p

WHERE sn.name = 'DB time' -- CPU

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND sncpu.name = 'CPU used by this session' -- CPU

AND stcpu.statistic# = sncpu.statistic#

AND stcpu.sid = st.sid

AND s.paddr = p.addr

AND s.last_call_et <> (SYSDATE - 240/1440) -- sessions logged on within 4 hours

AND st.value > 0;

db file scattered read

Systemwide Waits:

If the TIME spent waiting for multiblock reads is significant then it can be helpful to determine which segment/s Oracle is performing the reads against. The files where the reads are occuring can be found by looking at where BLKS_READ / READS > 1 . (A ratio greater than 1 indicates there are some multiblock reads occuring).



It can also be useful to see which sessions are performing scans and trace them to see if the scans are expected or not. This statement can be used to see which sessions may be worth tracing:



SELECT sid, total_waits, time_waited FROM v$session_event WHERE event='db file scattered read' and total_waits>0 ORDER BY 3,2;



One can also look at:

Statements with high DISK_READS in Sessions with high table scans blocks gotten in


db file sequential read



Systemwide Waits:IO is a normal activity so you are really interested in unnecessary or slow IO activity. If the TIME spent waiting for IOs is significant then we can determine which segment/s Oracle has to go to disk for. See the "Tablespace IO" and "File IO" sections of the ESTAT or STATSPACK reports to get information on which tablespaces / files are servicing the most IO requests, and to get an indication of the speed of the IO subsystem. If the TIME spent waiting for reads is significant then it can be helpful to determine which segment/s Oracle is performing the reads against. The files where the reads are occuring can be found by looking at .


It can also be useful to see which sessions are performing reads and trace them to see if the IOs are expected or not. This statement can be used to see which sessions may be worth tracing:



SELECT sid, total_waits, time_waited FROM v$session_event WHERE event='db file sequential read' and total_waits>0 ORDER BY 3,2;



One can also look at:

Statements with high DISK_READS in Sessions with high "physical reads" in



Undo Tablespace Check


set linesize 150

col username format a18

col sid format 99999

col object_name format a18

select s.username,s.sid,rn.name,rs.rssize/1024/1024 "UsedSize",rs.status,t.used_ublk,t.used_urec,do.object_name

from V$TRANSACTION t,V$SESSION s,V$ROLLNAME rn,V$ROLLSTAT rs,V$LOCKED_OBJECT lo,DBA_OBJECTS do

where t.addr = s.taddr

and t.xidusn = rn.usn

and rn.usn = rs.usn

and t.xidusn = lo.xidusn(+)

and do.object_id = lo.object_id;


Temp Tablespace Check


prompt

prompt +----------------------------------------------------+

prompt TEMP TABLESPACE USAGE BY SESSION

prompt +----------------------------------------------------+


--Temp TS usage by each session:


select b.tablespace

,a.sid,

sum(round(((b.blocks*p.value)/1024/1024),2)) size_mb

from v$session a

,v$sort_usage b

,v$process c

,v$parameter p

where p.name='db_block_size' and a.saddr = b.session_addr and

a.paddr=c.addr

group by b.tablespace,a.sid

order by sum(round(((b.blocks*p.value)/1024/1024),2)) desc







Extract the DDL Scripts for the existing database links:



SELECT

'create 'DECODE(U.NAME,'PUBLIC','public ')'database link 'CHR(10)

DECODE(U.NAME,'PUBLIC',Null, U.NAME'.') L.NAMEchr(10)

'connect to ' L.USERID ' identified by '''

L.PASSWORD''' using ''' L.host ''''

chr(10)';' TEXT

FROM sys.link$ L,

sys.user$ U

WHERE L.OWNER# = U.USER# ;




Please change the oracle directories appropriately:


select 'create or replace directory 'OWNER'.'DIRECTORY_NAME ' as ' ''''DIRECTORY_PATH''''';' from DBA_DIRECTORIES;


How to check database bit like 32bit or 64bit


SELECT distinct('This is a ' (length(addr)*4) '-bit database') "WordSize" FROM v$process;

select PLATFORM_ID, PLATFORM_NAME from v$database;



Check the PROFILE OPTIONS VALUE


SELECT po.profile_option_name "NAME",

po.USER_PROFILE_OPTION_NAME,

decode(to_char(pov.level_id),

‘10001′, ‘SITE’,

‘10002′, ‘APP’,

‘10003′, ‘RESP’,

‘10005′, ‘SERVER’,

‘10006′, ‘ORG’,

‘10004′, ‘USER’, ‘???’) "LEV",

decode(to_char(pov.level_id),

‘10001′, ”,

‘10002′, app.application_short_name,

‘10003′, rsp.responsibility_key,

‘10005′, svr.node_name,

‘10006′, org.name,

‘10004′, usr.user_name,

‘???’) "CONTEXT",

pov.profile_option_value "VALUE"

FROM FND_PROFILE_OPTIONS_VL po,

FND_PROFILE_OPTION_VALUES pov,

fnd_user usr,

fnd_application app,

fnd_responsibility rsp,

fnd_nodes svr,

hr_operating_units org

WHERE po.profile_option_name LIKE ‘%&&profile%’

AND pov.application_id = po.application_id

AND pov.profile_option_id = po.profile_option_id

AND usr.user_id (+) = pov.level_value

AND rsp.application_id (+) = pov.level_value_application_id

AND rsp.responsibility_id (+) = pov.level_value

AND app.application_id (+) = pov.level_value

AND svr.node_id (+) = pov.level_value

AND org.organization_id (+) = pov.level_value

AND decode(to_char(pov.level_id),

‘10001′, ”,

‘10002′, app.application_short_name,

‘10003′, rsp.responsibility_key,

‘10005′, svr.node_name,

‘10006′, org.name,

‘10004′, usr.user_name,

ORDER BY "NAME", pov.level_id, "VALUE";




***************



SELECT po.profile_option_name "NAME",

po.USER_PROFILE_OPTION_NAME,

decode(to_char(pov.level_id),

'10001', 'SITE',

'10002', 'APP',

'10003', 'RESP',

'10005', 'SERVER',

'10006', 'ORG',

'10004', 'USER', '???') "LEV",

decode(to_char(pov.level_id),

'10001', '',

'10002', app.application_short_name,

'10003', rsp.responsibility_key,

'10005', svr.node_name,

'10006', org.name,

'10004', usr.user_name,

'???') "CONTEXT",

pov.profile_option_value "VALUE"

FROM FND_PROFILE_OPTIONS_VL po,

FND_PROFILE_OPTION_VALUES pov,

fnd_user usr,

fnd_application app,

fnd_responsibility rsp,

fnd_nodes svr,

hr_operating_units org

WHERE po.profile_option_name LIKE 'ICX_FORMS_LAUNCHER'

AND pov.application_id = po.application_id

AND pov.profile_option_id = po.profile_option_id

AND usr.user_id (+) = pov.level_value

AND rsp.application_id (+) = pov.level_value_application_id

AND rsp.responsibility_id (+) = pov.level_value

AND app.application_id (+) = pov.level_value

AND svr.node_id (+) = pov.level_value

AND org.organization_id (+) = pov.level_value



*********


SELECT po.profile_option_name "NAME",

po.USER_PROFILE_OPTION_NAME,

decode(to_char(pov.level_id),

'10001', 'SITE',

'10002', 'APP',

'10003', 'RESP',

'10005', 'SERVER',

'10006', 'ORG',

'10004', 'USER', '???') "LEV",

decode(to_char(pov.level_id),

'10001', '',

'10002', app.application_short_name,

'10003', rsp.responsibility_key,

'10005', svr.node_name,

'10006', org.name,

'10004', usr.user_name,

'???') "CONTEXT",

pov.profile_option_value "VALUE"

FROM FND_PROFILE_OPTIONS_VL po,

FND_PROFILE_OPTION_VALUES pov,

fnd_user usr,

fnd_application app,

fnd_responsibility rsp,

fnd_nodes svr,

hr_operating_units org

WHERE po.profile_option_name LIKE '%&&profile%'

AND pov.application_id = po.application_id

AND pov.profile_option_id = po.profile_option_id

AND usr.user_id (+) = pov.level_value

AND rsp.application_id (+) = pov.level_value_application_id

AND rsp.responsibility_id (+) = pov.level_value

AND app.application_id (+) = pov.level_value

AND svr.node_id (+) = pov.level_value

AND org.organization_id (+) = pov.level_value

AND decode(to_char(pov.level_id),

'10001', '',

'10002', app.application_short_name,

'10003', rsp.responsibility_key,

'10005', svr.node_name,

'10006', org.name,

'10004', usr.user_name,

'???') LIKE '%&&username%'

ORDER BY "NAME", pov.level_id, "VALUE";


Find Concurrent manager for a particular concurrent request



select

c.user_name,

a.Request_id,

to_char(a.actual_start_date,'DD-MON-YYYY HH24:MI:SS') "Start",

decode(a.status_code,

'A','Waiting',

'B', 'Resuming',

'C', 'Normal',

'D', 'Cancelled',

'E', 'Error',

'G', 'Warning',

'H', 'On Hold',

'I', 'Normal',

'M', 'No Manager',

'P', 'Scheduled',

'Q', 'Standby',

'R', 'Normal',

'S', 'Suspended',

'T', 'Terminating',

'U', 'Disabled',

'W', 'Paused',

'X', 'Terminated',

'Z', 'Waiting') status_code,

b.user_concurrent_queue_name' - 'b.target_node "queue_name",

a.user_concurrent_program_name

from fnd_concurrent_worker_requests a,

fnd_concurrent_queues_vl b,

fnd_user c

where a.concurrent_queue_id=b.concurrent_queue_id

and a.phase_code='R'

and a.requested_by=c.user_id

and c.user_name='RMANI'

Order by 5;


db session

 SELECT s.sid, s.serial#, p.spid as "OS PID", s.username,

s.module, st.value/100 as "DB Time (sec)",

stcpu.value/100 as "CPU Time (sec)",

round(stcpu.value / st.value * 100,2) as "%CPU"

FROM v$sesstat st, v$statname sn, v$session s,

v$sesstat stcpu, v$statname sncpu, v$process p

WHERE sn.name = 'DB time’

AND st.statistic# = sn.statistic#

AND st.sid = s.sid

AND sncpu.name = 'CPU used by this session’

AND stcpu.statistic# = sncpu.statistic#

AND stcpu.sid = st.sid

AND s.paddr = p.addr

AND s.last_call_et < 1800

AND s.logon_time > (SYSDATE - 240/1440)

AND st.value > 0;

Thursday, November 4, 2021

invalid Object table & Compare

 create table GETSBACK.pre1226invalids as select * from dba_objects where status='INVALID';

select count(*) from GETSBACK.pre1226invalids;

select owner,object_name,object_type,status from dba_objects where status='INVALID' and object_name not in (select object_name from getsback.pre1226invalids where status='INVALID');

 - Apply EBS Patches (US)

export PATCH=20128107

export PATCH_HOME=/orasoft/oraApps/OEL6/cfs/R122/patches/patch_${PATCH}

 

time adpatch defaultsfile=$APPL_TOP/admin/$TWO_TASK/adalldefaults.txt \

logfile=adp${PATCH}.log patchtop=${PATCH_HOME}/${PATCH} \

driver=u${PATCH}.drv workers=64 interactive=yes

 

- Verify applied patches

sqlplus / as sysdba

SELECT DISTINCT bug_number,language,creation_date

      FROM apps.ad_bugs

      WHERE bug_number IN ('20128107')

ORDER BY bug_number,language,creation_date

/

 

- Disable “Maintenance Mode”

On Primary Application Node:

sqlplus -s apps/`tellme apps` @$AD_TOP/patch/115/sql/adsetmmd.sql DISABLE

Friday, August 13, 2021

DB Parameters Validate

 

1.1.1.1         Verify StandBy and FlasBack Parameters

On Primary Database Node as oracle,

$ sqlplus / as sysdba

select NAME ||'='||VALUE from v$parameter

 where NAME in ('db_unique_name',

                'log_archive_config',

                'log_archive_dest_2',

                'log_archive_min_succeed_dest',

                'log_archive_dest_state_1',

                'log_archive_dest_state_2',

                'remote_login_passwordfile',

                'fal_server',

                'standby_file_management');

 

SQL>alter database flashback on;

SQL> select NAME,FLASHBACK_ON from v$database;

SQL> archive log list

select NAME ||'='||VALUE from v$parameter

 where NAME in ('undo_retention',

                'undo_management',

                'db_flashback_retention_target',

                'db_recovery_file_dest',

                'db_recovery_file_dest_size');

Review some Init Parameters

 sqlplus / as sysdba

COLUMN name FORMAT a35 HEADING 'Parameter Name'

COLUMN value FORMAT a110 HEADING 'Value'

SET PAGESIZE 50000 LINES 200

select distinct name,value

from gv$parameter

where name in

('service_names',

'resource_manager_plan',

'shared_pool_size',

'shared_pool_reserved_size',

'job_queue_processes',

'utl_file_dir',

'timed_statistics')

order by 1;

Wednesday, July 14, 2021

Invalid Objects

 select object_type

, object_name
, owner
from dba_objects
where status = 'INVALID'
and owner = 'DEMANTRA'
order by object_type, object_name;



SQL> set pagesize 200 linesize 132
SQL> SELECT owner, object_type, object_name, status
     FROM all_objects
     WHERE status = 'INVALID'
     ORDER BY owner;



SELECT CASE WHEN object_type = 'SYNONYM' AND owner = 'PUBLIC' THEN
    'alter ' || owner || ' ' || DECODE(object_type, 'PACKAGE BODY', 'PACKAGE', object_type) || ' ' || object_name || ' ' || DECODE(object_type, 'PACKAGE BODY', 'COMPILE BODY', 'COMPILE') || ';'
    ELSE
    'alter ' || DECODE(object_type, 'PACKAGE BODY', 'PACKAGE', object_type) || ' ' || owner || '.' || object_name || ' ' || DECODE(object_type, 'PACKAGE BODY', 'COMPILE BODY', 'COMPILE') || ';'
    END "SQL_COMMANDS"
    FROM dba_objects
    WHERE object_type IN ('PACKAGE', 'PACKAGE BODY', 'VIEW', 'PROCEDURE', 'FUNCTION', 'TRIGGER', 'SYNONYM')
    AND status = 'INVALID' 
    ORDER BY DECODE(object_type, 'TRIGGER', '99', '00');



column owner format A9
column object_name format A31
column object_type format A15
column last_ddl_time format A10
spool invalids.lst
select OWNER, OBJECT_NAME,OBJECT_TYPE,LAST_DDL_TIME
from dba_objects where status='INVALID'
order by owner;

Tuesday, July 13, 2021

Thursday, July 8, 2021

You can generate and rebuild all Unusable indexes with the following script

 select 'alter index '||owner||'.'||index_name||' rebuild parallel 8;' from dba_indexes where status = 'UNUSABLE'

union all
select 'alter index '||owner||'.'||index_name||' noparallel;' from dba_indexes where status = 'UNUSABLE';

Sunday, July 4, 2021

Oracle E-Business Suite Release 12 Release-Specific Database Initialization Parameters for 19c

 

Oracle E-Business Suite Release 12  Release-Specific Database Initialization Parameters for 19c

S.No

Release-Specific Database Initialization Parameters for Oracle 19c

Required Parameters

Information about the Parameter

1

compatible = 19.0.0 #MP

EBS

 

2

optimizer_adaptive_plans = TRUE #MP

EBS

 

3

optimizer_adaptive_statistics = FALSE #MP

EBS

 

4

pga_aggregate_limit = 0 #MP

EBS

 

5

temp_undo_enabled = FALSE

EBS

 

6

_pdb_name_case_sensitive = TRUE #MP

EBS

 

7

event='10946 trace name context forever, level 8454144' #MP

EBS

 

8

_optimizer_gather_stats_on_conventional_dml = FALSE #MP

EBS

 

9

_optimizer_use_stats_on_conventional_dml = FALSE #MP

EBS

 

10

optimizer_real_time_statistics = FALSE #MP

EBS

 

Additional Database Initialization Parameters For Oracle E-Business Suite Release 12.2

11

recyclebin = off #MP

EBS

 

12

service_names=%s_dbSid%, <s_patch_service_name or ebs_patch>  # Based on AD/TXK Code level

EBS

 

13

local_listener=%s_dbSid%_LOCAL

EBS

 

14

result_cache_max_size = 600M

EB                S

                         



egrep 'compatible|optimizer_adaptive_plans|optimizer_adaptive_statistics|pga_aggregate_limit|temp_undo_enabled|_pdb_name_case_sensitive|event|_optimizer_gather_stats_on_conventional_dml|_optimizer_use_stats_on_conventional_dml|optimizer_real_time_statistics|recyclebin|service_names|local_listener|result_cache_max_size' intiSID.ora

Saturday, July 3, 2021

EBS DATABASE MULTITENANT CLONE

 s_undo_tablespace=<Source (PDB) system undo tablespace name>

s_db_oh=<Location of new ORACLE_HOME>

s_dbhost=<Target hostname>

s_dbSid=<Target PDB name>

s_pdb_name=<Target PDB name>

s_cdb_name=<Target CDB SID>

s_base=<Base directory for DB Oracle Home>

s_dbuser=<DB User>

s_dbgroup=<DB group> (Not applicable to Windows)

s_dbhome1=<Data directory>

s_display=<Display>

s_dbCluster=false

s_isDBCluster=n

s_dbport=<DB port>

s_port_pool=<Port pool number>



egrep -i 's_undo_tablespace|s_db_oh|s_dbhost|s_dbSid|s_pdb_name|s_cdb_name|s_base|s_dbuser|s_dbgroup|s_dbhome1|s_display|s_dbCluster|s_isDBCluster|s_dbport|s_port_pool'   



$ cd <NEW ORACLE_HOME>/appsutil/clone/bin

$ perl adclonectx.pl \

contextfile=<Source database context file> \

template=<NEW ORACLE_HOME>/appsutil/template/adxdbctx.tmp \

[pairsfile=<Pairs file generated in Section 4.1.2>]




If the pairsfile.txt file is not passed, you will be presented with the following questions:


Provide the values required for creation of the new Database Context file.


Target System Hostname (virtual or normal) [<Current hostname] :


Do you want the inputs to be validated (y/n) [n] ? :


Target Instance is RAC (y/n) [n] : n


Target System CDB Name : <Name of the Container database>


Target System PDB Name : <Name of the EBS PDB database>


Target System Base Directory : <Complete path to the base directory for the target system>


Oracle OS User [<Current OS User>]] :


Oracle OS Group [<Current OS User group] :


Role separation is supported y/n [n] ? : <If the answer to this prompt is 'y', enter values for the next two prompts also>


Specify value for OSOPER group [<Oracle OS Group>] :


Specify value for OSASM group [ ] :


Number of DATA_TOP's on the Target System [<Number of data tops on the source database>] : <Number of data tops for the target database>


Target System DATA_TOP Directory 1 [<data top directory>] : <If there is more than one data top, there will be additional prompts for the remaining data tops>


Specify value for OSBACKUPDBA group [<Oracle OS group>] :


Specify value for OSDGDBA group [<Oracle OS group>] :


Specify value for OSKMDBA group [<Oracle OS group>] :


Specify value for OSRACDBA group [<Oracle OS group>] :


Target System RDBMS ORACLE_HOME Directory[]:


Do you want to preserve the Display [localhost:10.0] (y/n) : n


Target System Display [<Target hostname>:0.0] :


Do you want the target system to have the same port values as the source system (y/n) [y] ? : <If the answer to this prompt is 'n' or if the source port pool is not free on the current node, enter the value for the next prompt>


Target System Port Pool [0-99] : <Port pool>


New context path and file name [<ORACLE_HOME>/appsutil/<CONTEXT_NAME>.xml] :




4.1.4 Configure the Database Technology Stack

Configure the database technology stack copied by running the following steps:


Navigate to <ORACLE_HOME>/appsutil/clone/bin and run Rapid Clone (adcfgclone.pl utility) with the following parameters to configure the database technology stack:

$ perl adcfgclone.pl dbTechStack <Complete path to the target context file>




4.1.5 Create the listener.ora and tnsnames.ora for the Target Database

Create the listener.ora and tnsnames.ora files for the target CDB by running the following commands:

Set the environment.


On UNIX:

$ cd <ORACLE_HOME>/appsutil

$ source ./txkSetCfgCDB.env -dboraclehome=<ORACLE_HOME>

On Windows:

C:\> cd <ORACLE_HOME>\appsutil

C:\> txkSetCfgCDB.cmd dboraclehome=<ORACLE_HOME>

Generate the listener.ora and tnsnames.ora.

$ cd <ORACLE_HOME>/appsutil/bin

$ perl txkGenCDBTnsAdmin.pl -dboraclehome=<ORACLE_HOME> -cdbname=<Name of the target container database> \

-cdbsid=<SID of the target container database> -dbport=<Target DB port> -outdir=$ORACLE_HOME/appsutil/log \

-israc=<yes/no> [-virtualhostname=<virtual hostname>]


where:

Parameter Description

cdbname Name of the target container database.

cdbsid

Oracle SID of the target container database instance.


For single-node database, the value is same as the cdbname.

For Oracle RAC database, it is the Instance name of the target database. israc Provide the value 'yes' for an Oracle RAC database.

Provide the value 'no' for a single-node database. virtualhostname Virtual hostname for the Oracle RAC database. For a single-node database, this parameter should not be used.



Start the listener for the target container database as follows:


On UNIX:

$ cd <ORACLE_HOME>/appsutil/scripts/<CONTEXT_NAME>

$ ./adcdblnctl.sh start <CDB SID>

Monday, June 28, 2021

DB Parameters

 egrep -i 'parameter_value_convert|db_unique_name|db_create_file_dest|db_recovery_file_dest|db_recovery_file_dest_size|control_files|log_archive_max_processes|fal_client|fal_server|standby_file_management|log_archive_config|log_archive_dest_2|valid_for|db_unique_name'


Sunday, April 18, 2021

Script to Check Profile Options Related to Debugging, Tracing, and Logging in EBS 12.2

 Script to Check Profile Options Related to Debugging, Tracing, and Logging in EBS 12.2

SELECT po.user_profile_option_name,

po.profile_option_name "NAME" ,

DECODE (TO_CHAR (pov.level_id), '10001', 'SITE' , '10002', 'APP', '10003', 'RESP',

'10004', 'USER', '???') "LEV",

DECODE (TO_CHAR (pov.level_id) , '10001', '', '10002', app.application_short_name ,

'10003', rsp.responsibility_key, '10004', usr.user_name, '???') "CONTEXT",

pov.profile_option_value "VALUE"

FROM fnd_profile_options_vl po,

fnd_profile_option_values pov,

fnd_user usr,

fnd_application app,

fnd_responsibility rsp

WHERE (upper(po.profile_option_name) like '%DEBUG%' or upper(po.profile_option_name) like

'%TRACE%' or upper(po.profile_option_name) like '%LOG%')

AND pov.application_id = po.application_id

AND pov.profile_option_id = po.profile_option_id

AND usr.user_id(+) = pov.level_value

AND rsp.application_id(+) = pov.level_value_application_id

AND rsp.responsibility_id(+) = pov.level_value

AND app.application_id(+) = pov.level_value

ORDER BY "NAME", pov.level_id, "VALUE"

Wednesday, March 17, 2021

verify the patches

 - Verify applied patches

sqlplus / as sysdba

SELECT DISTINCT bug_number,language,creation_date 

  FROM apps.ad_bugs 

  WHERE bug_number IN ('20128107')

ORDER BY bug_number,language,creation_date

/


  - Disable “Maintenance Mode”

On Primary Application Node:

sqlplus -s apps/`apps` @$AD_TOP/patch/115/sql/adsetmmd.sql DISABLE

applying patches

 


adpatch defaultsfile=$APPL_TOP/admin/$TWO_TASK/adalldefaults.txt  workers=36 logfile=u_18712060.log patchtop=/orasoft/oraApps/OEL6/ccc/R122/Add-On_Localizations/CCC/18712060 driver=u18712060.drv

Monday, March 15, 2021

Patch Applied Query

 

SELECT bug_number,to_char(creation_date,'dd-MON-yyyy hh24:mi:ss') FROM apps.ad_bugs WHERE bug_number IN ('10350522','12539637','20621314','16289505','16541956','22071026','5233248','10231107','5259121','15969486') GROUP BY bug_number,creation_date order by creation_date;

 

Saturday, January 23, 2021

Color Codes

 # Reset

Color_Off='\033[0m'       # Text Reset


# Regular Colors

Black='\033[0;30m'        # Black

Red='\033[0;31m'          # Red

Green='\033[0;32m'        # Green

Yellow='\033[0;33m'       # Yellow

Blue='\033[0;34m'         # Blue

Purple='\033[0;35m'       # Purple

Cyan='\033[0;36m'         # Cyan

White='\033[0;37m'        # White


# Bold

BBlack='\033[1;30m'       # Black

BRed='\033[1;31m'         # Red

BGreen='\033[1;32m'       # Green

BYellow='\033[1;33m'      # Yellow

BBlue='\033[1;34m'        # Blue

BPurple='\033[1;35m'      # Purple

BCyan='\033[1;36m'        # Cyan

BWhite='\033[1;37m'       # White


# Underline

UBlack='\033[4;30m'       # Black

URed='\033[4;31m'         # Red

UGreen='\033[4;32m'       # Green

UYellow='\033[4;33m'      # Yellow

UBlue='\033[4;34m'        # Blue

UPurple='\033[4;35m'      # Purple

UCyan='\033[4;36m'        # Cyan

UWhite='\033[4;37m'       # White


# Background

On_Black='\033[40m'       # Black

On_Red='\033[41m'         # Red

On_Green='\033[42m'       # Green

On_Yellow='\033[43m'      # Yellow

On_Blue='\033[44m'        # Blue

On_Purple='\033[45m'      # Purple

On_Cyan='\033[46m'        # Cyan

On_White='\033[47m'       # White


# High Intensity

IBlack='\033[0;90m'       # Black

IRed='\033[0;91m'         # Red

IGreen='\033[0;92m'       # Green

IYellow='\033[0;93m'      # Yellow

IBlue='\033[0;94m'        # Blue

IPurple='\033[0;95m'      # Purple

ICyan='\033[0;96m'        # Cyan

IWhite='\033[0;97m'       # White


# Bold High Intensity

BIBlack='\033[1;90m'      # Black

BIRed='\033[1;91m'        # Red

BIGreen='\033[1;92m'      # Green

BIYellow='\033[1;93m'     # Yellow

BIBlue='\033[1;94m'       # Blue

BIPurple='\033[1;95m'     # Purple

BICyan='\033[1;96m'       # Cyan

BIWhite='\033[1;97m'      # White


# High Intensity backgrounds

On_IBlack='\033[0;100m'   # Black

On_IRed='\033[0;101m'     # Red

On_IGreen='\033[0;102m'   # Green

On_IYellow='\033[0;103m'  # Yellow

On_IBlue='\033[0;104m'    # Blue

On_IPurple='\033[0;105m'  # Purple

On_ICyan='\033[0;106m'    # Cyan

On_IWhite='\033[0;107m'   # White


Friday, October 2, 2020

ORA-01652: unable to extend temp error, this may be an indication that your temporary tablespace is too small.

When Oracle throws the ORA-01652: unable to extend temp error, this may be an indication that your temporary

tablespace is too small. However, Oracle may throw that error if it runs out of space because of a one-time event, such

as a large index build. You’ll have to decide whether a one-time index build or a query that consumes large amounts

of sort space in the temporary tablespace warrants adding space.

To view the space a session is using in the temporary tablespace, run this query:



 SELECT s.sid, s.serial#, s.username

,p.spid, s.module, p.program

,SUM(su.blocks) * tbsp.block_size/1024/1024 mb_used

,su.tablespace

FROM v$sort_usage su

,v$session s

,dba_tablespaces tbsp

,v$process p

WHERE su.session_addr = s.saddr

AND su.tablespace = tbsp.tablespace_name

AND s.paddr = p.addr

GROUP BY

s.sid, s.serial#, s.username, s.osuser, p.spid, s.module,

p.program, tbsp.block_size, su.tablespace

ORDER BY s.sid;

If you determine

Monday, January 20, 2020

catupgrd.sql spooled file

In the case of a manual upgrade, were there errors reported in the spooled output of catupgrd.sql?

    No:
    -----
    Proceed to check 4.

    Yes:
    -----
    Work through the following checks

The following commands can be used to scan the output file for possible problems:
grep "PL/SQL" .log
grep -i "ora-" .log
grep -i "mgr-" .log
grep -i "oci-" .log
grep -i "sp2-" .log
grep -i "sp1-" .log
grep -i "sp3-" .log
grep -i "pls-" .log
grep -i error .log
grep -i severe .log
grep -i fatal .log
grep -i fail .log
grep -i stop .log
Or you can use the following command:
egrep -i '^pl/sql|^ora-|^mgr-|^oci-|^sp3-|^sp2-|^sp1-|^pls-|^error|^severe|^fatal|^fail|^stop' .log

Thursday, December 26, 2019

How to Configure : Configure Parallel Concurrent Processing

Configure Parallel Concurrent Processing

Check prerequisites for setting up Parallel Concurrent Processing
Parallel Concurrent Processing (PCP) spans two or more nodes. If you need to add nodes, follow the relevant instructions in My Oracle Support Knowledge Document 1383621.1, Cloning Oracle Applications Release 12 with Rapid Clone.

Note:  If you are planning to implement a shared Application tier file system, refer to My Oracle Support Knowledge Document 1375769.1.1, Sharing the Application Tier File System in Oracle E-Business Suite Release 12, for configuration steps. If you are adding a new Concurrent Processing node to the application tier, you will need to set up load balancing on the new application by repeating steps in Section 4.7.2.
Set Up PCP
Edit the applications context file via Oracle Applications Manager, and set the value of the variable APPLDCP to ON.

Source the Applications environment.

Execute AutoConfig by running the following command on all concurrent processing nodes:
$
      $INST_TOP/admin/scripts/adautocfg.sh
Check the tnsnames.ora and listener.ora configuration files, located in $INST_TOP/ora/10.1.2/network/admin. Ensure that the required FNDSM and FNDFS entries are present for all other concurrent nodes.

Restart the Applications listener processes on each application tier node.

Log on to Oracle E-Business Suite Release 12 using the SYSADMIN account, and choose the System Administrator Responsibility. Navigate to the Install > Nodes screen, and ensure that each node in the cluster is registered.

Verify that the Internal Monitor for each node is defined properly, with correct primary node specification, and work shift details. For example, Internal Monitor: Host1 must have primary node as host1. Also ensure that the Internal Monitor manager is activated: this can be done from Concurrent > Manager > Administrator.

Set the $APPLCSF environment variable on all the Concurrent Processing nodes to point to a log directory on a shared file system.

Set the $APPLPTMP environment variable on all the CP nodes to the value of the UTL_FILE_DIR entry in init.ora on the database nodes. (This value should be pointing to a directory on a shared file system.)

Set profile option 'Concurrent: PCP Instance Check' to OFF if database instance-sensitive failover is not required. By setting it to 'ON', a concurrent manager will fail over to a secondary Application tier node if the database instance to which it is connected becomes unavailable for some reason.
Set Up Transaction Managers
Shut down the application services (servers) on all nodes

Shut down all the database instances cleanly in the Oracle RAC environment, using the command:
SQL>shutdown immediate;
Edit $ORACLE_HOME/dbs/_ifile.ora. Add the following parameters:
_lm_global_posts=TRUE
_immediate_commit_propagation=TRUE
Start the instances on all database nodes, one by one.

Start up the application services (servers) on all nodes.

Log on to Oracle E-Business Suite Release 12 using the SYSADMIN account, and choose the System Administrator responsibility. Navigate to Profile > System, change the profile option ‘Concurrent: TM Transport Type' to ‘QUEUE', and verify that the transaction manager works across the Oracle RAC instance.

Navigate to Concurrent > Manager > Define screen, and set up the primary and secondary node names for transaction managers.

Restart the concurrent managers.

If any of the transaction managers are in deactivated status, activate them from Concurrent > Manager > Administrator.
Set Up Load Balancing on Concurrent Processing Nodes
Edit the applications context file through the Oracle Applications Manager interface, and set the value of Concurrent Manager TWO_TASK (s_cp_twotask) to the load balancing alias (_balance>).

Note:  Windows users must set the value of "Concurrent Manager TWO_TASK" (s_cp_twotask context variable) to the instance alias.

Execute AutoConfig by running $INST_TOP/admin/scripts/adautocfg.sh on all concurrent nodes.
Note: For further details on Concurrent Processing, refer to the Product Information Center (PIC) (Doc ID 1304305.1).

Saturday, September 28, 2019

mailer

set linesize 100
col Component format a40
SELECT component_name as Component, component_status as Status FROM fnd_svc_components WHERE component_type = 'WF_MAILER';


set linesize 150
set pagesize 9999
col COMPONENT_NAME format a50
col COMPONENT_STATUS format a50
select SC.COMPONENT_TYPE, SC.COMPONENT_NAME, FND_SVC_COMPONENT.Get_Component_Status(SC.COMPONENT_NAME) COMPONENT_STATUS from FND_SVC_COMPONENTS SC order by 1, 2;

workflow status

select fcq.USER_CONCURRENT_QUEUE_NAME Container_Name, DECODE(fcp.OS_PROCESS_ID,NULL,'Not
Running',fcp.OS_PROCESS_ID) PROCID,
fcq.MAX_PROCESSES TARGET,
fcq.RUNNING_PROCESSES ACTUAL,
fcq.ENABLED_FLAG ENABLED,
fsc.COMPONENT_NAME,
fsc.STARTUP_MODE,
fsc.COMPONENT_STATUS
from APPS.FND_CONCURRENT_QUEUES_VL fcq, APPS.FND_CP_SERVICES fcs, APPS.FND_CONCURRENT_PROCESSES
fcp, fnd_svc_components fsc
where fcq.MANAGER_TYPE = fcs.SERVICE_ID
and fcs.SERVICE_HANDLE = 'FNDCPGSC'
and fsc.concurrent_queue_id = fcq.concurrent_queue_id(+)
and fcq.concurrent_queue_id = fcp.concurrent_queue_id(+)
and fcq.application_id = fcp.queue_application_id(+)
and fcp.process_status_code(+) = 'A'
order by fcp.OS_PROCESS_ID, fsc.STARTUP_MODE

The following SQL script can be run in sqlplus connected as apps/ to determine the profile Option settings in the Database opposed to checking them in the Application:

The following SQL script can be run in sqlplus connected as apps/ to determine the profile Option settings in the Database opposed to checking them in the Application:
set linesize 155;
set pagesize 200;
set verify off;
col Profile format a20;
 col Level format a14;
col Value format a10;
col App format a3;
col Responsibility format a30;
col USER format a8;
col UPDATED_BY format a8;
select distinct fpo.profile_option_name Profile,
      fpov.profile_option_value Value,
      decode(fpov.level_id, 10001,'Site',
                       10002,'Application',
                       10003,'Responsibility',
                       10004,'User',
                       10005,'Server',
                       10006,'Organization')"LEVEL",
      fa.application_short_name App,
      fr.responsibility_name Responsibility,
      fu.user_name "USER"
from fnd_profile_option_values fpov,
fnd_profile_options fpo,
fnd_application fa,
fnd_responsibility_vl fr,
fnd_user fu,
fnd_logins fl
where fpo.profile_option_id=fpov.profile_option_id
and fa.application_id(+)=fpov.level_value
and fr.application_id(+)=fpov.level_value_application_id
and fr.responsibility_id(+)=fpov.level_value
and fu.user_id(+)=fpov.level_value
and fl.login_id(+) = fpov.LAST_UPDATE_LOGIN
and fpov.profile_option_value is not Null
and fpo.profile_option_name in
('APPS_FRAMEWORK_AGENT', 'WF_MAIL_WEB_AGENT', 'APPS_WEB_AGENT',
'APPS_SERVLET_AGENT', 'ICX_FORMS_LAUNCHER') order by 1,3;

https values


col PROFILE_OPTION_NAME format a60
set lines 2000 pages 2000
SELECT A.PROFILE_OPTION_NAME,B.PROFILE_OPTION_VALUE FROM FND_PROFILE_OPTIONS A,FND_PROFILE_OPTION_VALUES B
where a.PROFILE_OPTION_ID=b.PROFILE_OPTION_ID and b.profile_option_value like 'http:/%';

dblinks


set lines 100
set pages 100
column db_link format a40
column host format a100
select distinct owner from dba_db_links;
select OWNER,DB_LINK,CREATED from dba_db_links;
select OWNER,DB_LINK,CREATED,HOST from dba_db_links;
drop database link &n;



select Host,ACL from dba_network_acls;


find xx*  -type l | xargs ls –ltr