Thursday, October 15, 2009

How to restore DB from tape if DBID has been changed

You are requested to restore a database (into another one) from RMAN backup on tape which was done 2 month ago. You requested tape from your storage company, you have your backup copied over to your server - if that is your preference. And all of a sudden you realize that DBID has been changed AFTER you took your backup - say your database has been refreshed from production and this is a part of the process.

No problem! Just do that:

Eestore the controlfile, then the backup as follows:
RMAN> startup nomount force;
RMAN> restore controlfile from '/db/backup/MYDB/25jul09/c-3431719427-20090723-00';
RMAN> alter database mount;
This should mount the controlfile with the old DBID

Now you may proceed with the database restore - catalog you backup pieces, run restore & recover, apply archive logs (from the same tape) if necessary...

Script to restart database if down

#!/usr/bin/sh
# By GregZ 10/13/2009 to check DB status
##set -v
export ORACLE_HOME=/oracle/app/oracle/product/10.2.0
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=CRBURN
greg=gregz@gregzllc.com
#*************************************************************
# Test to see if Oracle is up...
#*************************************************************
$ORACLE_HOME/bin/sqlplus -s /< /tmp/check_$ORACLE_SID.ora
select * from v\$database;
quit
EOF
#*************************************************************
# If not, restart and e-mail...
#*************************************************************
check_stat=`cat /tmp/check_$ORACLE_SID.ora I grep -i error Iwc -l`;
oracle_num=`expr $check_stat`
echo $oracle_num
if [ $oracle_num -ne 0 ]
then
echo "$ORACLE_SID is down!" I mailx -s "$ORACLE_SID is down!" $greg
sqlplus "/ as sysdba" < /tmp/check_$ORACLE_SID.ora
startup
select * from v\$database;
quit
EOF1
check_stat=`cat /tmp/check_$ORACLE_SID.ora I grep -i error I wc -l`;
oracle_num=`expr $check_stat`
###echo $oracle_num
if [ $oracle_num -eq 0 ]
then
echo "$ORACLE_SID is brought up" I mailx -s "$ORACLE_SID is back up" $greg
fi
##else
## echo "$ORACLE_SID is up" I mailx -s "$ORACLE_SID is up" $greg
fi
exit 0

Friday, March 20, 2009

Restore database from old RMAN backup

1. As usual, you use catalog command to recatalog your backup pieces.
catalog backuppiece '/db/backup/MYDB/old_backup/your_piece_1_1';
2. Startup nomount and restore controlfile.
RMAN>restore controlfile;
3. Alter database mount and restore database
RMAN>alter database mount;
RMAN>restore database;
4. Try recover database;
It will give you the required archivelogs but you don't need them. You are just trying to restore from the old backup as it was. So check you max last archivelog in thi sbackup:
select max(sequence#) from v$log_history;
1425
Now do this:
Recover database until logseq=1426;
5. You are done.
Run:
Alter database open
6. And don't forget to create you tempfiles. RMAN backup does not have them!

ORA-01652:unable to extend temp segment

Don't rush to add additional tempfile or increase the size of existing ones if you are getting this.

If you are happy with your tempfile sizes (I usually allocate 10 to 20G to them), try increasing pga_aggregate_target. If this is not enouph, retrieve the sql from either v$sql or v$sqlarea (or better yet from the Grid Control) & see if execution plan is good. If not, tune it, otherwise recreate statistics on the tables involved. If you'd use cascade=true parameter in dbms_stats.gather_table_stats, indexes will be analyzed as well.