R12 Useful Scripts

Oracle Apps R12 Importance Scripts List :-
Location of below scripts:-
$ cd $ADMIN_SCRIPTS_HOME
adautocfg.sh - run autoconfig
adstpall.sh - stop all services
adstrtal.sh - start all services
adapcctl.sh - start/stop/status Apache only
adformsctl.sh - start/stop/status OC4J Forms
adformsrvctl.sh - start/stop/status Forms server in socket mode
adoacorectl.sh - start/stop/status OC4J oacore
adoafmctl.sh - start/stpp/status OC4J oafm
adopmnctl.sh - start/stop/status opmn
adalnctl.sh - start/stop RPC listeners (FNDFS/FNDSM)
adcmctl.sh - start/stop Concurrent Manager
gsmstart.sh - start/stop FNDSM
jtffmctl.sh - start/stop Fulfillment Server
adpreclone.pl - Cloning preparation script
adexecsql.pl - Execute sql scripts that update the profiles in an AutoConfig run
java.sh - Call java executable with additional args, (used by opmn, Conc. Mgr)

Sehedule Concurrent Requests




Oracle SYSADMIN related Concurrent Requests:



1) Gather Schema Statistics

 
 Schedule: Every Weekend (Preferably on every Sat 6:00 pm server time). If this is not sufficient (if performance is not good), it can be done 2/3 times a week.

OR, 
Weekend for ALL schemas and 2/3 times during the week for only few important schemas where in there is heavy insert / update / delete happening.



Parameters:

Schema name: ALL

Parallel Worker: Number of CPUs + 2

Estimate Percent: 30

Other parameters: Default



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run





2) Purge Concurrent Request and/or Manager Data

 
Schedule: Every day, nighttime, say 11:00 PM Server time



Parameters:

Age=30 (Purge concurrent request data older than 30 days)

Other parameters: Default



Note: Age parameter needs to be agreed with Business / Customer.



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



3) Purge Concurrent Request and/or Manager Data

 
 Schedule: Every day night time, say 11:30 Server time



Parameters:

Count: 5

Program Application: Application Object Library

Program: Workflow Background Process

Other parameters: Default



Note: Count Parameter needs to be agreed with Business / Customer.



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



4) Workflow Background Process

 
 Schedule: Every 10 min



Parameters:

Process Deferred: Yes

Process Timeout: No



How to submit: Login to Applications using SYSADMIN account, then navigate to Oracle Applications Manager responsibility, then navigate to Workflow Manager, then use “Submit Request for “ facility (top – right hand side) (Select “Background Engines” from drop down)



5) Workflow Background Process

 Schedule: Every 60 min



Parameters:

Process Deferred Yes

Process Timeout: Yes



How to submit: Login to Applications using SYSADMIN account, then navigate to Oracle Applications Manager responsibility, then navigate to Workflow Manager, then use “Submit Request for “ facility (top – right hand side) (Select “Background Engines” from drop down)



6) Workflow Control Queue Cleanup

 Schedule: Every day, night time / early morning hours



Parameters: Default



How to submit: Login to Applications using SYSADMIN account, then navigate to Oracle Applications Manager responsibility, then navigate to Workflow Manager, then use “Submit Request for “ facility (top – right hand side) (Select “Control Queue Cleanup” from drop down)


7) Purge Obsolete Workflow Runtime Data

 Schedule: Every weekend



Parameters:

Age: 30

Other parameters: Default



Note: Age parameter needs to be agreed with Business / Customer.



How to submit: Login to Applications using SYSADMIN account, then navigate to Oracle Applications Manager responsibility, then navigate to Workflow Manager, then use “Submit Request for “ facility (top – right hand side) (Select “Purge” from drop down)



8) Synchronize WF LOCAL tables

 
 Schedule: Every day, night time / early morning hours



Parameters: Default



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run
Note: As per metalink id 1158212.1, after E-business version 11.5.10 this request generally does not need to be run.



9) OAM Applications Dashboard Collection

 
 Schedule: Every 30 min



Parameters: Default



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



10) Purge Signon Audit data

 Schedule: Can no schedule needs to be run manually, say every week Monday / Friday morning.



Parameters: Date (By default system date)



Note: Most of customer wants this date to be, 2 to 3 months old



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



Note for DBA’s: There will be check box “Increment data parameter for each run” which must be checked.





11) Purge Debug Log

 
 Schedule: Every day / weekend.



Parameters: Date (By default system date)



Note: Most of customer wants this date to be, 2 weeks to 3 month old



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



Note for DBA’s: There will be check box “Increment data parameter for each run” which must be checked.



12) Resend Failed/Error Workflow Notifications

 
 Schedule: Run every 6 hours.



Parameters: ERROR / FAILED (One request for each parameter)



How to submit: Login to Applications using SYSADMIN account, navigate to System Administrator responsibility, then navigate to Requests > Run



Note for DBA’s: As this request takes date as parameter, it cannot be scheduled easily. You may have to run this physically on one particular day of week, say Monday morning.



DB Jobs


Purge old snapshots from PREFSTAT schema

ORA-00955

EMCA Fails With Error "ORA-00955: name is already used by an existing object" For SYNONYM MGMT_AVAILABILITY (Doc ID 470246.1)

Applies to:

Enterprise Manager for Oracle Database - Version 11.1.0.6 to 11.2.0.3 [Release 11.1 to 11.2]
Information in this document applies to any platform.
***Checked for relevance on 27-Oct-2011***


Symptoms

While recreating the database control in 11g database, it fails as below errors in emca_repos_create_timestamp.log file


Dec 9, 2007 10:41:26 AM oracle.sysman.emcp.EMReposConfig createRepository
CONFIG: ORA-00955: name is already used by an existing object

oracle.sysman.assistants.util.sqlEngine.SQLFatalErrorException: ORA-00955: name is already used by an existing object

at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeImpl(SQLEngine.java:1500)
at oracle.sysman.assistants.util.sqlEngine.SQLEngine.executeScript(SQLEngine.java:874)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java:270)
at oracle.sysman.assistants.util.sqlEngine.SQLPlusEngine.executeScript(SQLPlusEngine.java:311)
at oracle.sysman.emcp.EMReposConfig.createRepository(EMReposConfig.java:492)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:218)
at oracle.sysman.emcp.EMReposConfig.invoke(EMReposConfig.java:147)
at oracle.sysman.emcp.EMConfig.perform(EMConfig.java:221)
at oracle.sysman.emcp.EMConfigAssistant.invokeEMCA(EMConfigAssistant.java:534)
at oracle.sysman.emcp.EMConfigAssistant.performConfiguration(EMConfigAssistant.java:1214)
at oracle.sysman.emcp.EMConfigAssistant.statusMain(EMConfigAssistant.java:518)
at oracle.sysman.emcp.EMConfigAssistant.main(EMConfigAssistant.java:467)
Dec 9, 2007 10:41:26 AM oracle.sysman.emcp.EMReposConfig invoke
SEVERE: Error creating the repository

CREATE PUBLIC SYNONYM MGMT_AVAILABILITY FOR MGMT_AVAILABILITY
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

Cause

Related Bug 6111734  EMCA THROWS CONFIG: ORA-00955 CREATE PUBLIC SYNONYM MGMT_AVAILABILITY FOR MGMT_A


Solution

As a workaround,

Drop the Repository using RepManager


<ORACLE_HOME>/sysman/admin/emdrep/bin/RepManager <hostname> <listener_port> <sid> -action drop

Note : This will not remove the configuration files, but only the repository related objects from the database.Also, the database will be put in Quiescing mode when RepManager is ran.
Refer Note 375946.1 Running EMCA Results in Database quiesce And No New Connections or Operations Can Be Performed During the DB Control Repository Creation

If above RepManager fails with conflicts for any other SYNONYM then manually drop the DBConsole repository and objects referring to Note 278100.1 How To Drop, Create And Recreate DB Control In A 10g Database


 Fileload fails with ORA-00955: name is already used by an existing object (Doc ID 801963.1)


Applies to:

Oracle Agile PLM Framework - Version 9.2.2.4 to 9.3.0.0 [Release 9.2.0.0 to 9.3.0.0]
Information in this document applies to any platform.

Symptoms

Fileload fails with ORA-00955: name is already used by an existing object when running by multithreaded mode.

Fact:
Auto Purge Enabled is set to "Yes"
File Version Keep is set to "0"

Steps To Reproduce:
1. Login to JavaClient as admin
2. Goto Admin tab > System Settings > Viewers & Files
3. Make configuration as below and Save changes:
- Auto Purge Enabled = Yes
- File Version Keep = 0
4. Create index file to load files. (File can be URL. Create about 10 lines)
5. Login to JavaClient with user that have Fileload privilege
6. Goto Tools > Fileload
7. Set Index File
8. Change "Number Of Dedicated Threads" to a number greater than 1. (i.e. 10)
9. Set Log File Directory and OK

Cause

Code bug Bug 8413389; Root cause:purging involved creation of temporary table.the name for temporary table was not threadsafe

Solution

Upgrade to Agile PLM 9.3.0.1 or above.
To workaround the issue, please follow below instructions:

1. Login to JavaClient as admin
2. Goto Admin tab > System Settings > Viewers & Files
3. Change File Version Keep to "1" and Save
4. Run Fileload.
5. After Fileload is completed, change back File Version Keep to "0".
 

PT scripts

The Monitoring of predefined events that generates a message or warning when a certain threshold has been exceeded. This is done in an effort to ensure that an issue doesn’t become a problem.

The database monitoring is required for the following reason:
– Smooth running of production
– Keeping an eye on development
– Database performance
– In Support of an SLA (service level agreement)

Types of DB Monitoring
1. Status
2. Performance
3. Trend Analysis

Status Monitoring:
Monitor the current status of an event and reports when it exceeds a defined threshold.
Database:
– Database/Listener
– Monitor Alert. log Message on regular basis.
– Check all last night backup is successful.
– Tablespace/Datafiles full or Fragmented.
– Identify bad growth of segment.
– Identify at least 1 top resource consuming query
– Monitor Locking
– Check Maximum Extent about to be reached.
– Redo log Tracking
– UNDO and Temp Segment Free space.
– Monitor Running Job
– Tracking DB User/Session Information.
– Important Object Information

OS:
– SGA/PGA information
– CPU Usage Information
– Memory Utilization
– Disk Utilization

Performance Monitoring:

Monitor a defined set of performance statistics. This is done in an effort to maintain the best possible DB performance.

Trend Analysis Monitoring:
Collect the historical data for specified events and analyze these data on schedule basis to reveal any potential problems. For Example watching growth of data in a tablespace and predicting when it will fill.
Apart from the above checklist some of the other checklist a DBA are using. It is depend on the requirement. I am mentioning here some of the related query and scripts. It is fully related to DB Monitoring Purpose.
Note: Keep every one informed specially your senior or Junior DBA, System Admin, Manager and do not forget to document very important update.
Database Information:

Track OS Reboot Time:
net statistics server
systeminfo | find “Up Time” — to find system last uptime
systeminfo | find “System Boot Time” — to find system boot time
net statistics workstation | find “Statistics” Workstation Statistics for \\A5541TAG-WKS –perticular workstation statistics

Database and Instance Last start time:
SELECT to_char(startup_time,’DD-MON-YYYY HH24:MI:SS’) “DB Startup Time”
FROM sys.v_$instance;
SELECT SYSDATE-logon_time “Days”, (SYSDATE-logon_time)*24 “Hours”
from sys.v_$session where sid=1;

Track Database Version:
SELECT * from v$version;
Track Database Name and ID information:
SELECT DBID, NAME FROM V$DATABASE;‎
Track Database Global Name information:
SELECT * FROM GLOBAL_NAME;‎

Track Database Instance name:
SELECT INSTANCE_NAME FROM V$INSTANCE;‎
Track Database Host Details:
SELECT UTL_INADDR.GET_HOST_ADDRESS, UTL_INADDR.GET_HOST_NAME FROM DUAL;

Track Database Present Status:
SELECT created, RESETLOGS_TIME, Log_mode FROM V$DATABASE;
DB Character Set Information:
Select * from nls_database_parameters;

Track Database default information:
Select username, profile, default_tablespace, temporary_tablespace from dba_users;

Track Total Size of Database:
select a.data_size+b.temp_size+c.redo_size “Total_Size (GB)”
from ( select sum(bytes/1024/1024/1024) data_size
from dba_data_files ) a, ( select nvl(sum(bytes/1024/1024/1024),0) temp_size
from dba_temp_files ) b, ( select sum(bytes/1024/1024/1024) redo_size
from sys.v_$log ) c;

Total Size of Database with free space:
Select round(sum(used.bytes) / 1024 / 1024/1024 ) || ‘ GB’ “Database Size”,round(free.p / 1024 / 1024/1024) || ‘ GB’ “Free space”
from (select bytes from v$datafile
union all
select bytes from v$tempfile
union all
select bytes from v$log) used, (select sum(bytes) as p from dba_free_space) free group by free.p;
Track Database Structure:
select name from sys.v_$controlfile
/
select group#,member from sys.v_$logfile
/
Select F.file_id Id, F.file_name name, F.bytes/(1024*1024) Mbyte,
decode(F.status,’AVAILABLE’,'OK’,F.status) status, F.tablespace_name Tspace
from sys.dba_data_files F
order by tablespace_name;

Tablespace/Datafile/Temp/UNDO Information:

Track Tablespace Used/Free Space:
SELECT /* + RULE */ df.tablespace_name “Tablespace”, df.bytes / (1024 * 1024) “Size (MB)”,
SUM(fs.bytes) / (1024 * 1024) “Free (MB)”, Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) “% Free”, Round((df.bytes – SUM(fs.bytes)) * 100 / df.bytes) “% Used”
FROM dba_free_space fs, (SELECT tablespace_name,SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) df
WHERE fs.tablespace_name (+) = df.tablespace_name
GROUP BY df.tablespace_name,df.bytes
UNION ALL
SELECT /* + RULE */ df.tablespace_name tspace,
fs.bytes / (1024 * 1024), SUM(df.bytes_free) / (1024 * 1024), Nvl(Round((SUM(fs.bytes) – df.bytes_used) * 100 / fs.bytes), 1), Round((SUM(fs.bytes) – df.bytes_free) * 100 / fs.bytes)
FROM dba_temp_files fs, (SELECT tablespace_name,bytes_free,bytes_used
FROM v$temp_space_header
GROUP BY tablespace_name,bytes_free,bytes_used) df
WHERE fs.tablespace_name (+) = df.tablespace_name
GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
ORDER BY 4 DESC;

Track all Tablespaces with free space < 10%
Select a.tablespace_name,sum(a.tots/1048576) Tot_Size, sum(a.sumb/1024) Tot_Free, sum(a.sumb)*100/sum(a.tots) Pct_Free, ceil((((sum(a.tots) * 15) – (sum(a.sumb)*100))/85 )/1048576) Min_Add
from (select tablespace_name,0 tots,sum(bytes) sumb
from dba_free_space a
group by tablespace_name
union
Select tablespace_name,sum(bytes) tots,0 from dba_data_files
group by tablespace_name) a group by a.tablespace_name
having sum(a.sumb)*100/sum(a.tots) < 10
order by pct_free;

Track Tablespace Fragmentation Details:
Select a.tablespace_name,sum(a.tots/1048576) Tot_Size,
sum(a.sumb/1048576) Tot_Free, sum(a.sumb)*100/sum(a.tots) Pct_Free,
sum(a.largest/1024) Max_Free,sum(a.chunks) Chunks_Free
from ( select tablespace_name,0 tots,sum(bytes) sumb,
max(bytes) largest,count(*) chunks
from dba_free_space a
group by tablespace_name
union
select tablespace_name,sum(bytes) tots,0,0,0 from dba_data_files
group by tablespace_name) a group by a.tablespace_name
order by pct_free;

Track Non-Sys owned tables in SYSTEM Tablespace:
SELECT owner, table_name, tablespace_name FROM dba_tables WHERE tablespace_name = 'SYSTEM' AND owner NOT IN ('SYSTEM', 'SYS', 'OUTLN');

Track Default and Temporary Tablespace:
SELECT * FROM DATABASE_PROPERTIES where PROPERTY_NAME like '%DEFAULT%';
select username,temporary_tablespace,default_tablespace from dba_users where username='HRMS'; –for Particular User
Select default_tablespace,temporary_tablespace,username from dba_users; –for All Users
Track DB datafile used and free space:
SELECT SUBSTR (df.NAME, 1, 40) file_name,dfs.tablespace_name, df.bytes / 1024 / 1024 allocated_mb, ((df.bytes / 1024 / 1024) – NVL (SUM (dfs.bytes) / 1024 / 1024, 0)) used_mb,
NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb
FROM v$datafile df, dba_free_space dfs
WHERE df.file# = dfs.file_id(+)
GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes,dfs.tablespace_name
ORDER BY file_name;

Track Datafile with Archive Details:
SELECT NAME, a.status, DECODE (b.status, 'Active', 'Backup', 'Normal') arc, enabled, bytes, change#, TIME ARCHIVE FROM sys.v_$datafile a, sys.v_$backup b WHERE a.file# = b.file#;
Track Datafiles with highest I/O activity:
Select * from (select name,phyrds, phywrts,readtim,writetim
from v$filestat a, v$datafile b
where a.file#=b.file#
order by readtim desc) where rownum 0
ORDER BY elapsed_seconds;
Track Running RMAN backup status:
SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) “%_COMPLETE”
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE ‘RMAN%’ AND OPNAME NOT LIKE ‘%aggregate%’
AND TOTALWORK != 0 AND SOFAR != TOTALWORK;

Monitor Import Rate:
Oracle Import Utility usually takes hours for very large tables and we need to track the execution of Oracle Import Process. Below option can help you monitor the rate at which rows are being imported from a running import job.
select substr(sql_text,instr(sql_text,’into “‘),30) table_name,
rows_processed, round((sysdate-to_date(first_load_time,’yyyy-mm-dd hh24:mi:ss’))*24*60,1) minutes,
trunc(rows_processed/((sysdate-to_date(first_load_time,’yyyy-mm-dd hh24:mi:ss’))*24*60)) rows_per_minute
from sys.v_$sqlarea
where sql_text like ‘insert %into “%’ and command_type = 2 and open_versions > 0;
Database SGA Report:

Monitor SGA Information:
SELECT SUM(VALUE)/1024/1024 “Size in MB” from SYS.v_$sga;
select NAME, BYTES from v$sgastat order by NAME;

Monitor Shared Pool Information:
select to_number(value) shared_pool_size, sum_obj_size, sum_sql_size, sum_user_size,
(sum_obj_size + sum_sql_size+sum_user_size)* 1.3 min_shared_pool
from (select sum(sharable_mem) sum_obj_size
from v$db_object_cache where type ‘CURSOR’),
(select sum(sharable_mem) sum_sql_size from v$sqlarea),
(select sum(250 * users_opening) sum_user_size from v$sqlarea), v$parameter
where name = ‘shared_pool_size’;

Monitor PGA Information:
Select st.sid “SID”, sn.name “TYPE”, ceil(st.value / 1024 / 1024/1024) “GB”
from v$sesstat st, v$statname sn where st.statistic# = sn.statistic#
and sid in (select sid from v$session where username like UPPER(‘hrms’))
and upper(sn.name) like ‘%PGA%’ order by st.sid, st.value desc;

Monitor CPU Usage Information:
select ss.username, se.SID, VALUE/100 cpu_usage_seconds
from v$session ss, v$sesstat se, v$statname sn where se.STATISTIC# = sn.STATISTIC#
and NAME like ‘%CPU used by this session%’ and se.SID = ss.SID
and ss.status=’ACTIVE’ and ss.username is not null order by VALUE desc;

Disk I/O Report:
WITH totreadwrite AS (SELECT SUM (phyrds) phys_reads, SUM (phywrts) phys_wrts FROM v$filestat)
SELECT NAME, phyrds, phyrds * 100 / trw.phys_reads read_pct,
phywrts, phywrts * 100 / trw.phys_wrts write_pct
FROM totreadwrite trw, v$datafile df, v$filestat fs
WHERE df.file# = fs.file# ORDER BY phyrds DESC;

IO Usage for a Query:
select b.sql_text “Statement “, a.Disk_reads “Disk Reads”, a.executions “Executions”,
a.disk_reads/decode(a.executions,0,1,a.executions) “Ratio”,c.username
from v$sqlarea a, v$sqltext_with_newlines b,dba_users c
where a.parsing_user_id = c.user_id and a.address=b.address and a.disk_reads>100000
order by a.disk_reads desc,b.piece;

Display the System write batch size:
SELECT kviival write_batch_size
FROM x$kvii
WHERE kviidsc = ‘DB writer IO clump’ OR kviitag = ‘kcbswc’

Monitor Disk I/O Contention:
select NAME, PHYRDS “Physical Reads”,
round((PHYRDS / PD.PHYS_READS)*100,2) “Read %”, PHYWRTS “Physical Writes”,
round(PHYWRTS * 100 / PD.PHYS_WRTS,2) “Write %”, fs.PHYBLKRD+FS.PHYBLKWRT “Total Block I/O’s” from ( select sum(PHYRDS) PHYS_READS, sum(PHYWRTS) PHYS_WRTS
from v$filestat ) pd, v$datafile df, v$filestat fs
where df.FILE# = fs.FILE#
order by fs.PHYBLKRD+fs.PHYBLKWRT desc;
DB Locks/Blocks/Blocker Details:

Track Block session in oracle 9i/10g
‎select s1.username || ‘@’ || s1.machine || ‘ ( SID=’ || s1.sid || ‘ ) is blocking ‘ || s2.username || ‘@’ || s2.machine || ‘ ( SID=’ || s2.sid || ‘ ) ‘ AS blocking_status 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;
select do.object_name, row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
dbms_rowid.rowid_create(1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)
from gv$session s, dba_objects do
where sid = 543 and s.ROW_WAIT_OBJ# = do.OBJECT_ID;
For detail description of blocking you can run this on your Oracle-Home
oracle-home\rdbms\admin\utllockt.sql
Select process,sid, blocking_session from v$session where blocking_session is not null; –in 10g

Track Locked Session & Blocked:
PROMPT Blocked and Blocker Sessions
select /*+ ORDERED */ blocker.sid blocker_sid, blocked.sid blocked_sid ,
TRUNC(blocked.ctime/60) min_blocked, blocked.request
from (select *from v$lock
where block != 0 and type = ‘TX’) blocker, v$lock blocked
where blocked.type=’TX’ and blocked.block = 0 and blocked.id1 = blocker.id1;

Track Database Lock:
Select /*+ ORDERED */ l.sid, l.lmode,
TRUNC(l.ctime/60) min_blocked, u.name||’.'||o.NAME blocked_obj
from (select * from v$lock
where type=’TM’ and sid in (select sid
from v$lock where block!=0)) l, sys.obj$ o, sys.user$ u
where o.obj# = l.ID1 and o.OWNER# = u.user#;

Track the Session Waiting for Lock:
SELECT holding_session bsession_id, waiting_session wsession_id, b.username busername, a.username wusername, c.lock_type TYPE, mode_held, mode_requested, lock_id1, lock_id2
FROM sys.v_$session b, sys.dba_waiters c, sys.v_$session a
WHERE c.holding_session = b.sid AND c.waiting_session = a.sid;

Track Blocker Details:
SELECT sid, serial#, username, osuser, machine
FROM v$session
WHERE sid IN (select sid from v$lock
where block != 0 and type = ‘TX’);

Users/Sessions/Processes Details:
 


Average Wait Time for Particular Event:

SELECT EVENT, TOTAL_WAITS, TOTAL_TIMEOUTS, TIME_WAITED, round(AVERAGE_WAIT,2) “Average Wait”
from v$system_event order by TOTAL_WAITS;
Sessions Waiting On A Particular Wait Event:
SELECT count(*), event
FROM v$session_wait
WHERE wait_time = 0 AND event NOT IN (‘smon timer’,'pipe get’,'wakeup time manager’, ‘pmon timer’,'rdbms ipc message’, ‘SQL*Net message from client’)
GROUP BY event ORDER BY 1 DESC;
Track Logon time of DB user and OS user:
Select to_char(logon_time,’dd/mm/yyyy hh24:mi:ss’),osuser,status,schemaname,machine from v$session where type !=’BACKGROUND’; ‎

Track all Session User Details:
select sid, serial#,machine, status, osuser,username from v$session where username!=’NULL’;
Track Active Session User Details:
SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time FROM V$Session WHERE Status= ‘ACTIVE’ AND UserName IS NOT NULL;

Track Active User Details:
SELECT s.inst_id, s.sid, s.serial#, p.spid, s.username, s.program FROM gv$session s JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id WHERE s.type != ‘BACKGROUND’;
Report OS Process ID for each session:
SELECT ses.username || ‘(‘ || ses.sid || ‘)’ users, acc.owner owner, acc.OBJECT OBJECT, ses.lockwait, prc.spid os_process
FROM v$process prc, v$access acc, v$session ses
WHERE prc.addr = ses.paddr AND ses.sid = acc.sid;
Show Username and SID/SPID with Program Name:
select sid,name,value from v$spparameter where isspecified=’TRUE’;‎
SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time FROM V$Session
WHERE Status= ‘ACTIVE’ AND UserName IS NOT NULL; –to find active session
SELECT s.inst_id, s.sid, s.serial#, p.spid, s.username, s.program –active users details
FROM gv$session s JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE s.type != ‘BACKGROUND’;

Track Current Transaction in Database:
‎‎select a.sid, a.username, b.xidusn, b.used_urec, b.used_ublk from v$session a, v$transaction b
where a.saddr = b.ses_addr;‎

Important Object Information:

 Database Object Information:
Select owner,object_type,count(*) from dba_objects Where owner not IN (‘SYS’,'MDSYS’,'CTXSYS’,'HR’,'ORDSYS’,'OE’,'ODM_MTR’,'WMSYS’,'XDB’,'QS_WS’, ‘RMAN’,'SCOTT’,'QS_ADM’,'QS_CBADM’, ‘ORDSYS’,'OUTLN’,'PM’,'QS_OS’,'QS_ES’,'ODM’,'OLAPSYS’,'WKSYS’,'SH’,'SYSTEM’,'ORDPLUGINS’,'QS’,'QS_CS’)
Group by owner,object_type order by owner;
Query to Find 5 largest object in Database:
SELECT * FROM (select SEGMENT_NAME, SEGMENT_TYPE, BYTES/1024/1024/1024 GB, TABLESPACE_NAME from dba_segments order by 3 desc ) WHERE ROWNUM = sysdate – 7
Track Mviews Not Refreshed since last Week:
Select mview_name from user_mviews where LAST_REFRESH_DATE < sysdate – 7;

Long running Concurrent Request in Apps R12


Step 1 : Check Concurrent Request ID of long running concurrent request from front end
Step 2 : Find SID, SERIAL# and SPID by running SQL (given below)
Step 3 : Enable event 10046 trace with level 12 using oradebug ( for 15-20 minute)
Step 4 : Disable trace (once you are happy with trace size)
Step 5 : Convert raw trace to TKPROF using various sort options like fchela, prsela, execpu
Step 6 : Check TKPROF out file to find root cause of slow concurrent request

.
Step 1 : Check Request ID from Find Concurrent request

 screen (In my case Request ID is 2355)


Step 2 : Run below command to find SPID, provide concurrent request ID (2355 in my case) when prompted

SELECT a.request_id, d.sid, d.serial# ,d.osuser,d.process , c.SPID
FROM apps.fnd_concurrent_requests a,
apps.fnd_concurrent_processes b,
v$process c,
v$session d
WHERE a.controlling_manager = b.concurrent_process_id
AND c.pid = b.oracle_process_id
AND b.session_id=d.audsid
AND a.request_id = &Request_ID
AND a.phase_code = ‘R’;


REQUEST_ID SID SERIAL# OSUSER PROCESS SPID
—————-
2355 514 28 applmgr 17794 1633. .

Step 3.1 : Check and confirm SPID on Database Node
oraclevis11i@onlineappsdba>ps-ef | grep 1633
ovis11i 1633 1 0 13:30:43 ? 0:03 oraclevis11i (LOCAL=NO)


Step 3.2 : Set OSPID (1633 in my case) for ORADEBUG
SQL> oradebug setospid 1633

Oracle pid: 68, Unix process pid: 1633, image: oraclevis11i@onlineappsdba

Step 3.3 : Enable trace for 10046 event with level 12
 
SQL> oradebug event 10046 trace name context forever, level 12


Step 3.4 : Locate Trace file as
 

SQL>oradebug tracefile_name
/oracle/apps/vis11idb/10.2.0/admin/vis11i_onlineappsdba/udump/vis11i_ora_1633.trc
Wait for 15-20 minutes

Step 4 : Disable trace
 
SQL> oradebug event 10046 trace name context off


Step 5: Create tkprof file like

tkprof ‘/oracle/ apps/ vis11idb/ 10.2.0/ admin/ vis11i_onlineappsdba/ udump/ vis11i_ora_1633.trc’ ’/oracle/ apps/ vis11idb/ 10.2.0/ admin/ vis11i_onlineappsdba/ udump/ tkprof_1633.txt’ explain=apps/[apps_passwd] fchela …


Step 6 : Check TKPROF file to find root cause of slow concurrent request
.
SQL Script to Troubleshoot a long-running concurrent request
.

set term on
set feedback on
set echo on
set arraysize 4
set linesize 200
set pages 9999
set underline =;
column username format A15
column sid format 9990 heading SID
column type format A4
column lmode format 990 heading ‘HELD’
column request format 990 heading ‘REQ’
column id1 format 9999990
column id2 format 9999990
column sql_text format a100
column name format a80
break on id1 skip 1 dup
undefine v_request_id
define v_request_id
undefine v_spid
define v_spid
undefine v_sid
define v_sid
spool vj_concurrent_monitor.lst


Prompt Enter the concurrent_request_id
Accept v_request_id


prompt checking requests
select oracle_process_id from fnd_concurrent_requests where request_id=’&v_request_id’;


Prompt Enter the operating system oracle process id for this concurrent request
accept v_spid
 

Prompt Getting the sid
SELECT SID,SERIAL#,LOGON_TIME FROM V$SESSION WHERE PADDR IN
(SELECT ADDR FROM V$PROCESS WHERE SPID=’&v_spid’);


prompt Enter the session id for this concurrent request
accept v_sid
 

prompt memory usage for this session
SELECT A.SID,A.USERNAME,B.VALUE,c.name FROM V$SESSION a,V$SESSTAT B,V$STATNAME C WHERE A.SID=B.SID
AND B.STATISTIC#=C.STATISTIC# AND C.NAME like’%memor%’ and a.sid=’&v_sid’;


prompt resource usage for this session
SELECT A.SID,A.USERNAME,B.VALUE,c.name FROM V$SESSION a,V$SESSTAT B,V$STATNAME C WHERE A.SID=B.SID
AND B.STATISTIC#=C.STATISTIC# and a.sid=’&v_sid’ order by b.value;


prompt this session waited on
select sid,event,wait_time,state from v$session_wait where sid=’&v_sid’ order by wait_time;


prompt current sql executing by this session
select a.sid,b.sorts,b.executions,b.loads,b.parse_calls,b.disk_reads,
b.buffer_gets,b.rows_processed,C.sql_text from v$session a,v$sqlarea b,V$SQLTEXT C
where a.sql_address=b.address and b.address=c.address and a.sid=’&v_sid’;


prompt sql which is taking more than 3mb in shared pool
 

prompt nosql should take morethan 1mb in shared pool.
 

prompt please ask the developers to tune the following sql statements
 

select name,
namespace,type,sharable_mem/(1024*1024) sharablemem,loads,executions,locks,pins,kept from v$db_object_cache
where SHARABLE_MEM>3000000;


prompt sort segments using by this session
 
SELECT s.username,s.sid,s.osuser,s.process,s.machine,u.extents, u.blocks,u.tablespace FROM v$session s, v$sort_usage u
WHERE s.saddr=u.session_addr order by extents;
and s.sid=’&v_sid’;


prompt current temp segments free in this instance
 
SELECT tablespace_name, extent_size, total_extents, used_extents, free_extents, max_used_size FROM v$sort_segment;


prompt total system events at this time
select event,total_waits waits, total_timeouts timeouts, time_waited total_time from v$system_event order by total_waits;


prompt latch contention if thery is any
SELECT latch#, name, gets, misses, sleeps FROM v$latch WHERE sleeps>0 ORDER BY sleeps ;


prompt the latch which is sleeping
select name, sleeps,latch# from v$latch_children where sleeps>4 order by sleeps;

spool off
clear columns
clear breaks

Table Locks


TO 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.


ORA-16009


ORA-16009: remote archive log destination must be a STANDBY database 

Cause: The database associated with the archive log destination service name is other than the required STANDBY type database. Remote archival of redo log files is not allowed to non-STANDBY database instances. 

Action: Take the necessary steps to create the required compatible STANDBY database before retrying the ARCHIVE LOG processing. 


To check the database, run this query:

SQL> select database_role, open_mode from v$database;

PHYSICAL STANDBY MOUNTED

ERROR 1396 (HY000): Operation ALTER USER failed for 'Mysql'@'%'

 This MySQL error — ERROR 1396 (HY000): Operation ALTER USER failed for 'Mysql'@'%' — means that MySQL cannot find the user ...