1.     在主库进行下面配置

1.1  确认主数据库运行在归档模式下

              使用下面命令确定主数据库处于归档模式下:

                     SQL> archive log list;

              如果主数据库未处于归档模式下,使用下面命令设置主数据库:

                     SQL> shutdown immediate;  --立即关闭数据库

                     SQL> startup mount;                     --开启数据库到mount状态

                     SQL> alter database archivelog;   --将数据库修改为归档模式

                     SQL> alter database open;     --将数据库修改为open状态

1.2  确认主库强制写日志

                     SQL> select force_logging from v$database; --查看数据库是否处于归档模式

                     SQL> alter database force logging;     --修改模式为强制写日志,所有sql语句nologging操作时 也会强制写日志

1.3  配置主数据库的监听文件与传输文件

              配置监听文件

                     [oracle@oracle1 ~]$ vim /oracle/app/oracle/praduct/10.2.0/db_1/network/admin/listener.ora

                     SID_LIST_LISTENER =

                                   (SID_LIST =

                                          (SID_DESC =

                                                 (GLOBAL_DBNAME = TEST)

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

                                   (SID_NAME = TEST)

                                          )

                                   )

 

                            LISTENER =

                                   (DESCRIPTION =

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

                            )

              配置传输文件

                     [oracle@oracle1 ~]$ vim /oracle/app/oracle/praduct/10.2.0/db_1/network/admin/tnsnames.ora

                            DB102 =

                                   (DESCRIPTION =

                                          (ADDRESS_LIST =

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

                                          )

                                   (CONNECT_DATA =

                                          (SERVICE_NAME = TEST)

                                   )

                            )

              启动监听服务

                     [oracle@oracle1 ~]$ lsnrctl status       //查看监听服务状态

                     [oracle@oracle1 ~]$ lsnrctl start  //开启监听服务

1.4  修改主数据库的参数文件(spfile

              建立pfile文件

                     SQL> create pfile from spfile

              pfile中加入下面内容

                     vim /oracle/app/oracle/product/10.2.0/db_1/dbs/initTEST.ora

                            DB_UNIQUE_NAME=TEST      --show parameter DB_UNIQUE_NAME确认主库名称

                            LOG_ARCHIVE_CONFIG='DG_CONFIG=(DB101,DB102)' --此处为主库网络连接串(tnsnames.ora)

                            LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/archive  VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=TEST'  --主库的归档日志路径

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

                            FAL_SERVER=DB101 --网络异常恢复后自动将延迟的归档日志传输到备库,此处为主库网络连接串(tnsnames.ora)

                            FAL_CLIENT=DB102

                            STANDBY_FILE_MANAGEMENT=AUTO       --默认只传递数据,此作用主库把新创建的数据文件也传到备库

              重启数据库

                     SQL> shutdown immediate

                     SQL> startup pfile='/oracle/app/oracle/praoduct/10.2.0/db_1/dbs/initTEST.ora'

                     或模拟spfile失效

                     [oracle@oracle1 ~]$ mv /oracle/app/oracle/praoduct/10.2.0/db_1/dbs/spfileTEST.ora spfile.TEST.ora.bak

                     SQL> startup

              查看建立的pfile文件是否生效

                     SQL> show parameter fal

              如果生效,pfile生效,使用pfile重建spfile

                     create spfile from pfile

1.5  全库备份主数据库(应该在从库配置完成(2.4)后进行)

              备份主数据库

                     RMAN> backup full database format='/home/oracle/db_bak/%U' include current controlfile for standby;

              还原从数据库(需要先执行2.5操作)

                     RMAN> connect auxiliary sys/123456@DB102       --连接从库

                     RMAN> duplicate target database for standby nofilenamecheck;   --还原从数据库

2.     配置灾备数据库

2.1  在灾备数据库服务器中安装Oracle软件,保证服务器的环境变量、数据库的实例名、数据库的字符集与主数据库相同。

              在主数据库中使用下面命令查看主数据库的字符集:

                     SQL> select * from nls_database_parameters where parameter='NLS_CHARACTERSET';

2.2  配置从库监听服务与传输文件

              配置监听文件

                     [oracle@oracle2 ~]$ vim /oracle/app/oracle/praduct/10.2.0/db_1/network/admin/listener.ora

                            SID_LIST_LISTENER =

                                   (SID_LIST =

                                          (SID_DESC =

                                                 (GLOBAL_DBNAME = TEST)

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

                                   (SID_NAME = TEST)

                                          )

                                   )

 

                            LISTENER =

                                   (DESCRIPTION =

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

                            )

              配置传输文件

                     [oracle@oracle2 ~]$ vim /oracle/app/oracle/praduct/10.2.0/db_1/network/admin/tnsnames.ora

                            DB101 =

                                   (DESCRIPTION =

                                          (ADDRESS_LIST =

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

                                          )

                                   (CONNECT_DATA =

                                          (SERVICE_NAME = TEST)

                                   )

                            )

              开启监听

                     [oracle@oralce2 ~]$ lsnrctl start

2.3  配置从库的spfile,追加下面内容

                     DB_UNIQUE_NAME=TEST      --show parameter DB_UNIQUE_NAME

                     LOG_ARCHIVE_CONFIG='DG_CONFIG=(DB101,DB102)'

                     LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/archive  VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=TEST'

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

                     FAL_SERVER=DB102

                     FAL_CLIENT=DB101

                     STANDBY_FILE_MANAGEMENT=AUTO

2.4  关闭数据库并重新开启到nomount状态

                     SQL> startup nomount force;

2.5  还原从库,使从库与主库数据保持一致

              复制密码文件

                     [oracle@oracle2 ~]$ scp [email protected]:/$ORACLE_HOME/dbs/orapwTEST $ORACLE_HOME/dbs/

              将主库备份的文件拷贝到从库

                     [oracle@oracle2 ~]$ mkdir -pv /home/oracle/db_bak/

                     [oracle@oracle2 ~]$ scp [email protected]:/home/oracle/db_bak/*  /home/oracle/db_bak/

              回复完成,从数据库自动开启到mount状态

                     SQL> select open_mode from v$database;      --查看数据库状态

 

3.     测试主数据库与灾备数据库之间的通讯

3.1  在主数据库上切换日志组并查询进程

              当查询结果含有LNS,说明主数据库能够像灾备数据库传递日志文件

                     SQL> alter system switch logfile;  --切换日志组

                     SQL> select process from v$managed_standby;     --查看进程

                            PROCESS

                            ---------

                            ARCH

                            ARCH

                            LNS

3.2         在灾备数据库中查看是否能够正常开启RFS进程

                     SQL> SQL> select process from v$managed_standby;

                            PROCESS

                            ---------

                            ARCH

                            ARCH

                            RFS

                            RFS

3.3         开启灾备数据库的MRP恢复进程

                     SQL> alter database recover managed standby database disconnect from session;

 

4.     验证灾备

4.1  在主数据库中建立表或插入数据

4.2         切换主数据库的在线日志组

4.3         关闭备份库的MRP进程并将备份库更改为open状态,验证

              关闭Mrp进程

                     SQL> alter database recover managed standby database cancel;

PS.

=================================================

1)备用数据库在日志恢复过程中(MRP进程存在期间)数据库处于MOUNTED状态,此时备用数据库无法打开供读取使用

2)打开备用数据库

     停止备用库的日志恢复进程MRP

     alter database recover managed standby database cancel;

     open备用数据库,备用数据库默认打开为只读方式

     alter database open;

3)重新启动备用数据库的MRP进程,数据库自动从OPEN状态转换到MOUNT 状态

     alter database recover managed standby database disconnect from session;

4mrp进程停止期间,只要RFS进程存在,那么不影响日志的接收

====================================================