Find below few useful scripts for  Performance  Management::


# Important MOS notes for TRACING:

There are several ways to trace a particular session.

REFER : General SQL_TRACE / 10046 trace Gathering Examples (Note 1274511.1)

REFER : How To Collect 10046 Trace (SQL_TRACE) Diagnostics for Performance Issues (Note 376442.1)

REFER : How To Use SQL Trace And TKPROF For Performance Issues with EBusiness Suite (Note 980711.1)



# sqlplus settings

set linesize 1000

set pagesize 600

set time on

set timing on

define _editor=vi

set sqlprompt "&_user@&_CONNECT_IDENTIFIER> "


# Increase PGA

ALTER SYSTEM SET pga_aggregate_target='4G' SCOPE=BOTH;


# To create Snapshot

EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;


# 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 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 < 1800 -- active within last 1/2 hour

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

ORDER BY st.value;


# 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;



# Find Hidden Parameters::

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


 SELECT

   a.ksppinm  "Parameter",

   a.ksppdesc "Description",

   b.ksppstvl "Session Value",

   c.ksppstvl "Instance Value"

FROM

   x$ksppi a,

   x$ksppcv b,

   x$ksppsv c

WHERE

   a.indx = b.indx

   AND 

   a.indx = c.indx

   AND

   a.ksppinm LIKE '/_opt%' escape '/' ;

   

# Compile schema::


EXEC DBMS_UTILITY.compile_schema(schema => 'SCOTT');


EXEC UTL_RECOMP.recomp_serial('&schema_name');


select 

   'ALTER ' || OBJECT_TYPE || ' ' ||

   OWNER || '.' || OBJECT_NAME || ' COMPILE;'

from

   dba_objects

where

   status = 'INVALID'

and

   object_type in ('PACKAGE','FUNCTION','PROCEDURE','VIEW','SYNONYM') ;

   


## Find Type of SQL from v$sqlarea ::


select sql_fulltext,executions,loads,first_load_time,rows_processed,

  optimizer_mode,parsing_schema_name,module,

  DECODE(command_type,

2, 'INSERT',

3, 'SELECT',

6, 'UPDATE',

7, 'DELETE',

26, 'LOCK',

42, 'DDL',

44, 'COMMIT',

47, 'PL/SQL BLOCK',

command_type) CommandType 

  from v$sqlarea 

where 

command_type != 3 

and upper(sql_fulltext) like '%IE_SE_EXPENSES%'

order by first_load_time desc

/


########################################################

PL/SQL  block to increase CPU usage .  For testing only. 

########################################################


DECLARE

L_n NUMBER;

BEGIN

WHILE (TRUE)

LOOP

L_ n:= dbms_random.random();

END LOOP;

END;

/

########################################################

This code above will burn all CPU. Use it wisely.

########################################################


#######################################

Script to insert 1M rows into a table:

########################################


CREATE TABLE test_table TABLESPACE USERS AS

  ( SELECT LEVEL id, 

         SYSDATE+DBMS_RANDOM.VALUE(-1000, 1000) date_value, 

         DBMS_RANDOM.string('A', 20) text_value

  FROM dual

  CONNECT BY LEVEL <= 1000000);

  

Ever Hit with ORA-46981 in Oracle EBS Environment ?




Recently when I was tasked to do a cloning of my production Oracle Apps instance to a target single-node server, 

I hit a dead-end with the below error message::


SYS@CDBUAT> conn apps@UATEBS

Enter password:

ERROR:

ORA-46981: Access to service  from <DB-Host-IP> was denied.


CDBUAT is my CDB and UATEBS is my PDB. 


Source instance is  2 node RAC DB with 2 node application tier servers.

Target server is single-node, hosting DB and Application services together. 


DB was restored using disk based snapshot backup / restore tools  or RMAN. 


Believe me, there were no hits in metalink oracle support for this error.  Un-expected !!!.  No-one faced this error?


The db service is up.  Even after several restart, the error remained the same. 


I tried to connect to db by setting 10.1.2 oracle home environment, but error remained the same. 

Note that, this is a single node instance, that is, both DB and Application tier are at same node. 


Whenever I end up with a dead-end, I would always recall the correct procedure for the activity and compare with the procedures, which I have done. 


This is one of my humble suggestions. This has helped me a lot of times. 


One small step which I missed to perform  is,

 "Cleaning up the fnd_nodes" table. 


 This is not mentioned in the standard Cloning document available in MOS. 

 Might have been mentioned at the standard cloning procedure document, but not at Doc: 2560690.1 . 

 

 As I doubted, the fnd_nodes table still holding the node_names of the source host names along with current/target hostname. 

 I ran the exec fnd_nodes.setup_clean ; commit ;

 

 Ran the adcfgclone.pl with dbTechStack.

 Created TNS files.

 Restarted the listener. 

 

 Then, voila, the magic happened. 


Able to login to PDB as apps user without any hindrance.


  Find below few useful scripts for  Performance  Management:: # Important MOS notes for TRACING: There are several ways to trace a particul...