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.


 


::|| RMAN COLD BACKUP AND RESTORE ||::


I'm going to show, how to execute cold backup using rman and restore the DB using cold backup. 


Note:

1. This exercise is done on 11.2.0.2 database with archivelog enabled.

2. FRA need to be configured. 

3. Controlfile auto backup must be enabled. 


Quick Question: How to ensure all data are restored ?

Answer: 

 Before executing the cold backup, let me create a dummy table and insert a marker transaction on it.  After restore, this marker transaction should be there. 


Let's start:-


Step 1: Create a dummy table and insert a marker transaction.


Step 2: Restart the db to mount mode.



Step 3: Take cold backup using RMAN. Ensure controlfile autobackup is enabled. 





With this step, the RMAN Cold Backup activity is completed. 

Quick Question:  whey there's an error message at the end of RMAN log ?


Now, I will start with restoring this cold backup and ensure it is working fine. Remember to verify the marker transaction at the end of restore. 


For this restoration exercise, I'm going to remove control, data and log files from my file system and then restore with the cold backup.





Step 4: Restart the database from mount mode to nomount mode.


Step 5: Start restore of controlfiles.



Step 6: Mount the Database.



Step 7: Restore the cold backup.



Step 8: Open the DB with resetlogs and confirm marker transaction is present. 

                                    

Feedbacks, updates, advises are welcome.

Ho


  Some times it will be very hard to List down what are the Incident rules we defined in our OEM Application. Particularly, during IT Audit, we may need to provide the list of Incident Rulesets and details about individual rules.

Copy and paste Incident Rulesets/Rules from OEM 12c is not possible.

OEM 13c has an export/import option, but that will give you an xml file. You need to run the show by converting it to your favorite document.

This script will come in handy to get all details about OEM Incident rules.

SELECT

  *

FROM

  (

    SELECT

      r.RULESET_ID,

      r.RULE_ID,

      r.RULE_NAME,

      r.RULE_NAME_NLSID,

      r.CREATED_BY,

      r.DESCRIPTION,

      r.DESCRIPTION_NLSID,

      r.RESOURCE_BUNDLE,

      r.RULE_TYPE,

      r.RULE_ORDER,

      r.IS_REFERED_ACTION,

      r.REFERED_RULE_ID,

      r.IS_ENABLED,

      r.IS_BROKEN,

      r.CREATED_DATE,

      r.LAST_UPDATED_BY,

      r.LAST_UPDATED_DATE,

      r.RL_EXPRESSION,

      r.Event_Class,

      r.PRIV_MODE,

      r.Display_Order,

      ru.Subscribed_Users

    FROM

      (

        SELECT

          EmRulesEO.RULESET_ID,

          EmRulesEO.RULE_ID,

          EmRulesEO.RULE_NAME,

          EmRulesEO.RULE_NAME_NLSID,

          EmRulesEO.CREATED_BY,

          EmRulesEO.DESCRIPTION,

          EmRulesEO.DESCRIPTION_NLSID,

          EmRulesEO.RESOURCE_BUNDLE,

          EmRulesEO.RULE_TYPE,

          EmRulesEO.RULE_ORDER,

          EmRulesEO.IS_REFERED_ACTION,

          EmRulesEO.REFERED_RULE_ID,

          EmRulesEO.IS_ENABLED,

          EmRulesEO.IS_BROKEN,

          EmRulesEO.CREATION_DATE AS CREATED_DATE,

          EmRulesEO.LAST_UPDATED_BY,

          EmRulesEO.LAST_UPDATED_DATE,

          EmRulesEO.RL_EXPRESSION,

          EmrulesEO.Event_Class,

          EmrulesEO.PRIV_MODE,

          To_Number(EmRuleSetsEO.ruleset_order                   + (row_number() over (partition

          BY EmRulesEO.RULESET_ID order by EmRulesEO.RULE_ORDER))/1000) AS

          Display_Order

        FROM

          Em_Rules Emruleseo,

          (

            SELECT

              RULESET_ID,

              rownum AS RULESET_ORDER

            FROM

              (

                SELECT

                  RULESET_ID

                FROM

                  EM_RULE_SETS

                WHERE

                  IS_VISIBLE=1

                ORDER BY

                  Ruleset_Order

              )

          )

          EmRuleSetsEO

        WHERE

          Emrulesetseo.Ruleset_Id = Emruleseo.Ruleset_Id

        ORDER BY

          ruleset_order ASC,

          RULE_ORDER ASC

      )

      r

    LEFT OUTER JOIN

      (

        SELECT

          acts.rule_id AS rule_id,

          em_incident_rules.table_to_string(CAST(COLLECT(notif.recipient) AS SMP_EMD_LONG_STRING_ARRAY)) AS Subscribed_Users

        FROM

          sysman.em_rule_cond_actions acts,

          sysman.em_rule_basic_notifications notif

        WHERE

          acts.COND_ACTION_ID = notif.COND_ACTION_ID

        GROUP BY

          rule_id

      )

      ru

    ON

      r.rule_id = ru.rule_id

  )

  QRSLT

WHERE

  RULESET_ID = 7

ORDER BY

  RULE_ORDER ASC




After a long time.....

I'm decided to blog .

Here's my original script to find who are all owning System administrator responsibility.

select DISTINCT(PAPF.PERSON_ID), fu.user_name, fu.end_date, frt.responsibility_name,
PAPF.FULL_NAME,
furga.start_date "RESPONSIBILITY_START_DATE",
furga.end_date "RESPONSIBILITY_END_DATE"
from FND_USER_RESP_GROUPS_ALL furga,
fnd_user fu,
fnd_responsibility_tl frt,
PER_ALL_PEOPLE_F PAPF
where
FU.EMPLOYEE_ID=PAPF.PERSON_ID
--fu.employee_id IN (SELECT DISTINCT(PERSON_ID) FROM PER_ALL_PEOPLE_F )
AND fu.user_id=furga.user_id
and frt.responsibility_id=furga.responsibility_id
and furga.responsibility_id=20420
AND FRT.LANGUAGE='US'
-- GROUP BY FU.EMPLOYEE_ID
ORDER BY 1 ;


I've added DISTINCT(PAPF.PERSON_ID) to mitigate the duplicate entries in the result. Since PER_ALL_PEOPLE_F  table sometimes contain duplicate entry for a given person_id, when joining with other tables, we'll get duplicate entries.




A nice story about RMAN.


          The story begins,  when one of my associate DBAs did an RMAN restoration & recovery 2 days back. 

           Here, I need to mention the exact date, time and the backup schedules also. 

Similar to every organizations' backup policy, we too take full backup (FB) on saturday night and Incremental backup (IB) on other days. 

    Now the main story:

          The DBA restores the  Prod DB backup on DEV DB and recovers it such a way, that DEV mush have data upto 30th Dec 2016. He started his work on 2nd Jan 2017, after the day's IB.

          The command executed was:

rman auxiliary =/ << EOF
run {
set until time 'TO_DATE('2016-12-30 22:00:00', 'YYYY-MM-DD HH24:MI:SS')';
allocate auxiliary channel c1 type disk;
allocate auxiliary channel c2 type disk;
allocate auxiliary channel c3 type disk;
allocate auxiliary channel c4 type disk;
duplicate target database to 'TEST'
BACKUP LOCATION '' NOFILENAMECHECK
pfile=$ORACLE_HOME/dbs/initDEV.ora;
}
EXIT;
EOF

Have you found any problems or  syntax errors on this script ?
If yes, then Hats off to You. You are a seasoned DBA.

The restoration went fine except few errors messages.

RMAN-01009: syntax error: found "integer": expecting one of: "newline, ;"
RMAN-01009: syntax error: found "auxiliary": expecting one of: "channel"

The DBA thought there was an issue with "auxiliary channel" definition. Since the restoration and later recovery are went fine without any warnings/errors, he let the process continue. 

The work completed and he returned the DB to end-user. 

Next morning, he received a customer complaint saying, there are latest data in  the DB, which are older than 30th Dec 2016. 

Now, comes the another problem. 

There's no log file saved for the RMAN recovery op, to verify and prove everything that happen is  right.

The whole team were breaking  their head to see what went  wrong. 

Good  that the restored DB is DEV. We had a day's time to rectify the issue. 

But how could rman can restore till 2nd Jan '17 , while the command set the restoration point till "30th Dec 2016, 2200hrs" ?

I'll post the root cause on  tomorrow's post. 




Funny Linux Commands

% cat “food in cans”
cat: can’t open food in cans

% nice man woman
No manual entry for woman.

% “How would you rate Quayle’s incompetence?
Unmatched “.

% Unmatched “.
Unmatched “.

% [Where is Jimmy Hoffa?
Missing ].

% ^How did the sex change operation go?^
Modifier failed.

% make love
Make: Don’t know how to make love. Stop.

% sleep with me
bad character

% got a light?
No match.

% man: why did you get a divorce?
man:: Too many arguments.

% !:say, what is saccharine?
Bad substitute.

$ drink matter
matter: cannot create

Thanks to :  quora.com

Completed My First RAC project.



My birthday on this year is an unforgettable day!!!.

Yes. I've achieved one of my dreams today.

For the first time on my career, I've configured an Oracle 11gR2 RAC on an E-BIZ environment.

****************************************************
[oraprod@ec-pdb01 bin]$ ./rconfig /u01/rdbms/product/11.2.0/dbhome_1/assistants/rconfig/sampleXMLs/ConvertToRAC_AdminManaged.xml

Converting Database "RAC1" to Cluster Database. Target Oracle Home: /u01/rdbms/product/11.2.0/dbhome_1. Database Role: PRIMARY.
Setting Data Files and Control Files
Adding Database Instances
Adding Redo Logs
Enabling threads for all Database Instances
Setting TEMP tablespace
Adding UNDO tablespaces
Adding Trace files
Setting Flash Recovery Area
Updating Oratab
Creating Password file(s)
Configuring Listeners
Configuring related CRS resources
Starting Cluster Database

Operation Succeeded

/u01/rdbms/product/11.2.0/dbhome_1

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

I would like to say "Thank You" to  Kishoreji (akr14feb) for making me an Apps DBA ,
SriHari (Guruji) for Guiding me on difficult times,
Chandru  for  providing me a turning-point on life and all my friends.
A special Thanks to my wife Vasanthakala for her support.
Without them I would be a dust.

Reset VM Manager Portal "admin" user password

Guys,




This is how I reset the 'admin' user password of my Oracle VM Manager Installation.



1. There's a "register" link under the password field in Login page. Click that link and register a new user with simple password like 123456.

2. Login as sys or OVS user using sqlplus and connect to the DB.

3. select account_name, password from ovs.ovs_user where account_name='';

4. Copy the password field output.

5. update ovs.ovs_user set password='' where account_name='';

6. Commit and voila, you can now login with admin username and password will be 123456;



Isn't it Simple?

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