您的位置:首页 > 数据库 > Oracle

Oracle 10g 单实例数据库 Data Guard 之 Physical Standby 配置详解(根据官方文档总结)

2013-02-05 22:23 726 查看
--------Creating Physical Standby Database-------------------------------

--------Settings for the primary database--------------------------------

1、Enable Forced Logging

ALTER DATABASE FORCE LOGGING;

2、Create a Password File

orapwd file=orapw$ORACLE_SID password=oracle entries=5 force=y

3、Configure a Standby Redo Log

3.1 、conn / as sysdba

3.2 、select * from v$log;

3.3 、select * from v$logfile;

3.4 、prepare add standby redo log clause:

ALTER DATABASE ADD STANDBY LOGFILE GROUP 4

'/u01/app/oracle/oradata/cuug/redo04.log' SIZE 10M;



ALTER DATABASE ADD STANDBY LOGFILE GROUP 5

'/u01/app/oracle/oradata/cuug/redo05.log' SIZE 10M;

ALTER DATABASE ADD STANDBY LOGFILE GROUP 6

'/u01/app/oracle/oradata/cuug/redo06.log' SIZE 10M;

4、Set Primary Database Initialization Parameters

DB_UNIQUE_NAME=cuug

LOG_ARCHIVE_CONFIG='DG_CONFIG=(cuug,cuuo)'

LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/cuug/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=cuug'

LOG_ARCHIVE_DEST_2='SERVICE=cuuo LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=cuuo'

log_archive_format='%t_%s_%r.log'

FAL_SERVER=cuuo

FAL_CLIENT=cuug

DB_FILE_NAME_CONVERT='/u02/app/oracle/oradata/cuuo/','/u01/app/oracle/oradata/cuug/'

LOG_FILE_NAME_CONVERT='/u02/app/oracle/oradata/cuuo/','/u01/app/oracle/oradata/cuug/'

STANDBY_FILE_MANAGEMENT=AUTO



5、archive log list or show parameter archive;

6、Create a Backup Copy of the Primary Database Datafiles(IGNORE or OPTIONAL)

7、 Create a Control File for the Standby Database

6.1 startup mount;

6.2 alter database create standby controlfile as '/u02/app/oracle/oradata/cuuo/control01.ctl';

8、Prepare an Initialization Parameter File for the Standby Database

8.1 Copy the primary database parameter file to the standby database.

create pfile='/u02/app/oracle/oradata/cuuo/initcuuo.ora' from spfile;

8.2 Modifying Initialization Parameters for a Physical Standby Database

------If you choose the parameter value for the standby database other than the pfile created from the Primary database, the Controlfiles,user_dump_dest,background_dump_dest, core_dump_dest should also be changed for the standby database
if necessary.------

DB_UNIQUE_NAME=cuuo

LOG_ARCHIVE_CONFIG='DG_CONFIG=(cuuo,cuug)'---此处不修改

LOG_ARCHIVE_DEST_1='LOCATION=/u02/app/oracle/oradata/cuuo/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=cuuo'

LOG_ARCHIVE_DEST_2='SERVICE=cuug LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=cuug'

log_archive_format='%t_%s_%r.log'

FAL_SERVER=cuug

FAL_CLIENT=cuuo

DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/cuug/','/u02/app/oracle/oradata/cuuo/'

LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/cuug/','/u02/app/oracle/oradata/cuuo/'

STANDBY_FILE_MANAGEMENT=AUTO

8.3 create the password for the Standby Database

orapwd file=orapwcuuo password=oracle entries=5 force=y

9、Configure a dynamic regsitered listener for the standby database

9.1、add the following strings in the listener.ora via vi editor.



LSNDG =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1522))

)

)

SID_LIST_LSNDG =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME= cuuo)

(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)

(SID_NAME = cuuo)

)

)

9.2、add the following strings in the tnsnames.ora via vi editor.

LSNDG =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1522))

)

(CONNECT_DATA =

(SERVICE_NAME = cuuo)

)

)

8.3 lsnrctl start lsndg;

8.4 export ORACLE_SID=cuuo

conn / as sysdba;

startup pfile='/u02/app/oracle/oradata/cuuo/initcuuo.ora'

create spfile from pfile='/u02/app/oracle/oradata/cuuo/initcuuo.ora' ----The spfile generated here will be in the $ORACLE_HOME/dbs dir.

alter system set local_listener='LSN_DG';

alter system register;

-- start standby database listener

oracle@rac3-:>admin>lsnrctl status lsndg

LSNRCTL for Solaris: Version 10.2.0.2.0 - Production on 02-JUL-2012 17:38:52

Copyright (c) 1991, 2005, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac3)(PORT=1522)))

STATUS of the LISTENER

------------------------

Alias lsndg

Version TNSLSNR for Solaris: Version 10.2.0.2.0 - Production

Start Date 02-JUL-2012 17:33:12

Uptime 0 days 0 hr. 5 min. 40 sec

Trace Level off

Security ON: Local OS Authentication

SNMP OFF

Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/lsndg.log

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac3)(PORT=1522)))

Services Summary...

Service "cuuo" has 2 instance(s).

Instance "cuuo", status UNKNOWN, has 1 handler(s) for this service...

Instance "cuuo", status READY, has 1 handler(s) for this service...

Service "cuuo_XPT" has 1 instance(s).

Instance "cuuo", status READY, has 1 handler(s) for this service...

The command completed successfully

8.5、add the cuuo and the cuug tnsname as following (where the cuuo stands for the standby database,the cuug stands for the primary database) in the tnsnames.ora file via vi editor.

cuuo =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1522))

)

(CONNECT_DATA =

(SERVICE_NAME = cuuo)

)

)

cuug =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = rac3)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = cuug)

)

)

8.6-- start primary database listener

lsnrctl start

lsnrctl status

the status must me ready

Testing tns configuration

you must open both the cuug and cuuo in mount state at least.

conn sys/oracle@cuug as sysdba

conn sys/oracle@cuuo as sysdba

Ensure that you can connect to the both database successfully, and then do the following work on the next.

9、Start the Physical Standby Database

9.1 Start the physical standby database

startup mount;

9.2 Start Redo Apply.

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION ;



If the command execute successfully, Pls check the alert log for more information,and make sure the standby database is running in the recovery mode.



9.3 Test archival operations to the physical standby database.

In this example, the transmission of redo data to the remote standby location does not occur until after a log switch. A log switch occurs, by default, when an online redo log file becomes full. To force a log switch so that redo data is transmitted immediately,
use the following ALTER SYSTEM statement on the primary database. For example:

SQL> ALTER SYSTEM SWITCH LOGFILE;

You can check the standby database's archive directory after executing the command above,and make sure that there is a new rchivelog generated right now.And congratulations to you if so!

---------------Role Transitions-------------------------

1、 Verify it is possible to perform a switchover.

Check the primary database to see whether it can be switched to a standby database.

To do this, you can run the following command in the sqlplus.

select NAME,DB_UNIQUE_NAME,FORCE_LOGGING,SWITCHOVER#,SWITCHOVER_STATUS from v$database;

18:59:20 sys@CUUG> select NAME,DB_UNIQUE_NAME,FORCE_LOGGING,SWITCHOVER#,SWITCHOVER_STATUS from v$database;

NAME DB_UNIQUE_NAME FOR SWITCHOVER# SWITCHOVER_STATUS

---------------------------------------- ------------------------------ --- ----------- --------------------

CUUG cuuo YES 1268056249 SESSIONS ACTIVE

19:13:59 sys@CUUG> select NAME,DB_UNIQUE_NAME,FORCE_LOGGING,SWITCHOVER#,SWITCHOVER_STATUS from v$database;

NAME DB_UNIQUE_NAME FOR SWITCHOVER# SWITCHOVER_STATUS

---------------------------------------- ------------------------------ --- ----------- --------------------

CUUG cuug YES 1268056249 TO STANDBY

You can not switch to standby until the SWITCHOVER_STATUS become 'TO STANDBY', which means there is no current active sessions in the database.

The TO STANDBY value in the SWITCHOVER_STATUS column indicates that it is possible to switch the primary database to the standby role. If the TO STANDBY value is not displayed, then verify the Data Guard configuration is functioning correctly (for example,
verify all LOG_ARCHIVE_DEST_n parameter values are specified correctly).

If the value in the SWITCHOVER_STATUS column is SESSIONS ACTIVE, perform the steps described in Section A.4, "Problems Switching Over to a Standby Database" to identify and terminate active user or SQL sessions that might prevent a switchover from being processed.
If, after performing these steps, the SWITCHOVER_STATUS column still displays SESSIONS ACTIVE, you can successfully perform a switchover by appending the WITH SESSION SHUTDOWN clause to the ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY statement
described in Step 2.

2、Initiate the switchover on the primary database.

To change the current primary database to a physical standby database role, use the following SQL statement on the primary database:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

After this statement completes, the primary database is converted into a standby database. The current control file is backed up to the current SQL session trace file before the switchover. This makes it possible to reconstruct a current control file,
if necessary.



Adding the WITH SESSION SHUTDOWN clause after ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY if you the SWITCHOVER_STATUS returns 'SESSIONS ACTIVE' state, you can also switch the primary database to physical standby successfully.

After this statement completes, the primary database is converted into a standby database. The current control file is backed up to the current SQL session trace file before the switchover. This makes it possible to reconstruct a current control file, if
necessary.

3、Shut down and restart the former primary instance.

Shut down the former primary instance, and restart and mount the database:

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP MOUNT;

4、Verify the switchover status of the orginal primary in the V$DATABASE view.

19:30:33 sys@CUUG> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS

--------------------

TO PRIMARY

Elapsed: 00:00:00.06

5、Switch the target physical standby database role to the primary role.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

6、Finish the transition of the standby database to the primary role.

The task you perform is dependent on if the physical standby database has ever been opened in read-only mode:

Executing ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION ; on the cuug database

-------Alter the new standby database to the recovery mode.

If the physical standby database has not been opened in read-only mode since the last time it was started, issue the SQL ALTER DATABASE OPEN statement to open the new primary database:

SQL> ALTER DATABASE OPEN;

Then, go to step 7.

If the physical standby database has been opened in read-only mode since the last time it was started, you must shut down the target standby database and restart it:

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP;

7、Switch log file in the new Primary database to check whether the archive log is generated in the its archive log dir.And congratuations to you if so.

initialization parameters as followings:

DB_NAME=cuug

DB_UNIQUE_NAME=$ORACLE_SID

LOG_ARCHIVE_CONFIG='DG_CONFIG=(cuug,cuuo)'

LOG_ARCHIVE_DEST_1='LOCATION=${ORACLE_BASE}/oradata/${ORACLE_SID}/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=${ORACLE_SID}'

LOG_ARCHIVE_DEST_2='SERVICE=${STANDBY_SID} LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=${STANDBY_SID}'



FAL_SERVER=cuuo

FAL_CLIENT=${ORACLE_SID}

DB_FILE_NAME_CONVERT='${ORACLE_BASE}/oradata/${STANDBY_SID}/','${ORACLE_BASE}/oradata/${ORACLE_SID}/'

LOG_FILE_NAME_CONVERT='${ORACLE_BASE}/oradata/${STANDBY_SID}/','${ORACLE_BASE}/oradata/${ORACLE_SID}/'

STANDBY_FILE_MANAGEMENT=AUTO

转载请注明出处及原文链接:
http://blog.csdn.net/xiangsir/article/details/8572883
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: