| 订阅 | 在线投稿
分享
 
 
 

配置Windows与Linux平台的DATA GURAD

来源:互联网  宽屏版  评论
2008-06-01 03:36:36

从Oracle 11g数据库开始,Oracle支持在特定条件下Windows与Linux两个不同OS平台之间配置DATA GUARD,这样DATA GUARD再也不受原来需要同样OS平台的限制了(具体参考Metalink:413484.1):

配置过程示例:

主库:Windows 2003 +Oracle 11.1.0.6

SID:orcl

数据文件目录:D:\ORACLE\ORADATA\ORCL\

备用库:RHEL 4 U5+Oracle 11.1.0.6

SID:standby

数据文件目录:/home/oracle/opt/oradata/standby/

1、验证主库是归档模式,并将主库置于FORCE LOGGING模式:

SQL> archive log list

Database log mode Archive Mode

Automatic archival Enabled

Archive destination USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 229

Next log sequence to archive 231

Current log sequence 231

SQL> alter database force logging;

2、对主库做一个全库的RMAN备份,用于STANDBY配置:

RMAN> backup database format 'd:\db_%U.bak';

3、准备STANDBY数据文件路径和其他路径:

[oracle@test51 oradata]$ pwd

/home/oracle/opt/oradata

[oracle@test51 oradata]$ mkdir standby

[oracle@test51 oradata]$ cd standby

[oracle@test51 oradata]$ mkdir archive

[oracle@test51 oradata]$ cd $ORACLE_BASE/admin

[oracle@test51 admin]$ mkdir standby

[oracle@test51 oradata]$ cd standby

[oracle@test51 standby]$mkdir adump

[oracle@test51 standby]$mkdir dpdump

[oracle@test51 standby]$mkdir pfile

[oracle@test51 standby]$ ls

adump dpdump pfile

4、生成standby 初始化参数文件:

SQL> create pfile='d:/init.ora' from spfile;

添加以下几个STANDBY参数:

*.log_archive_config=’DG_CONFIG=(orcl,standby)’

*.fal_client=’standby’

*.fal_server=’primary’

*.db_file_name_convert=’D:\ORACLE\ORADATA\ORCL\’,'/home/oracle/opt/oradata/standby/’

*.log_file_name_convert=’D:\ORACLE\ORADATA\ORCL\’,'/home/oracle/opt/oradata/standby/’

*.standby_file_management=’auto’

*.log_archive_dest_1=’location=/home/oracle/opt/oradata/standby/archive VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)’

5、生成STANDBY控制文件:

SQL> alter database create standby controlfile as 'd:\ control01.ctl';

并将生成的STANDBY控制文件、初始化参数文件、备份集分别COPY至STANDBY端相应的目录,另外注意密码文件也需要COPY并在STANDBY端改名,因为主库和备库需要相同的密码文件,否则STANDBY无法配置成功:

[oracle@test51 standby]$ cp control01.ctl control02.ctl

[oracle@test51 standby]$ cp control01.ctl control03.ctl

[oracle@test51 standby]$ ls

archive control01.ctl control02.ctl control03.ctl db_04j3dk0q_1_1.bak db_05j3dk6n_1_1.bak

6、在STANDBY端MOUNT STANDBY数据库,可以看到从WINDOWS COPY过来的备份控制文件可以直接在LINUX底下MOUNT成功:

idle> startup mount pfile='/home/oracle/opt/admin/standby/pfile/init_standby.ora';

7、RESTORE STANDBY数据库:

由于控制文件里面记录的备份信息还是在WINDOWS上主库的备份信息,我们需要使用RMAN的catalog命令来使RMAN认出在STANDBY端从WINDOWS主库COPY过来的备份集:

RMAN> catalog start with '/home/oracle/opt/oradata/standby';

using target database control file instead of recovery catalog

searching for all files that match the pattern /home/oracle/opt/oradata/standby

List of Files Unknown to the Database

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

File Name: /home/oracle/opt/oradata/standby/db_05j3dk6n_1_1.bak

File Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak

Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done

List of Cataloged Files

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

File Name: /home/oracle/opt/oradata/standby/db_05j3dk6n_1_1.bak

File Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak

RMAN> crosscheck backup;

RMAN> delete expired backup;

等到RMAN能够正切认出STANDBY端的备份集后,我们就可以对数据库进行RESTORE了:

RMAN> list backup;

List of Backup Sets

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

3 Full 1.75G DISK 00:03:03 12-DEC-07

BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20071212T104026

Piece Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak

RMAN> restore database;

Starting restore at 12-DEC-07

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /home/oracle/opt/oradata/standby/SYSTEM01.DBF

channel ORA_DISK_1: restoring datafile 00002 to /home/oracle/opt/oradata/standby/SYSAUX01.DBF

channel ORA_DISK_1: restoring datafile 00003 to /home/oracle/opt/oradata/standby/UNDOTBS01.DBF

channel ORA_DISK_1: restoring datafile 00004 to /home/oracle/opt/oradata/standby/USERS01.DBF

channel ORA_DISK_1: restoring datafile 00005 to /home/oracle/opt/oradata/standby/EXAMPLE01.DBF

channel ORA_DISK_1: reading from backup piece /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak

channel ORA_DISK_1: piece handle=/home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak tag=TAG20071212T104026

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:01:05

Finished restore at 12-DEC-07

8、在主库和备用库端分别更改tnsnames配置,添加主库和备用库的TNS连接字,并确保在主库和STANDBY都能够连接上对方:

primary =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl)

)

)

standby =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = standby)

)

)

9、添加STANDBY LOGFILE,启动STANDBY至恢复管理模式:

idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo04.log' size 50M;

idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo05.log' size 50M;

idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo06.log' size 50M;

idle> recover managed standby database disconnect from session;

Media recovery complete.

10、主库配置到STANDBY的归档,另外注意主库需要设置log_archive_config这个参数,否则归档将不会从主库传至STANDBY端:

Sys@orcl> alter system set log_archive_dest_2='service=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby';

Sys@orcl> alter system set log_archive_dest_state_2=enable;

Sys@orcl> alter system set log_archive_config='DG_CONFIG=(orcl,standby)';

这样异构STANDBY就配置成功了。

11、测试STANDBY切换,注意在测试前要在主库端和备库端都准备好主库和备库的两种参数文件:

首先在主库端将主库切换为备库:

SQL> alter database commit to switchover to physical standby with session shutdown ;

SQL> startup mount pfile='d:\init_standby.ora'

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

再在备库端将备库切换为主库:

idle> alter database commit to switchover to primary;

idle> shutdown

idle> startup pfile='/home/oracle/opt/admin/standby/pfile/init.ora'

ORACLE instance started.

Total System Global Area 836976640 bytes

Fixed Size 1303132 bytes

Variable Size 595594660 bytes

Database Buffers 234881024 bytes

Redo Buffers 5197824 bytes

Database mounted.

Database opened.

至此,切换顺利完成。

从Oracle 11g数据库开始,Oracle支持在特定条件下Windows与Linux两个不同OS平台之间配置DATA GUARD,这样DATA GUARD再也不受原来需要同样OS平台的限制了(具体参考Metalink:413484.1): 配置过程示例: 主库:Windows 2003 +Oracle 11.1.0.6 SID:orcl 数据文件目录:D:\ORACLE\ORADATA\ORCL\ 备用库:RHEL 4 U5+Oracle 11.1.0.6 SID:standby 数据文件目录:/home/oracle/opt/oradata/standby/ 1、验证主库是归档模式,并将主库置于FORCE LOGGING模式: SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 229 Next log sequence to archive 231 Current log sequence 231 SQL> alter database force logging; 2、对主库做一个全库的RMAN备份,用于STANDBY配置: RMAN> backup database format 'd:\db_%U.bak'; 3、准备STANDBY数据文件路径和其他路径: [oracle@test51 oradata]$ pwd /home/oracle/opt/oradata [oracle@test51 oradata]$ mkdir standby [oracle@test51 oradata]$ cd standby [oracle@test51 oradata]$ mkdir archive [oracle@test51 oradata]$ cd $ORACLE_BASE/admin [oracle@test51 admin]$ mkdir standby [oracle@test51 oradata]$ cd standby [oracle@test51 standby]$mkdir adump [oracle@test51 standby]$mkdir dpdump [oracle@test51 standby]$mkdir pfile [oracle@test51 standby]$ ls adump dpdump pfile 4、生成standby 初始化参数文件: SQL> create pfile='d:/init.ora' from spfile; 添加以下几个STANDBY参数: *.log_archive_config=’DG_CONFIG=(orcl,standby)’ *.fal_client=’standby’ *.fal_server=’primary’ *.db_file_name_convert=’D:\ORACLE\ORADATA\ORCL\’,'/home/oracle/opt/oradata/standby/’ *.log_file_name_convert=’D:\ORACLE\ORADATA\ORCL\’,'/home/oracle/opt/oradata/standby/’ *.standby_file_management=’auto’ *.log_archive_dest_1=’location=/home/oracle/opt/oradata/standby/archive VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)’ 5、生成STANDBY控制文件: SQL> alter database create standby controlfile as 'd:\ control01.ctl'; 并将生成的STANDBY控制文件、初始化参数文件、备份集分别COPY至STANDBY端相应的目录,另外注意密码文件也需要COPY并在STANDBY端改名,因为主库和备库需要相同的密码文件,否则STANDBY无法配置成功: [oracle@test51 standby]$ cp control01.ctl control02.ctl [oracle@test51 standby]$ cp control01.ctl control03.ctl [oracle@test51 standby]$ ls archive control01.ctl control02.ctl control03.ctl db_04j3dk0q_1_1.bak db_05j3dk6n_1_1.bak 6、在STANDBY端MOUNT STANDBY数据库,可以看到从WINDOWS COPY过来的备份控制文件可以直接在LINUX底下MOUNT成功: idle> startup mount pfile='/home/oracle/opt/admin/standby/pfile/init_standby.ora'; 7、RESTORE STANDBY数据库: 由于控制文件里面记录的备份信息还是在WINDOWS上主库的备份信息,我们需要使用RMAN的catalog命令来使RMAN认出在STANDBY端从WINDOWS主库COPY过来的备份集: RMAN> catalog start with '/home/oracle/opt/oradata/standby'; using target database control file instead of recovery catalog searching for all files that match the pattern /home/oracle/opt/oradata/standby List of Files Unknown to the Database ===================================== File Name: /home/oracle/opt/oradata/standby/db_05j3dk6n_1_1.bak File Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak Do you really want to catalog the above files (enter YES or NO)? yes cataloging files... cataloging done List of Cataloged Files ======================= File Name: /home/oracle/opt/oradata/standby/db_05j3dk6n_1_1.bak File Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak RMAN> crosscheck backup; RMAN> delete expired backup; 等到RMAN能够正切认出STANDBY端的备份集后,我们就可以对数据库进行RESTORE了: RMAN> list backup; List of Backup Sets BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 3 Full 1.75G DISK 00:03:03 12-DEC-07 BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20071212T104026 Piece Name: /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak RMAN> restore database; Starting restore at 12-DEC-07 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /home/oracle/opt/oradata/standby/SYSTEM01.DBF channel ORA_DISK_1: restoring datafile 00002 to /home/oracle/opt/oradata/standby/SYSAUX01.DBF channel ORA_DISK_1: restoring datafile 00003 to /home/oracle/opt/oradata/standby/UNDOTBS01.DBF channel ORA_DISK_1: restoring datafile 00004 to /home/oracle/opt/oradata/standby/USERS01.DBF channel ORA_DISK_1: restoring datafile 00005 to /home/oracle/opt/oradata/standby/EXAMPLE01.DBF channel ORA_DISK_1: reading from backup piece /home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak channel ORA_DISK_1: piece handle=/home/oracle/opt/oradata/standby/db_04j3dk0q_1_1.bak tag=TAG20071212T104026 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:05 Finished restore at 12-DEC-07 8、在主库和备用库端分别更改tnsnames配置,添加主库和备用库的TNS连接字,并确保在主库和STANDBY都能够连接上对方: primary = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.168)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) standby = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.200.169)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) ) 9、添加STANDBY LOGFILE,启动STANDBY至恢复管理模式: idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo04.log' size 50M; idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo05.log' size 50M; idle> alter database add standby logfile '/home/oracle/opt/oradata/standby/redo06.log' size 50M; idle> recover managed standby database disconnect from session; Media recovery complete. 10、主库配置到STANDBY的归档,另外注意主库需要设置log_archive_config这个参数,否则归档将不会从主库传至STANDBY端: Sys@orcl> alter system set log_archive_dest_2='service=standby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'; Sys@orcl> alter system set log_archive_dest_state_2=enable; Sys@orcl> alter system set log_archive_config='DG_CONFIG=(orcl,standby)'; 这样异构STANDBY就配置成功了。 11、测试STANDBY切换,注意在测试前要在主库端和备库端都准备好主库和备库的两种参数文件: 首先在主库端将主库切换为备库: SQL> alter database commit to switchover to physical standby with session shutdown ; SQL> startup mount pfile='d:\init_standby.ora' SQL> alter database recover managed standby database disconnect from session; 再在备库端将备库切换为主库: idle> alter database commit to switchover to primary; idle> shutdown idle> startup pfile='/home/oracle/opt/admin/standby/pfile/init.ora' ORACLE instance started. Total System Global Area 836976640 bytes Fixed Size 1303132 bytes Variable Size 595594660 bytes Database Buffers 234881024 bytes Redo Buffers 5197824 bytes Database mounted. Database opened. 至此,切换顺利完成。
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有