Oracle 10g RAC环境下创建物理DATAGUARD
为一个RAC搭建standby和单节点搭建方法基本一致,我们可以把RAC看成是一个单节点的数据库,只需要保证所有节点的日志能传送到备库
为一个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.
--修改DATAGUARD相关参数
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
input archive log thread=1 sequence=82 recid=5 stamp=653353066
channel c1: starting piece 1 at 30-APR-08
channel c2: starting archive log backupset
channel c2: specifying archive log(s) in backup set
input archive log thread=1 sequence=85 recid=13 stamp=653409646
input archive log thread=2 sequence=42 recid=2 stamp=653248818
input archive log thread=2 sequence=43 recid=3 stamp=653250118
input archive log thread=2 sequence=46 recid=10 stamp=653353763
input archive log thread=2 sequence=47 recid=11 stamp=653354798
input archive log thread=2 sequence=48 recid=12 stamp=653409644
input archive log thread=2 sequence=49 recid=16 stamp=653410122
channel c2: starting piece 1 at 30-APR-08
channel c2: finished piece 1 at 30-APR-08
piece handle=/soft/backup/02jf4fql_1_1 tag=TAG20080430T144854 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:05
channel c2: deleting archive log(s)
archive log filename=/soft/archivelog/1_85_644085430.arc recid=13 stamp=653409646
archive log filename=/soft/archivelog/2_42_644085430.arc recid=2 stamp=653248818
archive log filename=/soft/archivelog/2_43_644085430.arc recid=3 stamp=653250118
archive log filename=/soft/archivelog/2_46_644085430.arc recid=10 stamp=653353763
archive log filename=/soft/archivelog/2_47_644085430.arc recid=11 stamp=653354798
archive log filename=/soft/archivelog/2_48_644085430.arc recid=12 stamp=653409644
archive log filename=/soft/archivelog/2_49_644085430.arc recid=16 stamp=653410122
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/01jf4fqq_1_1 tag=TAG20080430T144854 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:14
channel c1: deleting archive log(s)
archive log filename=/soft/archivelog/1_80_644085430.arc recid=1 stamp=653247673
archive log filename=/soft/archivelog/1_81_644085430.arc recid=4 stamp=653268228
archive log filename=/soft/archivelog/1_82_644085430.arc recid=5 stamp=653353066
channel c1: starting archive log backupset
channel c1: specifying archive log(s) in backup set
input archive log thread=1 sequence=83 recid=6 stamp=653353068
input archive log thread=1 sequence=84 recid=9 stamp=653353575
input archive log thread=1 sequence=86 recid=14 stamp=653409966
input archive log thread=1 sequence=87 recid=15 stamp=653410123
input archive log thread=2 sequence=44 recid=7 stamp=653353071
input archive log thread=2 sequence=45 recid=8 stamp=653353072
channel c1: starting piece 1 at 30-APR-08
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/03jf4fr9_1_1 tag=TAG20080430T144854 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:02
channel c1: deleting archive log(s)
archive log filename=/soft/archivelog/1_83_644085430.arc recid=6 stamp=653353068
archive log filename=/soft/archivelog/1_84_644085430.arc recid=9 stamp=653353575
archive log filename=/soft/archivelog/1_86_644085430.arc recid=14 stamp=653409966
archive log filename=/soft/archivelog/1_87_644085430.arc recid=15 stamp=653410123
archive log filename=/soft/archivelog/2_44_644085430.arc recid=7 stamp=653353071
archive log filename=/soft/archivelog/2_45_644085430.arc recid=8 stamp=653353072
Finished backup at 30-APR-08
Starting backup at 30-APR-08
channel c1: starting full datafile backupset
channel c1: specifying datafile(s) in backupset
input datafile fno=00001 name=/dev/raw/raw1
input datafile fno=00005 name=/dev/raw/raw7
input datafile fno=00003 name=/dev/raw/raw2
channel c1: starting piece 1 at 30-APR-08
channel c2: starting full datafile backupset
channel c2: specifying datafile(s) in backupset
input datafile fno=00002 name=/dev/raw/raw3
input datafile fno=00004 name=/dev/raw/raw5
channel c2: starting piece 1 at 30-APR-08
channel c2: finished piece 1 at 30-APR-08
piece handle=/soft/backup/05jf4frg_1_1 tag=TAG20080430T144919 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:43
channel c2: starting full datafile backupset
channel c2: specifying datafile(s) in backupset
including current control file in backupset
channel c2: starting piece 1 at 30-APR-08
channel c2: finished piece 1 at 30-APR-08
piece handle=/soft/backup/06jf4ft0_1_1 tag=TAG20080430T144919 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:22
channel c2: starting full datafile backupset
channel c2: specifying datafile(s) in backupset
including current SPFILE in backupset
channel c2: starting piece 1 at 30-APR-08
channel c2: finished piece 1 at 30-APR-08
piece handle=/soft/backup/07jf4ftm_1_1 tag=TAG20080430T144919 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:06
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/04jf4frg_1_1 tag=TAG20080430T144919 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:13
Finished backup at 30-APR-08
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=88 recid=17 stamp=653410237
channel c1: starting piece 1 at 30-APR-08
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/08jf4fv9_1_1 tag=TAG20080430T145120 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:04
channel c1: deleting archive log(s)
archive log filename=/soft/archivelog/1_88_644085430.arc recid=17 stamp=653410237
channel c1: starting archive log backupset
channel c1: specifying archive log(s) in backup set
input archive log thread=2 sequence=50 recid=18 stamp=653410279
channel c1: starting piece 1 at 30-APR-08
channel c1: finished piece 1 at 30-APR-08
piece handle=/soft/backup/09jf4fvf_1_1 tag=TAG20080430T145120 comment=NONE
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
[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