RAC环境下创建物理DG

RAC环境下创建物理DATA GUARD

[@more@]

为一个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就用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 log比archivelog方式有更大的优势,且在最大保护、最大可用、实时恢复的情况下必须有standby redo log。
Standby redo log的组数一般为(N +1)* thread# (N分别为每个thread#的联机日志组数)。
在本例,每一个thread的联机日志都是2组,所以,需要添加6组standby 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

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21102096/viewspace-1018972/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21102096/viewspace-1018972/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值