| 導購 | 订阅 | 在线投稿
分享
 
 
 

配置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. 至此,切換順利完成。
󰈣󰈤
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
王朝網路微信公眾號
微信掃碼關註本站公眾號 wangchaonetcn
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有