Saturday, May 28, 2011

SQL Profile – create manually


Symptom
Sql execution is too long

Cause
After automatic statistics collection on table, the execution plan changed. It is no more picking the index and doing full table scan.

solution
Step 1. Find the SQL ID that needs a profile,
               in this example: 50ux45v27k6ab

Step 2. Find the hint that introduces a good plan
               In this example: INDEX(TRAIN_SHEET_OSPOINT PK_TRAIN_SHEET_OSPOINT)

Step 3. Run following anonymous PLQSL block
DECLARE
cl_sql_text CLOB; 
BEGIN
SELECT sql_text  
INTO cl_sql_text  
FROM gv$sqlarea where sql_id = '50ux45v27k6ab' and rownum = 1; 
DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text => cl_sql_text,  
profile => sqlprof_attr(‘INDEX(TRAIN_SHEET_OSPOINT PK_TRAIN_SHEET_OSPOINT)'),  
name => 'USE_PK_FOR_UPDATE',  
category => 'DEFAULT', 
force_match => TRUE); 
end; 
/

Hope this helps! Rupam

Wednesday, May 18, 2011

Flashback Cheatsheet


Enabling/disabling Logging for Flashback Database
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=4320; # 3 days
SQL> ALTER DATABASE FLASHBACK ON;
SQL> ALTER DATABASE FLASHBACK OFF;

Estimating Disk Space Requirements for Flashback Database Logs
SQL> SELECT ESTIMATED_FLASHBACK_SIZE FROM V$FLASHBACK_DATABASE_LOG;

By default, flashback logs are generated for all permanent tablespaces.
SQL> ALTER TABLESPACE tbs_3 FLASHBACK OFF;
SQL> ALTER TABLESPACE tbs_3 FLASHBACK ON;

Backup database
RMAN> backup database plus archivelog;

Backup flash recovery area
RMAN> backup recovery area;

Flashback usage
sql> select * from v$recovery_file_dest;
sql> select * from v$flash_recovery_area_usage;

Create Restore Point
sql> create restore point rp01;
sql> select name from v$restore_point;
sql> drop restore point rp01;
sql> SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,GUARANTEE_FLASHBACK_DATABASE,STORAGE_SIZE
        FROM V$RESTORE_POINT;
sql> SELECT NAME, SCN, TIME, DATABASE_INCARNATION#,GUARANTEE_FLASHBACK_DATABASE, STORAGE_SIZE
        FROM V$RESTORE_POINT
      WHERE GUARANTEE_FLASHBACK_DATABASE='YES';

-- Determining the Current Window for Flashback Database
sql> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
      FROM V$FLASHBACK_DATABASE_LOG;

Restore to Restore Point using RMAN
RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP MOUNT;
RMAN> LIST RESTORE POINT ALL;
RMAN> LIST RESTORE POINT  RP03;
RMAN> flashback database  to  restore point rp01;
RMAN> alter database open resetlogs;

RMAN> FLASHBACK DATABASE TO SCN 46963;
RMAN> FLASHBACK DATABASE TO RESTORE POINT BEFORE_CHANGES;
RMAN> FLASHBACK DATABASE TO TIME "TO_DATE('09/20/00','MM/DD/YY')";
RMAN> SQL 'ALTER DATABASE OPEN READ ONLY'; # VERIFY CHANGES

Restore to Restore Point using SQL
sql> shutdown immediate
sql> startup mount
sql> flashback database  to  restore point rp01;
sql> alter database open resetlogs;

Options After Flashback Database to the Wrong Time
RMAN> FLASHBACK DATABASE TO SCN 42963;  #earlier than current SCN
RMAN> RECOVER DATABASE UNTIL SCN 56963; #later than current SCN
RMAN>  RECOVER DATABASE;

Performing Flashback Database to Undo an OPEN RESETLOGS
sql> select resetlogs_change# from v$database;
sql> select oldest_flashback_scn from v$flashback_database_log;
sql> select resetlogs_change# from v$database;
sql> select oldest_flashback_scn from v$flashback_database_log;

Flashback Database To The Right of Open Resetlogs
sql> select oldest_flashback_scn from v$flashback_database_log;
SQL> select prior_incarnation# from v$database_incarnation where status = 'CURRENT';
RMAN> LIST INCARNATION OF DATABASE trgt;
RMAN> RESET DATABASE TO INCARNATION 1;
RMAN> FLASHBACK DATABASE TO SCN 1500;


Flashback Table
   -- Prerequisites for Using Flashback Table
sql> ALTER TABLE table ENABLE ROW MOVEMENT;
sql> SELECT, INSERT, DELETE, and ALTER privileges on the table.

 Performing Flashback Table
sql> FLASHBACK TABLE EMP TO SCN 123456;
sql> FLASHBACK TABLE EMP TO TIMESTAMP
      TO_TIMESTAMP('2005-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')

Viewing, Querying and flashback  Objects in the Recycle Bin
SQL> show recyclebin;
SQL> SELECT object_name as recycle_name, original_name, type
     FROM recyclebin;
SQL> SELECT * FROM "BIN$KSD8DB9L345KLA==$0";
SQL> FLASHBACK TABLE "BIN$gk3lsj/3akk5hg3j2lkl5j3d==$0" TO BEFORE DROP;
OR
sql> FLASHBACK TABLE HR.INT_ADMIN_EMP TO BEFORE DROP;
FLASHBACK TABLE "BIN$KSD8DB9L345KLA==$0" TO BEFORE DROP
     RENAME TO hr.int2_admin_emp;


Hope this helps! Regards Rupam

Thursday, April 28, 2011

Rman: Ora-01008 When Connecting To Target in 11.2.0.2 [ID 1280447.1]




It's a bug with a patch. Workaround is to :

SQL> alter system flush shared_pool;

Hope This Helps! Rupam

Tuesday, April 26, 2011

Basics of 10g RAC/CRS




IMP: login as root for startup and shutdown

To Start CRS
Go to $CRS_HOME/bin
# ./crsctl start crs
Or
#  /etc/init.d/init.crs start

Check CRSD process
ps -ef|grep crsd.bin

To Stop CRS
Go to $CRS_HOME/bin
# ./crsctl stop crs
Or
# /etc/init.d/init.crs stop

CRS enable/disable
Go to $CRS_HOME/bin
crsctl enable crs
crsctl disable crs # ensures that the services do not come up after a reboot.

To find out the value of your CLUSTER_NAME from CRS (OCR),
  cd $CRS_HOME/bin
  ./cemutlo -n

lists the version of CRS software installed
crsctl query crs softwareversion []

lists the CRS software operating version
crsctl query crs activeversion


Status of CRS services
Go to $CRS_HOME/bin
bash-3.00$ ./crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.cmwdb1.gsd application ONLINE ONLINE cmwdb1
ora.cmwdb1.ons application ONLINE ONLINE cmwdb1
ora.cmwdb1.vip application ONLINE ONLINE cmwdb1
ora.cmwdb2.gsd application ONLINE ONLINE cmwdb2
ora.cmwdb2.ons application ONLINE ONLINE cmwdb2
ora.cmwdb2.vip application ONLINE ONLINE cmwdb2


Check current OCR file

bash-3.00$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 2
Total space (kbytes) : 102188
Used space (kbytes) : 2140
Available space (kbytes) : 100048
ID : 617463612
Device/File Name : /dev/vx/rdsk/racdg/rac_srvconfig
Device/File integrity check succeeded

Device/File not configured

Cluster registry integrity check succeeded


Check current CRS file

bash-3.00$ crsctl query css votedisk
0. 0 /dev/vx/rdsk/racdg/crs

located 1 votedisk(s).

Files need to backed for CRS

CRS HOME and startup scripts

$CRS_HOME
/etc/init.d/init.cssd
/etc/init.d/init.crs
/etc/init.d/init.crsd
/etc/init.d/init.evmd
/var/opt/oracle
/etc/inittab

OCR file

bash-3.00$ ocrconfig -showbackup
cmwdb1 2010/09/27 12:17:02 /oracle/crs/cdata/crs
cmwdb1 2010/09/27 08:17:01 /oracle/crs/cdata/crs
cmwdb1 2010/09/27 04:17:00 /oracle/crs/cdata/crs
cmwdb1 2010/09/26 12:16:57 /oracle/crs/cdata/crs
cmwdb1 2010/09/19 08:16:08 /oracle/crs/cdata/crs

CRS file
bash-3.00$ crsctl query css votedisk
0. 0 /dev/vx/rdsk/racdg/crs
dd if=/dev/vx/rdsk/racdg/crs of=/oracle/crs/data/crs/crs_backup.dmp bs=4k


CRS Log files location
$CRS_HOME/log/hostname


cluster verification utlity
     cluvfy comp crs -n all -verbose
     cluvfy comp ocr -n all -verbose
     cluvfy comp nodecon -n all -verbose
     olsnodes
     cluvfy comp -list
     cluvfy stage -list
     cvuqdisk
     cluvfy stage -post crsinst -n all -verbose  # as oracle

Do you want to check the health of the Clusterware?
     crsctl check crs
     crsctl check evmd
     crsctl check cssd
     crsctl check crsd
           

# OEM User Defined OS Metric.
    Script is called by OEM to monitor the health of CRSd on a particular node.
    # UserDefinedHostScripts/checkCRS.sh

    The script runs the "crsctl check crsd" command. The normal output
    is "CRS appears healthy". Any other response will trigger an alert.
    The alert is configured to send an email and an snmp trap to Unicenter.

    #!/usr/bin/ksh
    if [[ $(/ora01/oracle/product/crs_1020/bin/crsctl check crsd) = "CRS appears healthy" ]]
      then print "em_result=0\nem_message=CRSd is healthy\n"
      else print "em_result=1\nem_message=CRSd not responding\n"
    fi
    exit

CRS reboot issue
Whenever a node is having issues joining the cluster back post reboot, here is a quick check list :

    * /var/log/messages
    * ifconfig
    * ip route
    * /etc/hosts
    * /etc/sysconfig/network-scripts/ifcfg-eth*
    * ethtool
    * mii-tool
    * cluvfy
    * $CRS_HOME/log/hostname









To find the root cause, please provide the following from all the nodes to Oracle Support.

1)- OSWatcher output from all the nodes
2)- All log files under $CRS_HOME/log. You can use diagcollection.pl to get all log files.
3)- System OS logs "/var/log/messages".

4)- OPROCD log files under /etc/oracle/oprocd or /var/opt/oracle/oprocd.

5) Capture output of the cluvfy command.
Execute the following commands as oracle:

>ORACLE_SID=crs;ORAENV_ASK=NO;. oraenv;ORAENV_ASK=YES
>HOST=$(hostname)
>cd /opt/oracle/admin/SR
>script $HOST.cluvfy.log
>cluvfy stage -post crsinst -n all -verbose
>exit
Upload the files to Oracle in support of your SR.


Using the diagcollection.pl procedure
Run the following commands on each node. These commands must be run as root.

>export ORA_CRS_HOME=/ora01/oracle/product/crs_1020
>export ORACLE_BASE=/ora01/oracle
>export ORACLE_HOME=/ora01/oracle/product/crs_1020
>export HOSTNAME=$(hostname)
>cd $ORA_CRS_HOME/bin
>script diag.log
>env
>id
>./diagcollection.pl -collect
>exit
This creates the
            diag.log file in $ORA_CRS_HOME/bin and
these files crsData_.tar.gz,
            ocrData_.tar.gz,
            oraData_.tar.gz and
            basData_.tar.gz

If you get a prompt to overwrite existing tar.gz files, go ahead and overwrite.
This is a perl script, so /bin/perl has to be in your PATH.




Hope this helps! Rupam

Tuesday, April 19, 2011

DATAPUMP With PARALLEL > 1 ON 11.2 RAC



Symptoms
Datapump on 11.2 RAC with PARALLEL > 1  hits the following errors


ORA-31693: Table data object "SCOTT"."ESCSTATUS" failed to load/unload and is being skipped do error:
ORA-31617: unable to open dump file "/ora01/oracle/admin/demo/dpdump/demo_expdp_SCOTT.041911_06_02.dmp" for write
ORA-19505: failed to identify file "/ora01/oracle/admin/demo/dpdump/demo_expdp_SCOTT.041911_16_02.dmp"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Cause
From 11.2, Datapump new parameter CLUSTER is introduced.

CLUSTER : Default=Y

Purpose :
Determines whether Data Pump can use Oracle Real Application Clusters (RAC)
resources and start workers on other Oracle RAC instances.

Syntax and Description : CLUSTER=[Y | N]


Solution
To force Data Pump to use only the instance where the job is started and to replicate pre-Oracle Database 11g release 2 (11.2) behavior, specify CLUSTER=N.

Example:
$ expdp hr DIRECTORY=dpump_dir1 DUMPFILE=hr_clus%U.dmp CLUSTER=N PARALLEL=3

Hope this help! Rupam