Appendix C: Create Standby Database Manually - Linux
A standby database is a special copy of the primary database. Once created, Dbvisit Standby can be used to automatically keep the standby database up to date with the primary database. Dbvisit Standby can automatically create the standby database, but in some cases it may be desirable to manually create the standby database. These steps show two different methods for manually creating the standby database. Please choose one method.
Creating a standby database (using RMAN)
Oracle's Rman can be used to create a standby database without shutting down the primary database. You do not need to create an Rman catalog.The easiest way to use Rman is to create the backup on disk. However, this requires significant free space if your database is very large. It is also possible to save the backup to tape. In this case you would need a tape or media manager as part of your Rman configuration.On some systems it may be possible to use an external Hard Disk (through USB) to backup the database and then use this disk to restore the database on the standby server.
The examples below is making use of Disk Based backups: Â Â
- The assumption in this example is that the primary and standby database servers are exactly the same:
- Same Operating System and version
- Same Database Software and Patch Levels
- Same directory structure is used
- Backups are stored in /u02/backup/devdb.
- This location exists on both the primary and the standby database servers. Â
- The backup will be created on the primary database using RMAN and stored in /u02/backup/devdb/
- The backup must then be copied manually to the standby server to /u02/backup/devdb/ Â (This can be done using scp command)
- Once the backup is copied to the standby server, RMAN is used to perform the restore/creation of the standby database.
Preliminary steps:
1. Setup the same Linux or Unix user accounts (Oracle software owner) and groups (dba) on the standby server (preferably with the same uid and the same gid), as on the primary server.
2. Recreate the same Oracle directory structure on the standby server as on the primary server.
3. Install Oracle software on the standby server preferably in the same location as on the primary server.
4. Copy the database parameter (pfile/spfile) file for the production database on the production server to the standby server into $ORACLE_HOME/dbs
5. Copy the /etc/oratab file from the production server to the standby server, of make sure the entry for the database you want to create the standby database for is in the standby oratab file.
6. Copy the password file $ORACLE_HOME/dbs/orapw<$ORACLE_SID> from the production server to the standby server.Â
7. Create a directory on the primary and standby server where the full backup of the database can be kept. In this example /u02/backup/devdb will be used.
On the primary server:
8. Set the Oracle environment to the production database (with the oraenv command in Linux/UNIX) - in the example the database is called "devdb"
oracle@dbvlin101[/home/oracle]: . oraenv ORACLE_SID = [oracle] ? devdb The Oracle base remains unchanged with value /u01/app/oracle oracle@dbvlin101[/home/oracle]:
Â
9. Â Run the following RMAN commands to backup the primary database:
Note that TAGs are used to make it easier to restore. Â For more detail on RMAN and using "tags" please see the Oracle documentation
Â
Â
$ rmanÂ
connect target /Â
run{Â
change archivelog all crosscheck;Â
allocate channel ch1 type disk;Â
backup as compressed backupset database format '/u02/backup/devdb/db_%U' tag 'BKP1_DB';
sql "alter system archive log current";Â
backup archivelog all format '/u02/backup/devdb/arc_%U' tag 'BKP1_ARC';Â
backup current controlfile for standby format '/u02/backup/devdb/standby-ctl-%U';
release channel ch1;
}
10. Once the backup is finished, copy the backup files located in  /u02/backup/devdb/  to same location on standby server.  Example:  scp  /u02/backup/devdb/* dbvlin102: /u02/backup/devdb/
Â
On the standby server:
11. Set the environment for the standby database (similar to step 8 above using oraenv utility), then start the standby database in nomount mode.
Â
oracle@dbvlin102[/home/oracle]: . oraenv
ORACLE_SID = [oracle] ? devdb
The Oracle base remains unchanged with value /u01/app/oracle
oracle@dbvlin102[/home/oracle]: sqlplus "/ as sysdba"
SQL> startup nomount
12. Start RMAN on the standby server and create the standby database.Â
Important: the following assume that the database parameter file was already copied from the primary to standby server and that the directory structure and settings for the standby server is exactly the same as the primary. Â (This is the ideal and recommended configuration for a standby database to match production)
Â
$rman
connect target /Â
RMAN> restore standby controlfile from '/u02/backup/devdb/standby-ctl-1qq7t60h_1_1';
RMAN> sql 'alter database mount';
RMAN> restore database from tag 'BKP1_DB';
RMAN> recover database from tag 'BKP1_ARC';
NOTE: You will get an error from the recover command as the above command as it is looking for archive logs that will not exist in the BKP1_ARC backup. Â It will however apply the required logs from this backup. Â
Â
13. Standby database is now complete. RMAN has started the standby database in mount standby mode which is correct for Dbvisit Standby to continue.Â
Creating a standby database (traditional method)
The process involves making a full backup of your production database on the primary server. This can be either a hot or a cold backup. If a hot backup is used, then the archive log files created during the backup will also need to be copied to the standby database.
Preliminary steps:
1. Setup the same Linux or Unix user accounts (Oracle software owner) and groups (dba) on the standby server (preferably with the same uid and the same gid) as on the primary server.
2. Recreate the same Oracle directory structure on the standby server as on the primary server.
3. Install Oracle software on the standby server preferably in the same location as on the primary server.
4. Copy the init.ora file for the production database on the production server to the standby server.
5. Copy the /var/opt/oracle/oratab or /etc/oratab from the production server to the standby server (this is not necessary for Windows).5.Â
6. Copy the password file $ORACLE_HOME/dbs/orapw<$ORACLE_SID> from the production server to the standby server. You may have to create a new password file with the orapwd utility.
7. Copy the spfile file from the production server to the standby server if it is used.
On the primary server:
8. Make a standby controlfile on the production database using the following command:
Â
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/oracle/orabase/admin/dbvisitp/create/STANDBY_DBVISIT_control01.ctl' REUSE;
Where dbvisitp is the name of the database
9. Copy this standby controlfile to a temporary location on the standby server.
10. Make a cold or a hot backup of the database to either disk or tape.
11. Restore the full production database backup (including any new archive logs) to the standby server.
On the standby server:
12. Replace the existing controlfile(s) (if any) with this new standby controlfile from the temporary location. Make sure the names of the controlfile(s) stay the same.
Example: if the existing controlfiles were named control01.ctl and control02.ctl, replace the existing controlfiles with the new standby controlfile (created in step 8 above) and make sure that new standby controlfiles are named control01.ctl and control02.ctl.
13. Set the correct Oracle environment (on Linux and Unix with the oraenv command)
14. Start sqlplus:
Â
sqlplus /nolog
SQL> connect / as sysdba ;
SQL> startup nomount
SQL> alter database mount standby database ;
SQL> recover standby database ;
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
15. Apply archives until there are no more archives to be applied.
16. Standby database is now complete. The standby database is in mount standby mode which is correct for Dbvisit Standby to continue. For reference the commands to start a standby database are:
Â
SQL> startup nomount
SQL> alter database mount standby database;