Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
By Haili Jiao
10g OCP & 9i OCA
May 2008
Oracle 10g Data Guard is a great tool to ensure high availability, data protection and
disaster recovery for enterprise data. I have been working on Data Guard/Standby
databases using both Grid control and SQL command line for a couple of years, and my
latest experience with Data Guard was manually creating a Physical Standby Database
for a Laboratory Information Management System (LIMS) half a year ago. I maintain it
daily and it works well. I would like to share my experience with the other DBAs.
In this example the database version is 10.2.0.3.. The Primary database and Standby
database are located on different machines at different sites. The Primary database is
called PRIM and the Standby database is called STAN. I use Flash Recovery Area, and
OMF.
1. Make sure the operating system and platform architecture on the primary and
standby systems are the same;
2. Install Oracle database software without the starter database on the standby server
and patch it if necessary. Make sure the same Oracle software release is used on
the Primary and Standby databases, and Oracle home paths are identical.
3. Test the Standby Database creation on a test environment first before working on
the Production database.
1
$orapwd file=pwdPRIM.ora password=xxxxxxxx force=y
(Note: Replace <Oracle_Home> with the actual Oracle home path, and xxxxxxxxx with the
password for the SYS user.)
- On UNIX:
$Cd $ORACLE_HOME/dbs
$Orapwd file=pwdPRIM.ora password=xxxxxxxx force=y
(Note: Replace xxxxxxxxx with your actual password for the SYS user.)
BYTES
----------
52428800
52428800
52428800
2) Use the following command to determine your current log file groups:
SQL> select group#, member from v$logfile;
4) To verify the results of the standby redo log groups creation, run the following
query:
SQL>select * from v$standby_log;
2
- On Windows:
SQL>create pfile=’<Oracle_home>\database\pfilePRIM.ora’ from spfile;
(Note- specify your Oracle home path to replace ‘<Oracle_home>’).
- On UNIX:
SQL>create pfile=’<Oracle_home>/dbs/pfilePRIM.ora’ from spfile;
(Note- specify your Oracle home path to replace ‘<Oracle_home>’).
2) Edit this pfile to add the new primary and standby role parameters: (Here the file
paths are from a windows system. For UNIX system, specify the path accordingly)
db_name=PRIM
db_unique_name=PRIM
LOG_ARCHIVE_CONFIG='DG_CONFIG=(PRIM,STAN)'
LOG_ARCHIVE_DEST_1=
'LOCATION=F:\Oracle\flash_recovery_area\PRIM\ARCHIVELOG
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=PRIM'
LOG_ARCHIVE_DEST_2=
'SERVICE=STAN LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=STAN'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
remote_login_passwordfile='EXCLUSIVE'
FAL_SERVER=STAN
FAL_CLIENT=PRIM
STANDBY_FILE_MANAGEMENT=AUTO
DB_FILE_NAME_CONVERT='E:\oracle\product\10.2.0\oradata\STAN\DATAFILE','E:\oracle\produ
ct\10.2.0\oradata\PRIM\DATAFILE'
LOG_FLE_NAME_CONVERT=’E:\oracle\product\10.2.0\oradata\STAN\ONLINELOG’,’E:\oracle\p
roduct\10.2.0\oradata\PRIM\ONLINELOG’,’F:\Oracle\flash_recovery_area\STAN\ONLINELOG’,’F:\
Oracle\flash_recovery_area\PRIM\ONLINELOG’
6. Create spfile from pfile, and restart primary database using the new spfile.
Data Guard must use SPFILE. Create the SPFILE and restart database.
- On windows:
SQL> shutdown immediate;
SQL> startup nomount pfile=’<Oracle_home>\database\pfilePRIM.ora’;
SQL>create spfile from pfile=’<Oracle_home>\database\pfilePRIM.ora’;
-- Restart the Primary database using the newly created SPFILE.
SQL>shutdown immediate;
SQL>Startup;
(Note- specify your Oracle home path to replace ‘<Oracle_home>’).
3
- On Unix:
SQL> shutdown immediate;
SQL> startup nomount pfile=’<Oracle_home>/dbs/pfilePRIM.ora’;
SQL>create spfile from pfile=’<Oracle_home>/dbs/pfilePRIM.ora’;
-- Restart the Primary database using the newly created SPFILE.
SQL>shutdown immediate;
SQL>Startup;
(Note- specify your Oracle home path to replace ‘<Oracle_home>’).
3. Copy the Primary DB pfile to Standby server and rename/edit the file.
2) Rename it to pfileSTAN.ora, and modify the file as follows. : (Here the file paths
are from a windows system. For UNIX system, specify the path accordingly)
*.audit_file_dest='E:\oracle\product\10.2.0\admin\STAN\adump'
*.background_dump_dest='E:\oracle\product\10.2.0\admin\STAN\bdump'
*.core_dump_dest='E:\oracle\product\10.2.0\admin\STAN\cdump'
*.user_dump_dest='E:\oracle\product\10.2.0\admin\STAN\udump'
*.compatible='10.2.0.3.0'
4
control_files='E:\ORACLE\PRODUCT\10.2.0\ORADATA\STAN\CONTROLFILE\STAN.CTL','F:\O
RACLE\FLASH_RECOVERY_AREA\STAN\CONTROLFILE\STAN.CTL'
db_name='PRIM'
db_unique_name=STAN
LOG_ARCHIVE_CONFIG=’DG_CONFIG=(PRIM,STAN)’
LOG_ARCHIVE_DEST_1=
‘LOCATION=F:\Oracle\flash_recovery_area\STAN\ARCHIVELOG
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=STAN’
LOG_ARCHIVE_DEST_2=
‘SERVICE=PRIM LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=PRIM’
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=PRIM
FAL_CLIENT=STAN
remote_login_passwordfile='EXCLUSIVE'
DB_FILE_NAME_CONVERT=’E:\oracle\product\10.2.0\oradata\PRIM\DATAFILE’,’E:\oracle\prod
uct\10.2.0\oradata\STAN\DATAFILE’
LOG_FILE_NAME_CONVERT=’E:\oracle\product\10.2.0\oradata\PRIM\ONLINELOG’,’E:\oracle\p
roduct\10.2.0\oradata\STAN\ONLINELOG’,’F:\Oracle\flash_recovery_area\PRIM\ONLINELOG’,’F:\
Oracle\flash_recovery_area\STAN\ONLINELOG’
STANDBY_FILE_MANAGEMENT=AUTO
4. On Standby server, create all required directories for dump and archived log
destination:
Create directories adump, bdump, cdump, udump, and archived log destinations for
the standby database.
1) On Primarysystem: use Oracle Net Manager to configure a listener for PRIM and
STAN. Then restart the listener.
5
$lsnrctl stop
$lsnrctl start
2) On Standby server: use Net Manager to configure a listener for PRIM and STAN.
Then restart the listener.
$lsnrctl stop
$lsnrctl start
2) On Standby system: use Oracle Net Manager to create network service names for
PRIM and STAN. Check tnsping to both services:
$tnsping PRIM
$tnsping STAN
10. On Standby server, setup the environment variables to point to the Standby
database.
- On Unix:
SQL>startup nomount pfile=’<Oracle_home>/dbs/pfileSTAN.ora’;
SQL>create spfile from pfile=’<Oracle_home>/dbs/pfileSTAN.ora’;
-- Restart the Standby database using the newly created SPFILE.
SQL>shutdown immediate;
SQL>startup mount;
(Note- specify your Oracle home path to replace ‘<Oracle_home>’).
6
1) On Standby perform a query:
SQL>select sequence#, first_time, next_time from v$archived_log;
14. If you want the redo data to be applied as it is received without waiting for
the current standby redo log file to be archived, enable the real-time apply.
IV. Maintenance:
1. Check the alert log files of Primary and Standby databases frequently to
monitor the database operations in a Data Guard environment.
I scheduled weekly Hot Whole database backup against my primary database that
also backs up and delete the archived logs on Primary.
For the standby database, I run RMAN to backup and delete the archive logs once per
week.
$rman target <username>/<password>@STAN;
Rman>backup archivelog all delete input;
3. Password management
The password for the SYS user must be identical on every system for the redo data
transmission to succeed. If you change the password for SYS on Primary database,
you will have to update the password file for Standby database accordingly, otherwise
the logs won’t be shipped to the standby server.
Refer to section II.2, step 2 to update/recreate password file for the Standby database.
Reference:
Oracle Data Guard Concepts and Administration 10g Release 2 (10.2), B14239-04