Anda di halaman 1dari 6

Data Guard Physical Standby configuration in Oracle Database 11g R2

===================================================================
Machine setup
------------We have two servers (physical or VMs) with Linux OS and Oracle installed on t
hem. In this case I ve used Oracle Linux 5.5
and Oracle Database 11.2.0.1.0.
- The primary server has a running database instance.
- The standby server has a software only installation.
1. Primary Server Setup
----------------------- Logging:
Check that the primary database is in archivelog mode.
--sql> SELECT log_mode FROM v$database;
--LOG_MODE
---------ARCHIVELOG
--If it is noarchivelog mode, switch is to archivelog mode using sql.
sql>
sql>
sql>
sql>
---

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

2. Enabled forced logging


------------------------Enabled forced logging by issuing the following command.
sql> ALTER DATABASE FORCE LOGGING;
--SELECT force_logging FROM v$database;
--3. Initialization Parameters
---------------------------- Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this ca
se they are both set to orcl on the primary database.
sql> show parameter db_name
--NAME
TYPE
VALUE
-------------- ------- -----db_name
string orcl
--sql> show parameter db_unique_name
--NAME
TYPE
VALUE

-------------- ------- -----db_unique_name string orcl


--- The DB_NAME of the standby database will be the same as that of the primary
, but it must have a different DB_UNIQUE_NAME value.
The DB_UNIQUE_NAME values of the primary and standby database should be use
d in the DG_CONFIG setting of the LOG_ARCHIVE_CONFIG
parameter. For this example, the standby database will have the value orcl_s
tby .
--sql> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCL_STBY)';
--- Set suitable remote archive log destinations. In this case I m using the defa
ult archive, but we can specify a location explicitly.
Notice the SERVICE and the DB_UNIQUE_NAME for the remote location reference
the standby location.
--sql> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL_STBY NOAFFIRM ASYNC VA
LID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL_STBY';
sql> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
--- The LOG_ARCHIVE_FORMAT and LOG_ARCHIVE_MAX_PROCESSES parameters must be set
to appropriate values and the REMOTE_LOGIN_PASSWORDFILE
must be set to exclusive.
--sql> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;
sql> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=30;
sql> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
--- In addition to the previous setting, it is recommended to make sure the pri
mary is ready to switch roles to become a standby.
For that to work properly we need to set the following parameters. Adjust t
he *_CONVERT parameters to account for your filename
and path differences between the servers.
sql> ALTER SYSTEM SET FAL_SERVER=ORCL_STBY;
sql> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
4. Service Setup
---------------Entries for the primary and standby databases are needed in the $ORACLE_HOME/n
etwork/admin/tnsnames.ora files on both servers.
We can create these using the Network Configuration Utility (netca) or manual
ly. The following entries were used during this setup:
--ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.153.129)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)

ORCL_STBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.153.130)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
--5. Backup Primary Database
-------------------------- For a backup-based duplicate, or a manual restore, take a backup of the pri
mary database.
$ rman target=/
-RMAN> BACKUP DATABASE format '/u01/backup/full_bkp_%D_%s_%u' PLUS ARCHIVELOG
format '/u01/backup/arch_bkp_%D_%s_%u';
--6. Create Standby Controlfile and PFILE
--------------------------------------- Create a controlfile for the standby database by issuing the following comm
and on the primary database.
sql> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/orcl_stby.ctl';
--sql> CREATE PFILE='/tmp/initorcl_stby.ora' FROM SPFILE;
--- Amend the PFILE making the entries relevant for the standby database. I m maki
ng a replica of the original server,
so in my case I only had to amend the following parameters.
*.db_unique_name='ORCL_STBY'
*.fal_server='ORCL'
*.log_archive_dest_2='SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_
ROLE) DB_UNIQUE_NAME=ORCL'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7. Standby Server Setup (Manual by restoring backup)
=====================================================
- Create directories
Create the necessary directories on the standby server.
--$ mkdir -p /u01/app/oracle/oradata/orcl
$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl
$ mkdir -p /u01/app/oracle/admin/orcl/adump
--- Copy the files from the primary to the standby server.

$ scp /tmp/orcl_stby.ctl oracle@192.168.153.130:/u01/app/oracle/oradata/orcl/


control01.dbf -- confirm filename before starting standby instance
--# Parameter file.
scp /tmp/initorcl_stby.ora oracle@192.168.153.130:/tmp/initorcl_stby.ora
--# Remote login password file.
scp $ORACLE_HOME/dbs/orapworcl oracle@192.168.153.130:$ORACLE_HOME/dbs
--# Transfer backup files
scp /u01/backup/* oracle@192.168.153.130:/u01/backup
--i) Start Listener
----------------- Make sure the listener is started on the standby server.
$ lsnrctl start
ii) Restore Backup
------------------ Make copy of control file
$ cd /u01/app/oracle/oradata/orcl/
$ cp control01.ctl control02.ctl
- Create the SPFILE form the amended PFILE.
$ export ORACLE_SID=orcl
$ sqlplus / as sysdba
--sql> CREATE SPFILE FROM PFILE='/tmp/initorcl_stby.ora';
--- Restore the backup files.
$ rman target=/
RMAN> STARTUP MOUNT;
RMAN> list backup of database;
RMAN> RESTORE DATABASE;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8. Standby Server Setup (using RMAN DUPLICATE)
----------------------------------- Create directories
Create the necessary directories on the standby server.
--$ mkdir -p /u01/app/oracle/oradata/orcl
$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl
$ mkdir -p /u01/app/oracle/admin/orcl/adump
--- Copy the files from the primary to the standby server.

$ scp /tmp/orcl_stby.ctl oracle@192.168.153.130:/u01/app/oracle/oradata/orcl/


control01.ctl
--# Parameter file.
scp /tmp/initorcl_stby.ora oracle@192.168.153.130:/tmp/initorcl_stby.ora
--# Remote login password file.
scp $ORACLE_HOME/dbs/orapworcl oracle@192.168.153.130:$ORACLE_HOME/dbs
--i) Start Listener
----------------- Make sure the listener is started on the standby server.
$ lsnrctl start
ii) Start instance
$ export ORACLE_SID=orcl
sql> sqlplus / as sysdba
sql> STARTUP NOMOUNT PFILE='/tmp/initorcl_stby.ora';
--ii) Duplicate database
Connect to RMAN, specifying a full connect string for both the TARGET and AUX
ILLARY instances. DO not attempt to use OS authentication.
$ rman TARGET sys/oracle@orcl AUXILIARY sys/oracle@orcl_stby
DUPLICATE TARGET DATABASE
FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='ORCL_STBY' COMMENT 'Is standby'
SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMA
RY_ROLE) DB_UNIQUE_NAME=ORCL'
SET FAL_SERVER='ORCL' COMMENT 'Is primary'
NOFILENAMECHECK;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9. Add standby redolog files
---------------------------Add standby redolog files for switchover and real time apply.
sql> ALTER DATABASE ADD
y_redo01.log') SIZE 50M;
sql> ALTER DATABASE ADD
y_redo02.log') SIZE 50M;
sql> ALTER DATABASE ADD
y_redo03.log') SIZE 50M;
sql> ALTER DATABASE ADD
y_redo04.log') SIZE 50M;

STANDBY LOGFILE ('/u01/app/oracle/oradata/orcl/standb


STANDBY LOGFILE ('/u01/app/oracle/oradata/orcl/standb
STANDBY LOGFILE ('/u01/app/oracle/oradata/orcl/standb
STANDBY LOGFILE ('/u01/app/oracle/oradata/orcl/standb

10. Start Apply Process


----------------------Start the apply process on standby server.
# Foreground redo apply. Session never returns until cancel.
sql> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
# Background redo apply. Control is returned to the session once the apply pr
ocess is started.
sql> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
sql> ALTER DATABASE OPEN READ ONLY;
If you need to cancel the apply process, issue the following command.
sql> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
11. Test Log Transport
----------------------- On primary server
SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG WHERE ARCHIVED='YES';
- On standby server
SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG WHERE APPLIED='YES';
Above result on both server should be same. else it is not synchronized with
Primary.
12. Troubleshooting Dataguard
----------------------------i) Standby Database Does Not Receive Redo Data from the Primary Database
If the standby site is not receiving redo data, query the V$ARCHIVE_DEST v
iew and check for error messages. For example,
enter the following query:
--SQL> SELECT DEST_ID "ID", STATUS "DB_status",
DESTINATION "Archive_dest", ERROR "Error"
FROM V$ARCHIVE_DEST WHERE DEST_ID <=5;
---

Anda mungkin juga menyukai