Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Sunday, 8 April 2012

Oracle: How to roll forward standby database using archivelogs

At times oracle standby database may get out of sync with primary database. After fixing the issue causing standby out of sync, we need to roll forward standby database so that it can sync up with primary again.
To roll forward standby database, we can use archivelogs.

1. If the archivelogs are deleted from primary already.
We can restore the archivelogs from backups. Suppose our catdb stores RMAN catalog.
we can use this code to restore the archivelogs.
connect target /
connect catalog catuser/catpass@catdb

RUN {
allocate channel c1 type 'SBT_TAPE' 
parms 'ENV=(NB_ORA_CLIENT=prod1)' maxopenfiles 10;

allocate channel c2 type 'SBT_TAPE'
parms 'ENV=(NB_ORA_CLIENT=prod2)' maxopenfiles 10;
restore archivelog from time 'sysdate - 1' until time 'sysdate';
release channel c1;
release channel c2;
}
Depending on how long the standby has been out of sync, we can change the 'from time' accordingly. 

2. If the archivelogs are still on primary database.
We can simply copy them to the standby database,
after copying archivelogs to the standby, we need to catalog the files copied over.
RMAN> catalog start with '/tmp/logs_from_primary';
Otherwise oracle cannot recognize these files.
 
Once we have the archivelogs, either through method 1 or method 2,
we can roll forward the standby database.
SQL> recover managed standby database disconnect;

Saturday, 7 April 2012

Oracle: How to setup physical standby database

In production environment, It's often required to have a physical standby database. In case the primary environment is gone, we can continue serve customer requests using standby database.

There are a few ways to set up oracle standby database, In any ways, please make sure you have the following ready:
  • remote login is enabled, both primary and standby SYS password are the same, this can be set using orapwd.
  • log shipping is enabled on primary, define the proper TNS entry, set log_archive_dest_x, and set log_archive_dest_state_x to enable.
  • The pfile or spfile is ready on standby database.

1. Using storage level replication
On primary database, put the database in backup mode. This is to make sure the copy replicated to standby environment is consistent.
SQL> alter database begin backup;
In storage, split the replication. Stop backup mode on primary database:
SQL> alter database end backup;
Create standby controlfiile:
RMAN> backup current controlfile for standby format '/tmp/stdby_ctrol_%U';
Copy the controlfile backup to standby servers, restore the controlfile.
SQL> startup nomoun;
RMAN> catalog start with '/tmp/stdby_ctrol';
RMAN> restore controlfile from '/tmp/stdby_ctrol_blahblah';

Mount the standby database, and enable redo apply.
SQL> alter database mount standby database;
SQL> recover managed standby database disconnect;
Note: Please make sure do NOT sync back the standby environment on storage level again, otherwise it will destroy the standby database.

2. Using RMAN duplicate.
connect to primary database and standby databse.
$ rman target / AUXILIARY SYS/sys_pwd@sbdb
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;

Wednesday, 21 March 2012

NetBackup: how to restore oracle backup to a different server

Production environment is running on RAC, prod1 and prod2 are the cluster members.
We need to restore the production data to a testing server test1 for application testing, if test1 uses the same NetBackup master and media servers, we can restore the data using this rman code
set dbid = 1234567890;
connect target /
connect catalog rmanid/rmanpass@rmancatalog

RUN {
allocate channel c1 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=prod1)' maxopenfiles 10;
allocate channel c2 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=prod2)' maxopenfiles 10;
set until time "TO_DATE('2012-03-21 12:30:00', 'YYYY-MM-DD HH24:MI:SS')";
restore controlfile;
sql 'alter database mount';
restore database;
recover database;
release channel c1;
release channel c2;
 }

But if we try the restore directly, we will get this error:
ERROR: client is not validated to perform the requested operation.

Before restoration, we have to allow test1 to restore from the backup made on prod1 and prod2. To do this, you need log on to the backup master server. In directory /usr/openv/netbackup/db/altnames, create a file named test1, in file test1, put prod1 and prod2 as the content.

$ cat /usr/openv/netbackup/db/altnames/test1
prod1
prod2
$