RAC環境下創建物理DATA GUARD

爲一個RAC搭建standby和單節點搭建方法基本一致,我們可以把RAC看成是一個單節點的數據庫,只需要保證所有節點的日誌能傳送到備庫即可。
一、在備庫服務器安裝ORACLE軟件

只安裝軟件,不要創建數據庫。ORACLE軟件版本和主庫保持一致。

二、修改主庫參數

節點1執行:
SQL> show parameter spfile
NAME TYPE VALUE
------- ------ -------------------------
spfile string /dev/raw/raw14


節點2執行:
SQL> show parameter spfile
NAME TYPE VALUE
------- ------ -------------------------
spfile string /dev/raw/raw14

可見,在本例中,RAC各節點共用一個spfile,所以,我們修改參數時,可以只需在一個節點下修改就可以了。

--強制數據庫LOGGING
SQL> ALTER DATABASE FORCE LOGGING;
Database altered.

--修改DATA GUARD相關參數
SQL> ALTER SYSTEM SET DB_UNIQUE_NAME=primary scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)' scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/soft/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary' scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby' scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=spfile;
System altered.

SQL> ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' scope=spfile;
System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4 scope=spfile;
System altered.

SQL> ALTER SYSTEM SET COMPATIBLE = '10.2.0.3' scope=spfile;
System altered.


--以下幾個參數是爲了SWITCH OVER用的,是可選參數。
--
但是爲了以後可能發生的SWITCH OVER更方便,應該養成設置這些參數的習慣

SQL> ALTER SYSTEM SET FAL_CLIENT = PRIMARY SCOPE=SPFILE;
System altered.

SQL> ALTER SYSTEM SET FAL_SERVER = STANDBY SCOPE=SPFILE;
System altered.

SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO SCOPE=SPFILE;
System altered.

SQL> ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/soft/oradata/rac/','/dev/raw/' SCOPE=SPFILE;
System altered.

SQL> ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/soft/oradata/rac/','/dev/raw/' SCOPE=SPFILE;
System altered.

--在本文測試環境下,由於主庫和備庫路徑不一致,所以要設置路徑轉換參數。

三、修改主庫爲歸檔模式

1--關閉所有實例

--注意:修改以上參數後,必須把所有實例都關閉。否則在啓動實例的時候可能會導致錯誤:
--ORA-00600: internal error code, arguments: [kccsbck_first], [2], [2241198041],[], [], [], [], []

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2、修改爲歸檔模式

--關閉所有節點
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

--在其中一個節點啓用歸檔
SQL> startup mount
ORACLE instance started.
Total System Global Area 159383552 bytes
Fixed Size 1260672 bytes
Variable Size 79692672 bytes
Database Buffers 75497472 bytes
Redo Buffers 2932736 bytes
Database mounted.

SQL> alter database archivelog;
Database altered.

SQL> alter database open;
Database altered.

10GR2以前,在RAC環境下修改歸檔必須先把設置參數cluster_database=false,把數據庫設置爲歸檔後再把該參數設置爲true,但這個步驟在10GR2可以省略。

四、備份數據庫

1、備份數據庫

備份操作在節點1(rac1)上執行。
由於歸檔在不同的節點下,故要連接所有節點進行備份:

[oracle@rac1 ~]$ $ORACLE_HOME/bin/rman target / 
Recovery Manager: Release 10.2.0.3.0 - Production on Wed Apr 30 14:48:23 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: RAC (DBID=2232067446)

RMAN> run
2> {
3> allocate channel c1 device type disk format '/soft/backup/%U' connect 
sys/test@rac1;
4> allocate channel c2 device type disk format '/soft/backup/%U' connect 
sys/test@rac2;
5> backup database plus archivelog delete all input;
6> }

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=134 instance=rac1 devtype=DISK
allocated channel: c2
channel c2: sid=141 instance=rac2 devtype=DISK
Starting backup at 30-APR-08
current log archived
channel c1: starting archive log backupset
channel c1: specifying archive log(s) in backup set
input archive log thread=1 sequence=80 recid=1 stamp=653247673
input archive log thread=1 sequence=81 recid=4 stamp=653268228
......
channel c1: backup set complete, elapsed time: 00:00:04
channel c1: deleting archive log(s)
archive log filename=/soft/archivelog/2_50_644085430.arc recid=18 stamp=653410279
Finished backup at 30-APR-08
released channel: c1
released channel: c2

2、生成備庫控制文件

RMAN> run 
2> {
3> allocate channel c1 device type disk format '/soft/backup/CON_%U';
4> backup current controlfile for standby;
5> }

allocated channel: c1
channel c1: sid=131 instance=rac1 devtype=DISK
Starting backup at 30-APR-08
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
including standby control file in backupset
channel c1: starting piece 1 at 30-APR-08
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/CON_0ajf4gqi_1_1 tag=TAG20080430T150554 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:12
Finished backup at 30-APR-08
released channel: c1

爲一個RAC搭建standby和單節點搭建方法基本一致,我們可以把RAC看成是一個單節點的數據庫,只需要保證所有節點的日誌能傳送到備庫即可。

五、備庫環境準備

1、在備庫添加指向主庫的tnsnames

在備庫的tnsnames.ora添加如下內容:
primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 200.200.200.11)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 200.200.200.22)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = primary)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)

)

2、在備庫創建相關目錄

包括adump,bdump,cdump,udump及數據文件目錄等。

3、拷貝主庫的密碼文件到備庫上

--拷貝rac1的密碼文件到備庫的$ORACLE_HOME/dbs下,並把該密碼文件修改爲orapwd<sid>。這裏我的sid就用rac1,所以,不用改名。
--
使用orapwd重新創建密碼文件也可。

[oracle@rac1 dbs]$ scp orapwrac1 172.25.0.35:`pwd`
orapwrac1 100% 1536 1.5KB/s 00:00 

4、配置備庫的監聽

[oracle@standby admin]$ more listener.ora 
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = standby)
(ORACLE_HOME = /opt/oracle/product/10.2/database)
(SID_NAME = rac1)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)

啓動備庫監聽:lsnrctl start

5、設置備庫參數文件

從主庫rac1上根據spfile創建一個pfile文件,並傳到備庫上。

SQL> create pfile from spfile;
File created.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Real Application Clusters and Data Mining options

[oracle@rac1 ~]$ cd $ORACLE_HOME/dbs
[oracle@rac1 dbs]$ scp initrac1.ora 172.25.0.35:`pwd`
initrac1.ora 

在備庫上修改參數文件:

刪除所有非”*”打頭的參數設置及rac相關參數
設置dataguard參數
修改後參數如下:

[oracle@standby dbs]$ more initrac1.ora 

*.audit_file_dest='/opt/oracle/admin/rac/adump'
*.background_dump_dest='/opt/oracle/admin/rac/bdump'
*.compatible='10.2.0.3'
*.control_files='/soft/oradata/rac/control01.ctl','/soft/oradata/rac/control02.ctl','/soft/oradata/rac/control03.ctl'
*.core_dump_dest='/opt/oracle/admin/rac/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='/DEV/RAW/','/SOFT/ORADATA/RAC/'
*.db_name='rac'
*.db_unique_name='STANDBY'
*.fal_client='STANDBY'
*.fal_server='PRIMARY'
*.job_queue_processes=10
*.log_archive_config='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='LOCATION= /soft/oradata/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
*.log_archive_dest_2='SERVICE=primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=4
*.log_file_name_convert='/DEV/RAW/','/SOFT/ORADATA/RAC/'
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=157286400
*.sga_target=157286400
*.standby_file_management='AUTO'
*.undo_management='AUTO'
undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/oracle/admin/rac/udump'

以上有些參數非必須設置的,但是爲了switchover更方便,建議都修改上。
Undo
表空間保留其中一個就可以。
路徑轉換相關參數要設置對,否則會報錯。

6、把備庫啓動到nomount狀態

[oracle@standby ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Apr 30 18:42:39 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.
Total System Global Area 159383552 bytes
Fixed Size 1260672 bytes
Variable Size 62915456 bytes
Database Buffers 92274688 bytes
Redo Buffers 2932736 bytes

7、從主庫拷貝備份到備庫上

之前備份的所有文件都拷貝到備庫上,路徑要和主庫備份路徑保持一致。如果不一致,linux下可以用ln的方式解決。
注意:兩個節點都有歸檔的備份,要把這些備份都拷貝到備庫上。

RAC1
[oracle@rac1 backup]$ scp * 172.25.0.35:`pwd`
01jf4fqq_1_1 100% 23MB 3.8MB/s 00:06 
03jf4fr9_1_1 100% 194KB 194.0KB/s 00:00 
04jf4frg_1_1 100% 315MB 3.4MB/s 01:34 
08jf4fv9_1_1 100% 13KB 13.0KB/s 00:00 
09jf4fvf_1_1 100% 4608 4.5KB/s 00:00 
CON_0ajf4gqi_1_1 100% 15MB 3.7MB/s 00:04 

RAC2
[oracle@rac2 backup]$ scp * 172.25.0.35:`pwd`
02jf4fql_1_1 100% 7145KB 3.5MB/s 00:02 
05jf4frg_1_1 100% 175MB 3.4MB/s 00:52 
06jf4ft0_1_1 100% 15MB 1.5MB/s 00:10 
07jf4ftm_1_1 100% 96KB 96.0KB/s 00:00 

六、恢復備庫

1、在主庫添加指向備庫的tnsname

在主庫的tnsnames.ora添加如下內容:
STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =200.200.200.123)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)

2、在主庫執行,利用auxiliary來恢復備庫

[oracle@rac1 ~]$ $ORACLE_HOME/bin/rman target / auxiliary sys/6212327@standby
Recovery Manager: Release 10.2.0.3.0 - Production on Wed Apr 30 19:37:05 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: RAC (DBID=2232067446)
connected to auxiliary database: RAC (not mounted)

RMAN> run
{

allocate channel c1 device type disk format '/soft/backup/%U' connect sys/6212327@rac1;
2> 3> 4> allocate channel c2 device type disk format '/soft/backup/%U' connect 
sys/6212327@rac2;
5> allocate auxiliary channel ac1 device type disk format '/soft/backup/%U'; 
6> allocate auxiliary channel ac2 device type disk format '/soft/backup/%U';
7> duplicate target database for standby;
8> }
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=132 instance=rac1 devtype=DISK
allocated channel: c2
channel c2: sid=134 instance=rac2 devtype=DISK
allocated channel: ac1
channel ac1: sid=155 devtype=DISK
allocated channel: ac2
channel ac2: sid=154 devtype=DISK
Starting Duplicate Db at 30-APR-08

contents of Memory Script:
{
restore clone standby controlfile;
sql clone 'alter database mount standby database';
}
executing Memory Script

Starting restore at 30-APR-08
channel ac1: starting datafile backupset restore
channel ac1: restoring control file
channel ac1: reading from backup piece /soft/backup/CON_0ajf4gqi_1_1
channel ac1: restored backup piece 1
piece handle=/soft/backup/CON_0ajf4gqi_1_1 tag=TAG20080430T150554
channel ac1: restore complete, elapsed time: 00:00:04
output filename=/soft/oradata/rac/control01.ctl
output filename=/soft/oradata/rac/control02.ctl
output filename=/soft/oradata/rac/control03.ctl
Finished restore at 30-APR-08

sql statement: alter database mount standby database
contents of Memory Script:

{
set newname for tempfile 1 to "/soft/oradata/rac/raw6";
switch clone tempfile all;
set newname for datafile 1 to "/soft/oradata/rac/raw1";
set newname for datafile 2 to "/soft/oradata/rac/raw3";
set newname for datafile 3 to "/soft/oradata/rac/raw2";
set newname for datafile 4 to "/soft/oradata/rac/raw5";
set newname for datafile 5 to "/soft/oradata/rac/raw7";
restore
check readonly
clone database
;
}

executing Memory Script
executing command: SET NEWNAME
renamed temporary file 1 to /soft/oradata/rac/raw6 in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 30-APR-08
channel ac1: starting datafile backupset restore
channel ac1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /soft/oradata/rac/raw3
restoring datafile 00004 to /soft/oradata/rac/raw5
channel ac1: reading from backup piece /soft/backup/05jf4frg_1_1
channel ac2: starting datafile backupset restore
channel ac2: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /soft/oradata/rac/raw1
restoring datafile 00003 to /soft/oradata/rac/raw2
restoring datafile 00005 to /soft/oradata/rac/raw7
channel ac2: reading from backup piece /soft/backup/04jf4frg_1_1
channel ac1: restored backup piece 1
piece handle=/soft/backup/05jf4frg_1_1 tag=TAG20080430T144919
channel ac1: restore complete, elapsed time: 00:01:22
channel ac2: restored backup piece 1
piece handle=/soft/backup/04jf4frg_1_1 tag=TAG20080430T144919
channel ac2: restore complete, elapsed time: 00:01:32
Finished restore at 30-APR-08

contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=653426781 filename=/soft/oradata/rac/raw1
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=653426781 filename=/soft/oradata/rac/raw3
datafile 3 switched to datafile copy
input datafile copy recid=8 stamp=653426781 filename=/soft/oradata/rac/raw2
datafile 4 switched to datafile copy
input datafile copy recid=9 stamp=653426781 filename=/soft/oradata/rac/raw5
datafile 5 switched to datafile copy
input datafile copy recid=10 stamp=653426781 filename=/soft/oradata/rac/raw7
Finished Duplicate Db at 30-APR-08

released channel: c1
released channel: c2
released channel: ac1
released channel: ac2

從日誌可以看到,oracle先根據參數文件把控制文件恢復到合適位置,然後再根據db_file_name_cover把數據文件恢復到合適位置。

七、後續工作

1、把備庫置於恢復狀態:

[oracle@standby admin]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Apr 30 19:40:59 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Oracle Label Security and Data Mining options
SQL> alter database recover managed standby database disconnect from session;
Database altered

此時觀察備庫的alert文件,可以發現有很多類似的信息:
Errors in file /opt/oracle/admin/rac/bdump/rac1_mrp0_10825.trc:
ORA-00313: open failed for members of log group 4 of thread 2
ORA-00312: online log 4 thread 2: '/soft/oradata/rac/raw11'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Clearing online redo logfile 4 /soft/oradata/rac/raw11
Clearing online log 4 of thread 2 sequence number 50

這是正常的,在第一次置於recover狀態的時候,備庫會生成對應的online redo log


2、在備庫添加standby redo log

Standby redo logarchivelog方式有更大的優勢,且在最大保護、最大可用、實時恢復的情況下必須有standby redo log
Standby redo log
的組數一般爲(N +1)* thread# N分別爲每個thread#的聯機日誌組數)。
在本例,每一個thread的聯機日誌都是2組,所以,需要添加6standby redo log

SQL> alter database recover managed standby database cancel;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 ('/soft/oradata/rac/slog4.ora') SIZE 52428800;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 ('/soft/oradata/rac/slog5.ora') SIZE 52428800;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 ('/soft/oradata/rac/slog6.ora') SIZE 52428800;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 ('/soft/oradata/rac/slog7.ora') SIZE 52428800;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 ('/soft/oradata/rac/slog8.ora') SIZE 52428800;
Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 ('/soft/oradata/rac/slog9.ora') SIZE 52428800;
Database altered.

注意:standby redo log的大小必須和聯機日誌一樣。

八、遇到的問題

1、備庫嘗試拿gap的時候,發現不能連接主庫。

FAL[client, MRP0]: Error 12545 connecting to PRIMARY for fetching gap sequence

Wed Apr 30 20:21:23 2008
Errors in file /opt/oracle/admin/rac/bdump/rac1_mrp0_10965.trc:
ORA-12545: Connect failed because target host or object does not exist
Wed Apr 30 20:22:23 2008
FAL[client]: Failed to request gap sequence 
GAP - thread 1 sequence 88-88
DBID 2232067446 branch 644085430
FAL[client]: All defined FAL servers have been attempted.

這個問題和gap有關,備庫嘗試拿gap的時候,發現不能連接主庫。這個問題是RAC的監聽造成的,參考yangtingkun的解決方法,修改兩個參數即可:

ALTER SYSTEM SET LOCAL_LISTENER = '(ADDRESS = (PROTOCOL = TCP)(HOST = 200.200.200.11)(PORT = 1521))' SID = 'rac1';
ALTER SYSTEM SET LOCAL_LISTENER = '(ADDRESS = (PROTOCOL = TCP)(HOST = 200.200.200.22)(PORT = 1521))' SID = 'rac2';


2、備庫現在需要從主庫上拿sequence 88這個歸檔,但這個歸檔在前面做備份的時候刪除了。

Wed Apr 30 20:28:51 2008

FAL[client]: Failed to request gap sequence 
GAP - thread 1 sequence 88-88
DBID 2232067446 branch 644085430

FAL[client]: All defined FAL servers have been attempted.
-------------------------------------------------------------
Check that the CONTROL_FILE_RECORD_KEEP_TIME initialization
parameter is defined to a value that is sufficiently large
enough to maintain adequate log switch information to resolve
archivelog gaps.

這個問題還是和gap有關。備庫現在需要從主庫上拿sequence 88這個歸檔,但這個歸檔在前面做備份的時候刪除了。解決方法是從備份還原這個歸檔:

RMAN> restore archivelog sequence 88;
Starting restore at 30-APR-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=138 instance=rac1 devtype=DISK
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=88
channel ORA_DISK_1: reading from backup piece /soft/backup/08jf4fv9_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/soft/backup/08jf4fv9_1_1 tag=TAG20080430T145120
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章