Wednesday, June 1, 2011

Exadata Performance Monitoring | ASH Report

Script is to get Essence of AWR.

it takes last 24 Hour snapshot and shows statistics of Queries which has elapsed time more than 1 Hours. which query used offloading and bytes returned by Exadata cell. (which can be customize).
It also shows Top wait class & 40 Hot objects by Physical Reads.

set linesize 250
set numwidth 20
set pagesize 555
set serveroutput off;
SET ECHO OFF;
set termout on;
set verify off;
set recsep off;
col TEXT FOR A30
col ELAPSED_TIME_SEC for 99999999
col objects for a50
col INST for 9999
col ITL_WT FOR 9999999
COL PHY_WRIT FOR 9999999999
COL ROW_LCK_WT FOR 999999999
COL ELAPSED_TIME FOR 999999999999
COL CPU_TIME FOR 99999999
COL EXECUTIONS FOR 9999999999
COL PX_SERVERS FOR 99999999999
COL DISK_READ_BYTES FOR 999999999999999
COL DISK_WRITE_BYTES FOR 999999999999999
COL ROWS_PROCESSED FOR 9999999999999

--SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF;
undefine MIN_SNAP
undefine MAX_SNAP

col MAX_SNAP new_value MAX_SNAP
col MIN_SNAP new_value MIN_SNAP

---PROMPT "USE THIS WHEN SNAPSHOT TAKEN BY EVERY HALF HOUR"
---SELECT MAX(SNAP_ID) MAX_SNAP,MIN(SNAP_ID) MIN_SNAP FROM ---DBA_HIST_SNAPSHOT
---WHERE BEGIN_INTERVAL_TIME > (SYSDATE - 1) - 4/ 24
---AND END_INTERVAL_TIME <= (SYSDATE) - 3/ 24 ORDER BY 1;

PROMPT "USE THIS WHEN SNAPSHOT IS TAKEN EVERY 1 HOUR"
SELECT MAX(SNAP_ID) MAX_SNAP,MIN(SNAP_ID) MIN_SNAP FROM DBA_HIST_SNAPSHOT
WHERE BEGIN_INTERVAL_TIME > (sysdate -1) - 4/24
and BEGIN_INTERVAL_TIME <= (SYSDATE) - 3/24 ORDER BY 1;

--SET VARIFY OFF;
set verify off;
SET TERMOUT ON;
SPOOL /home/oracle/scripts/monitor/HM_repot.txt;
prompt " snapshot between &&MIN_SNAP and &&MAX_SNAP"

SELECT END_INTERVAL_TIME as START_TIME FROM DBA_HIST_SNAPSHOt WHERE SNAP_ID=&&MIN_SNAP AND ROWNUM= 1;
SELECT END_INTERVAL_TIME as END_TIME FROM DBA_HIST_SNAPSHOt WHERE SNAP_ID=&&MAX_SNAP and rownum=1;

PROMPT *****************************************************************
prompt *********SQLs with elapsed time more then 1 hour*****************
PROMPT *****************************************************************


SELECT sql_id,
text,
elapsed_time,
CPU_TIME,
EXECUTIONS,
PX_SERVERS,
DISK_READ_BYTES,
DISK_WRITE_BYTES,
IO_INTERCONNECT_BYTES,
OFFLOAD_ELIGIBLE_BYTES,
CELL_SMART_SCAN_ONLY_BYTES,
FLASH_CACHE_READS,
ROWS_PROCESSED
--AVG_PX_SERVER
FROM (SELECT x.sql_id,
SUBSTR ( dhst.sql_text, 1, 30) text,
ROUND ( x.elapsed_time / 1000000,0)  elapsed_time,
ROUND ( x.cpu_time / 1000000,0)  CPU_TIME,
--ROUND ( x.elapsed_time / 1000000, 3) elapsed_time,
--ROUND ( x.cpu_time / 1000000, 3) cpu_time_sec,
x.executions_delta       EXECUTIONS,
ROUND (X.DISK_READ_BYTES/1048576,0)        DISK_READ_BYTES,
ROUND (X.DISK_WRITE_BYTES/1048576,0)       DISK_WRITE_BYTES,
ROUND (X.IO_INTERCONNECT_BYTES/1048576,0)  IO_INTERCONNECT_BYTES,
ROUND (X.OFFLOAD_ELIGIBLE_BYTES/1048576,0) OFFLOAD_ELIGIBLE_BYTES,
X.FLASH_CACHE_READS                        FLASH_CACHE_READS,
ROUND (X.cell_smart_scan_only_BYTES/1048576,0)  CELL_SMART_SCAN_ONLY_BYTES,
(x.ROWS_PROCESSED) ROWS_PROCESSED,
(X.PX_SERVERS) PX_SERVERS,
--ROUND(X.PX_SERVERS/X.executions_delta,0) AVG_PX_SERVER,
row_number () OVER (PARTITION BY x.sql_id ORDER BY 0) rn
FROM dba_hist_sqltext dhst,
(SELECT dhss.sql_id                       sql_id,
SUM (dhss.cpu_time_delta)                 cpu_time,
SUM (dhss.elapsed_time_delta)             elapsed_time,
SUM (dhss.executions_delta)               executions_delta,
SUM (dhss.PHYSICAL_READ_BYTES_DELTA)      DISK_READ_BYTES,
SUM (dhss.PHYSICAL_WRITE_BYTES_DELTA)     DISK_WRITE_BYTES,
SUM (dhss.IO_INTERCONNECT_BYTES_DELTA)    IO_INTERCONNECT_BYTES,
SUM (dhss.IO_OFFLOAD_ELIG_BYTES_DELTA)    OFFLOAD_ELIGIBLE_BYTES,
SUM (dhss.OPTIMIZED_PHYSICAL_READS_DELTA) FLASH_CACHE_READS,
SUM (dhss.IO_OFFLOAD_RETURN_BYTES_DELTA)  cell_smart_scan_only_BYTES,
SUM (dhss.ROWS_PROCESSED_DELTA)      ROWS_PROCESSED,
SUM (dhss.PX_SERVERS_EXECS_DELTA) PX_SERVERS
FROM dba_hist_sqlstat dhss
WHERE dhss.snap_id IN
(SELECT snap_id
FROM dba_hist_snapshot
--WHERE SNAP_ID > 1865 AND SNAP_ID<= 1889)
WHERE SNAP_ID > &&MIN_SNAP AND SNAP_ID<= &&MAX_SNAP)
--comment BELOW line if want to include current executions.
--AND dhss.executions_delta > 0
GROUP BY dhss.sql_id) x
WHERE x.sql_id = dhst.sql_id
AND ROUND ( x.elapsed_time / 1000000, 3) > 3600)
WHERE rn = 1 ORDER BY ELAPSED_TIME DESC;

PROMPT *****************************************************************
PROMPT ********WAIT_CLASS AND COUNTS / NOTE " NULL VALUE IS CPU"********
PROMPT *****************************************************************

select wait_class, count(*) cnt from dba_hist_active_sess_history
WHERE SNAP_ID > &&MIN_SNAP AND SNAP_ID<= &&MAX_SNAP
group by wait_class_id, wait_class
order by 2;

PROMPT *****************************************************************
prompt *********   Top 40 Objects by Physical Read     *****************
PROMPT *****************************************************************

SELECT * FROM (
SELECT do.OWNER||'.'||do.OBJECT_NAME||'..['||do.OBJECT_TYPE||']' AS OBJECTS,
DHSS.INSTANCE_NUMBER AS INST,
SUM(DHSS.LOGICAL_READS_DELTA) LOGICAL_READ,
SUM(DHSS.PHYSICAL_READS_DELTA) PHY_READ,
SUM(DHSS.PHYSICAL_WRITES_DELTA) PHY_WRIT,
SUM(DHSS.ITL_WAITS_DELTA) ITL_WT,
SUM(DHSS.ROW_LOCK_WAITS_DELTA) ROW_LCK_WT
from dba_hist_seg_stat DHSS, DBA_OBJECTS DO
WHERE SNAP_ID > &&MIN_SNAP AND SNAP_ID<= &&MAX_SNAP
--WHERE DHSS.SNAP_ID > 20135 AND DHSS.SNAP_ID<= 20183
AND DHSS.OBJ#=DO.OBJECT_ID
group by do.OWNER||'.'||do.OBJECT_NAME||'..['||do.OBJECT_TYPE||']',DHSS.INSTANCE_NUMBER
order BY PHY_READ DESC
) WHERE ROWNUM <=40;
SPOOL off;
EXIT;

Wednesday, April 13, 2011

space alert on filesystem

#!/bin/ksh
LOG=/export/home/space.log
cat /dev/null > $LOG
df -g | sort -rnk 4 | grep -vE '^-|Free|proc' | awk '{sub (/%/,"",$4);print $4 "\t" $7}' | while rea
d output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
#echo $usep
#echo $partition
if [ $usep -ge 70 ]; then
echo "Alert :$usep% used on $partition on $(hostname) \n" >> $LOG
fi
done
####################
if [[ -s $LOG ]]; then
#echo "sending mail"
mailx -s "space alert on $(hostname)" jignesh.kankrecha@xxx.com < $LOG
else
#echo "not sending"
fi;

Thursday, April 7, 2011

Oracle output into excel sheet

Hi All

this is the proto-type format of shell script embedded with SQL script , which output into a excel sheet.
=========================================
#!/bin/ksh
echo $ORACLE_HOME
myfile=/home/oracle/awr/perf.sql
emailfile=/home/oracle/awr/MY_TEST_FILE.xls
echo $myfile
echo $emailfile
$ORACLE_HOME/bin/sqlplus -s xxx/yyy@conn_identifier @$myfile
cat $emailfile | uuencode $emailfile | mailx -s "report" jignesh.kankrecha@jpmchase.com
exit;

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

####################################
put $myfile which is /home/oracle/awr/perf.sql in below format
####################################
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF;
set linesize 125
set numwidth 10
set pagesize 50
col TEXT FOR A30
col ELAPSED_TIME_SEC for 99999999
SET ECHO OFF;
SPOOL MY_TEST_FILE.xls;
--your SQL STATEMENT HERE;
spool off;
exit;
####################################

Wednesday, March 23, 2011

generate AWR automatic

hmm so , there was a performance problem in my prod server,
which pushed me to create a baseline of whole month and we never had it. To create that i needed AWR report of every day , every hour which made it even hard for me to take snapshot of it.

To create AWR manually needs a lot of times and obviously LABOR.

so i created my favorite script which is derived from BASH shell , where i had aix 5.1 and never had bash 3.x , which dont allowed `seq` in for loop.

so i wrote in (ksh). which is as below.

#!/bin/ksh
if [ $# != 4 ]
then
echo "Syntax awr_generation.sh dbid instanceId startsnapid endsnapid"
exit 1
fi
l_dbid=$1
l_instid=$2
l_start_snapid=$3
let l_end_snapid=$4-1
i=${l_start_snapid}
until [[ $i = $l_end_snapid ]];
do
let l_next_snapid=$i+1;
l_awr_log_file="/home/oracle/awr/awrrpt_${2}_${i}_${l_next_snapid}.log"
sqlplus -s / as sysdba << EOF set head off set pages 0 set lines 132 set echo off set feedback off spool $l_awr_log_file SELECT output FROM TABLE (dbms_workload_repository.awr_report_html
($l_dbid,$l_instid,$i,$l_next_snapid)
);
spool off
EOF
let i=i+1
done

Saturday, October 9, 2010

Golden Gate on ASM

I  also wrote latest post  Goldengate on ASM / RAC  , which is step by step configuration of GG on Grid Infrastructure.


Create the parameter file for the Primary Extract group

Its setup for 2 Node RAC , THREADS will be 2.
ggsci>>ADD EXTRACT E_X, TRANLOG, THREADS 2, BEGIN NOW
ggsci>>ADD EXTTRAIL /u01/ggate/TRAIL/ts, EXTRACT E_X

ggsci>>edit params ./GLOBALS
GGSCHEMA GGS
CHECKPOINTTABLE GGS.CKPT

ggsci>>DBLOGIN USERID ggs, PASSWORD test
ADD CHECKPOINTTABLE GGS.CKPT

sqlplus / as sysdba
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER SYSTEM SWITCH LOGFILE;

Configure tnsentry as +ASM alias and password file.

ggsci>>edit params E_X
SETENV (ORACLE_SID=abc)
USERID ggsuser, PASSWORD ggs_tmp1
EXTTRAIL /u01/ggate/TRAIL/ts
DISCARDFILE ./dirout/E_X.dsc, APPEND, MEGABYTES 10
TRANLOGOPTIONS ASMUSER SYS@+ASM, ASMPASSWORD system
--GETTRUNCATES
DYNAMICRESOLUTION
--TRANLOGOPTIONS FETCHCHAINEDUPDATES
ddl include mapped objname xxx.*;
TABLE xxx.*;
TABLEEXCLUDE xxx.USER_ACTIVITY_TRACE;

Create the parameter file for the Data pump group

ggsci>>ADD EXTRACT P_x,EXTTRAILSOURCE /u01/ggate/TRAIL/ts
ggsci>>ADD RMTTRAIL /u01/ggate/TRAIL/rs, EXTRACT P_x

ggsci>>edit params p_x
userid ggs, password test
rmthost 192.168.1.72, mgrport 7809
rmttrail /u01/ggate/TRAIL/rs
PASSTHRU
--GETTRUNCATES
DYNAMICRESOLUTION
ddl include mapped objname xxx.*;
TABLE xxx.*;

===================================================
ON TARGET SYSTEM
===================================================
Create the parameter file for the replicate group

ggsci>>EDIT PARAMS ./GLOBALS
GGSCHEMA GGS
CHECKPOINTTABLE GGS.CKPT

ggsci>>DBLOGIN USERID ggs, PASSWORD test
ADD CHECKPOINTTABLE GGS.CKPT

sqlplus / as sysdba

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER SYSTEM SWITCH LOGFILE;

ggsci>>ADD REPLICAT R_x,EXTTRAIL /u01/ggate/TRAIL/rs, CHECKPOINTTABLE GGS.CKPT

ggsci>>EDIT PARAMS r_x
REPLICAT R_x
ASSUMETARGETDEFS
userid ggs, password test
DDL
MAP xxx.*, TARGET xxx.*;


ON SOURCE
START EXTRACT E_X
START EXTRACT P_x

ggsci>>info all

make sure every process is running

ON TARGET SYSTEM

START REPLICAT R_x
STATUS REPLICAT R_x

make sure every process is running

---------------------
The best Drill down
---------------------

tail -f ggserr.log

Monday, September 20, 2010

Upgrade ASM and database from 10g to 11g


The upgrade will fall in three phase

1) Install 11g software.

2) Upgrade ASM

3) Upgrade database.


phase 1) Install 11g software.



























phase 2) upgrade ASM

Oracle cluster Synchronization Services (CSS) needs to be upgraded as follow:

Connect as root user and execute:

export ORACLE_HOME=/u01/app/oracle/product/11.1/db_1

Where: $ORACLE_HOME is your new 11g ASM Oracle Home.

$ORACLE_HOME/bin/localconfig reset





Startup the ASM instance using the old ASM Oracle Home e.g. 10.1.0.5.



From another graphical session, set the environment variables

(ORACLE_HOME, PATH, etc.) pointing to your new ASM Oracle Home 11g

Execute the DBUA from the new 11g ASM Oracle Home:

$ORACLE_HOME/bin/dbua

Where: $ORACLE_HOME is the new ASM Oracle Home





DBUA will show 2 options:

=)> upgrade a database

=)> upgrade ASM instance.

Select [upgrade ASM instance] option.

The DBUA will upgrade your ASM instance to the latest release automatically.

























Finally, please startup the databases that are using ASM as

storage option.

Note: The databases will not be affected with the ASM upgrade.

The databases will remain in the original 10g version only since they do not share the same Oracle Home.

START ASM INSTANCE FROM NEW 11G ORACLE_HOME note:it wil be already started


PHASE 3) UPGRADE DATABASE.


START DATABASE from old ORACLE_HOME 10.2.0.1

$ORACLE_HOME/rdbms/admin/utlu111i.sql

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Sep 4 18:32:16 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> @/u01/app/oracle/product/11.1/db_1/rdbms/admin/utlu111i.sql

Oracle Database 11.1 Pre-Upgrade Information Tool 09-04-2010 18:35:20

.

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

Database:

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

--> name: PRODASM

--> version: 10.2.0.1.0

--> compatible: 10.2.0.1.0

--> blocksize: 8192

--> platform: Linux IA (32-bit)

--> timezone file: V2

.

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

Tablespaces: [make adjustments in the current environment]

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

--> SYSTEM tablespace is adequate for the upgrade.

.... minimum required size: 721 MB

.... AUTOEXTEND additional space required: 241 MB

--> UNDOTBS1 tablespace is adequate for the upgrade.

.... minimum required size: 472 MB

.... AUTOEXTEND additional space required: 447 MB

--> SYSAUX tablespace is adequate for the upgrade.

.... minimum required size: 410 MB

.... AUTOEXTEND additional space required: 180 MB

--> TEMP tablespace is adequate for the upgrade.

.... minimum required size: 61 MB

.... AUTOEXTEND additional space required: 41 MB

.

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

Update Parameters: [Update Oracle Database 11.1 init.ora or spfile]

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

WARNING: --> "sga_target" needs to be increased to at least 336 MB

.

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

Renamed Parameters: [Update Oracle Database 11.1 init.ora or spfile]

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

-- No renamed parameters found. No changes are required.

.

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

Obsolete/Deprecated Parameters: [Update Oracle Database 11.1 init.ora or spfile]

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

--> "background_dump_dest" replaced by "diagnostic_dest"

--> "user_dump_dest" replaced by "diagnostic_dest"

--> "core_dump_dest" replaced by "diagnostic_dest"

.

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

Components: [The following database components will be upgraded or installed]

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

--> Oracle Catalog Views [upgrade] VALID

--> Oracle Packages and Types [upgrade] VALID

--> JServer JAVA Virtual Machine [upgrade] VALID

--> Oracle XDK for Java [upgrade] VALID

--> Oracle Workspace Manager [upgrade] VALID

--> OLAP Analytic Workspace [upgrade] VALID

--> OLAP Catalog [upgrade] VALID

--> EM Repository [upgrade] VALID

--> Oracle Text [upgrade] VALID

--> Oracle XML Database [upgrade] VALID

--> Oracle Java Packages [upgrade] VALID

--> Oracle interMedia [upgrade] VALID

--> Spatial [upgrade] VALID

--> Data Mining [upgrade] VALID

--> Expression Filter [upgrade] VALID

--> Rule Manager [upgrade] VALID

--> Oracle OLAP API [upgrade] VALID

.

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

Miscellaneous Warnings

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

WARNING: --> Database is using an old timezone file version.

.... Patch the 10.2.0.1.0 database to timezone file version 4

.... BEFORE upgrading the database. Re-run utlu111i.sql after

.... patching the database to record the new timezone file version.

WARNING: --> Database contains stale optimizer statistics.

.... Refer to the 11g Upgrade Guide for instructions to update

.... statistics prior to upgrading the database.

.... Component Schemas with stale statistics:

.... SYS

WARNING: --> Database contains schemas with objects dependent on network

packages.

.... Refer to the 11g Upgrade Guide for instructions to configure Network ACLs.

.... USER SYSMAN has dependent objects.

WARNING: --> EM Database Control Repository exists in the database.

.... Direct downgrade of EM Database Control is not supported. Refer to the

.... 11g Upgrade Guide for instructions to save the EM data prior to upgrade.

.

PL/SQL procedure successfully completed.

NOTE: TO AVOID BELOW ERROR APPLY PATCH 5632264

WARNING: --> Database is using an old timezone file version.

.... Patch the 10.2.0.1.0 database to timezone file version 4

.... BEFORE upgrading the database. Re-run utlu111i.sql after

.... patching the database to record the new timezone file version.

if patch cant apply do as below

The manual process is:

a) download the correct 5632264 patch for your base version and platform.

b) unzip the 6672979 patch

c) make a backup of the 2 *.dat files in your $ORACLE_HOME/oracore/zoneinfo

directory and removed them (Databases may be running but if possible stop them to avoid any file locks)

d) copy the 2 *.dat files and the readme.txt from the unzipped patch 5632264/files/oracore/zoneinfo directory to your $ORACLE_HOME/oracore/zoneinfo directory (Databases may be running but if possible stop them to avoid any file locks).

e) stop all databases using this $ORACLE_HOME and after all databases are stopped start them again

startup database

SQL> select * from v$timezone_file;

FILENAME VERSION

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

timezlrg.dat 4


EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;

EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;

PL/SQL procedure successfully completed.

EXEC DBMS_STATS.GATHER_SCHEMA_STATS('SYS');

PL/SQL procedure successfully completed.

create pfile from spfile;

copy pfile from old home to new 11g home

cp initPRODASM.ora /u01/app/oracle/product/11.1/db_1/dbs

cp orapwPRODASM /u01/app/oracle/product/11.1/db_1/dbs

copy init+ASM.ora if its not there on new 11g home/dbs

change init parameters in new file

export new 11g path

export ORACLE_SID=PRODASM

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.1/db_1

#export ORA_CRS_HOME=$ORACLE_BASE/product/10.2.0/crs_1

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

export PATH=$ORACLE_HOME/bin:$ORA_CRS_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin

update /etc/oratab

#PRODASM:/u01/app/oracle/product/10.2.0/db_1:N

PRODASM:/u01/app/oracle/product/11.1/db_1:N

+ASM:/u01/app/oracle/product/11.1/db_1:N

export parameters

PRDASM-> cp initPRODASM.ora /u01/app/oracle/product/11.1/db_1/dbs

PRDASM-> cp orapwPRODASM /u01/app/oracle/product/11.1/db_1/dbs

PRDASM-> export ORACLE_HOME=$ORACLE_BASE/product/11.1/db_1

PRDASM-> export ORACLE_SID=PRODASM

PRDASM-> RS_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin <

PRDASM-> which sqlplus

/u01/app/oracle/product/11.1/db_1/bin/sqlplus

PRDASM-> sqlplus / as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Sat Sep 4 19:49:23 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup upgrade

ORA-32004: obsolete and/or deprecated parameter(s) specified

ORACLE instance started.

Total System Global Area 188313600 bytes

Fixed Size 1298780 bytes

Variable Size 71306916 bytes

Database Buffers 113246208 bytes

Redo Buffers 2461696 bytes

Database mounted.

Database opened.

19) run catupgrd.sql

SQL> @/u01/app/oracle/product/11.1/db_1/rdbms/admin/catupgrd.sql

check if any component or database object is not a invalid