Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10167854
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: Oracle

2013-03-26 09:30:24

Oracle RAC + Data Guard 环境搭建  

2013-03-25 15:58:20|  分类: oracle-rac |  标签: |字号 

Oracle 高可用性的三个主要体现是: RAC, Data Guard  Stream.  所以熟练掌握这些技术就是评价DBA的标准一个。 RAC + Data Guard 主要用在灾备或者报表服务器上。 比如用RAC+ 逻辑standby 做报表,从而减轻RAC 系统的压力。 

 

关于Data Guard 的一些原理知识可以参考:

      Oracle Data Guard 理论知识

     http://blog.csdn.net/tianlesoftware/archive/2010/04/22/5514082.aspx

 

Oracle Data Gurad Physical Standby 相关说明

http://blog.csdn.net/tianlesoftware/archive/2010/05/04/5557410.aspx

 

RAC 的知识参考:

 

RAC 的一些概念性和原理性的知识

http://blog.csdn.net/tianlesoftware/archive/2010/02/27/5331067.aspx

 

Redhat 5.4 + ASM + RAW+ Oracle 10g RAC 安装文档

http://blog.csdn.net/tianlesoftware/archive/2010/09/09/5872593.aspx

 

 

 

RAC  Data Guard 的组合有4种情况:

组合

Primary

 Standby

1

Single Instance

Single Instance

2

Single Instance

RAC

3

RAC

Single Instance

4

RAC

RAC

 

RAC + DG 平台下,重用的几个视图:

(1)    v$archive_dest_status: Standby Database 上可以在这个视图中查看接收的日志编号,恢复的日志编号,从而可以了解Standby Database  Primary Database 日志的差别。 如果standby Primary 滞后太多,可以考虑增加恢复进程。 该视图中的recovery_mode 列也显示了是否使用了实时恢复(Real-Time Apply.

(2)    v$archive_dest: 这个视图中的error 列可以用于辅助诊断。

(3)    v$managed_standby:  这个视图可以确认standby RAC中,哪个实例是执行recover 的实例。

 

 

下面实验是RAC + Single standby 的模式。

 

测试环境

 

1.1  RAC Primary Database 环境

 

RAC primary

Rac1

Rac2

Public IP

10.85.10.1

10.85.10.2

Private IP

192.168.1.200

192.168.1.201

Virtual IP

10.85.10.3

10.85.10.4

Instance

Orcl1

Orcl2

DB_NAME

Orcl

Data,Control File, Redo File

ASM

 

1.2  Standby Database 环境

 

Single Instance Standby

 说明

IP

10.85.10.5

Oracle

RAC 版本

Instance

Orcl

DataControl FileRedo File

/u01

 

 

二.配置说明

 

1.3  switchover 之前,这时RACPrimary Database

(1)    RAC的每个实例都要配置日志发送,目的地指向Standby

(2)    确认日志发送的方法。如:LGWR

(3)    Standby 配置日志接收方法,如:standby redo log

(4)    启动MRP

 

1.4  switchover 之后,此时,rac standby database

如果Standby RAC,则日志接收和日志恢复可以是不同的Instance。 因此Oracle 在术语上把这两种实例分别叫作Receive Instance  Recover Instance。 在这个实验中,放在一个实例上进行。

 

(1)    Single Instance 的日志只发送到RAC的一个实例。

(2)    确认RAC 的日志接收方法,如: Standby Redo Log

(3)    RAC的一个实例上启动MRP.

 

 

三. 开始搭建

3.1 主库归档模式设置

       Data Guard 用的归档日志来完成同步, 所以在实验之前, 主库必须是归档模式。 这里就RAC 的归档。 关于RAC的归档参考Blog RAC  RMAN 备份中的1.2 节。设置归档就那么几步, 设置好归档目录,然后关闭所以节点,最后在一个节点上将模式设置为归档就ok了。

 

RAC  RMAN 备份

http://blog.csdn.net/tianlesoftware/archive/2010/09/22/5901053.aspx

 

 

 

3.2 准备备库环境

 

安装Oracle软件,并建立实例的相关目录。Linux 平台上Oracle 的安装参考blog

              linux平台下oracle数据库安装

              http://blog.csdn.net/tianlesoftware/archive/2009/10/24/4718218.aspx

 

 

在备库创建相关目录

mkdir -p  $ORACLE_BASE/oradata/orcl/datafile

mkdir -p  $ORACLE_BASE/oradata/orcl/tempfile

mkdir -p  $ORACLE_BASE/admin/orcl/adump

mkdir -p  $ORACLE_BASE/admin/orcl/bdump

mkdir -p  $ORACLE_BASE/admin/orcl/cdump

mkdir -p  $ORACLE_BASE/admin/orcl/dpdump

mkdir -p  $ORACLE_BASE/admin/orcl/hdump

mkdir -p  $ORACLE_BASE/admin/orcl/pfile

mkdir -p  $ORACLE_BASE/admin/orcl/udump

 

这里要注意的地方:

       因为RAC 主库是用ASM 来存放的,所以这里设置的目录,与ASM 目录是不一致的, 这种情况下,我们就需要在参数文件里用db_file_name_convertlog_file_name_convert 参数来进行转换。

 

 

3.3        配置主备库的监听,修改tnsnames.ora  listener.ora  文件

 

主备库的tnsnames.ora 文件是一致的。 修改成如下:

 

ORCL2 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

      (INSTANCE_NAME = orcl2)

    )

  )

 

ORCL1 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

      (INSTANCE_NAME = orcl1)

    )

  )

 

ORCL_ST =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SID = orcl)

    )

  )

 

这里要注意RAC 实例和单实例配置上的区别。 上面以用红色标出。

 

 

net manager 工具,在备库创建一个监听。 也可以手动的在listener.ora 文件里添加如下内容:

      

SID_LIST_LISTENER_RAC2 =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)

      (PROGRAM = extproc)

    )

   (SID_DESC =

      (SID_NAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)

    )

  )

 

LISTENER =

  (DESCRIPTION =

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

  )

 

注意:SID_LIST_LISTENER 配置的是静态注册,如果没有该参数,而且Data Guard 启动顺序又不正确,那么在主库可能会报 PING[ARC1]: Heartbeat failed to connect to standby 'orcl_st'. Error is 12514. 错误,导致归档无法完成。

Oracle Listener 动态注册  静态注册

http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx

 

 

3.4        在主库上创建备库的密码文件和控制文件,并将文件传到备库的相关位置

 

3.4.1 密码文件:

 

[oracle@rac2 dbs]$ pwd

/u01/app/oracle/product/10.2.0/db_1/dbs

[oracle@rac2 bin]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle

[oracle@rac2 bin]$ cd $ORACLE_HOME/dbs/

[oracle@rac2 dbs]$ ls

ab_+ASM2.dat  init+ASM2.ora  initorcl2.ora  orapworcl1

hc_+ASM2.dat  initdw.ora     orapw+ASM2     orapworcl2

hc_orcl2.dat  init.ora       orapworcl      snapcf_orcl2.f

 

缺省情况下,win下口令文件的格式是pwdsid.oraunix下的格式是orapwSID(大小写敏感)

 

参考:

Oracle OS认证 口令文件 密码丢失处理

http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4698293.aspx

 

传送文件:

[oracle@rac2 dbs]$ scp orapworcl 10.85.10.5://u01/app/oracle/product/10.2.0/db_1/dbs

orapworcl                                     100% 1536     1.5KB/s   00:00

[oracle@rac2 dbs]$

 

 

3.4.2 控制文件

 

[oracle@rac1 admin]$ export ORACLE_SID=orcl1

[oracle@rac1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Oct 8 03:39:00 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn system/oracle;

Connected.

SQL> alter database create standby controlfile as '/u01/control01.ctl';

Database altered.

SQL>

 

--判断一个数据库是Primary还是Standby,就是通过控制文件来判断的。

 

传送文件:

[oracle@rac1 u01]$ scp control01.ctl 10.85.10.5://u01/app/oracle/oradata/orcl/datafile

control01.ctl                                 100%   15MB   1.4MB/s   00:11

 

在备库上将控制文件复制2份,并命名为control02.ctl, control03.ctl

 

[oracle@rac3 orcl]$ cp control01.ctl control02.ctl

[oracle@rac3 orcl]$ cp control01.ctl control03.ctl

[oracle@rac3 orcl]$ ls

control01.ctl  control02.ctl  control03.ctl

 

 

3.5 参数文件

 

3.5.1 主库的参数文件

 

先用spfile 来创建pfile 文件。 这里要注意的,不要直接用create pfile from spfile来创建。 至于为什么参考Blog

       RAC 修改 spfile 参数

http://blog.csdn.net/tianlesoftware/archive/2010/09/24/5902591.aspx

 

[oracle@rac1 u01]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Oct 8 04:33:51 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected.

SQL> create pfile='/u01/tmp.ora' from spfile;

File created.

SQL> !

[oracle@rac1 u01]$ cd /u01

[oracle@rac1 u01]$ ls

app               dave.log                    RAC_hot_database_backup.sh.out

backup            dave.ora                    tianlesoftware.dmp

control01.ctl     impdp.log                   tmp.ora

dave_2010929.dmp  RAC_hot_database_backup.sh

[oracle@rac1 u01]$ more tmp.ora

 

通过more 命令,我们就可以看到rac pfile 参数的内容,对于RAC 主库,我们不需要做什么修改,只需要添加如下内容:

 

*.log_archive_config='dg_config=(orcl,orcl_st)'

*.log_archive_dest_3='service=orcl_st VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=orcl_st'

*.db_file_name_convert=' /u01/app/oracle/oradata/orcl/datafile','+DATA/orcl/datafile',

' /u01/app/oracle/oradata/orcl/tempfile','+DATA/orcl/tempfile'

*.log_file_name_convert=' /u01/app/oracle/oradata/orcl/datafile', '+DATA/orcl/datafile'

*.standby_file_management=auto

*.fal_server='orcl_st'

orcl1.fal_client='orcl1'

orcl2.fal_client='orcl2'

 

这里要注意的地方:如果之前配置了实例之间归档文件的互相传送,那么这里需要加上db_unique_name 参数:

orcl2.log_archive_dest_2='service=orcl1 db_unique_name=orcl'

orcl1.log_archive_dest_2='service=orcl2 db_unique_name=orcl'

 

不然在启动时会报如下错误:

BAD PARAM ORA-16052: DB_UNIQUE_NAME attribute is required

 

查询Data Guard db_unique_name 可以通过v$dagatuard_config视图:

 

SQL> select * from v$dataguard_config;

DB_UNIQUE_NAME

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

orcl

orcl_st

 

如果之前没有添加,可以通过修改pfile,在用pfile 创建spfile,或者用SQL, 如:

SQL> alter system set log_archive_dest_2='service=orcl1 db_unique_name=orcl' sid='orcl2';

 

关于这些参数的意义,可以参考:

Oracle Data Guard 理论知识

http://blog.csdn.net/tianlesoftware/archive/2010/04/22/5514082.aspx

 

一些说明:

(1)    使用ASM 作存储时,datafile tempfile 是分别放在两个目录下的,所以在standby 上也单独创建一个tempdata 目录,并在db_file_convert 中作相应的设置。

(2)    在使用ASMRAC中,注意不要修改db_unique_name 的参数值,因为ASM 存放文件的规则,是按照+diskgroup_name/database_unique_name/file_type/tag_name.file_number.incarnation 这样一个规则存放的,但是第二项database_unique_name 并不是db_name; 如果改变了db_unique_name,则之后创建的数据文件会放到新的目录下,会导致db_file_convert的失败,这一点需要特别注意。

(3)    如果RAC中使用db_create_online_dest_n 系列的参数,要相应调整standby 上的log_file_name_convert 参数。

 

 

第一点里提到ASM 分开存放文件,我们可以用asmcmd 命令连上ASM 验证一下:

 

[oracle@rac2 +ASM]$ export ORACLE_SID=+ASM2

[oracle@rac2 +ASM]$ asmcmd

ASMCMD> ls

DATA/

FLASH_RECOVERY_AREA/

ASMCMD> cd DATA

ASMCMD> ls

ORCL/

ASMCMD> cd ORCL/

ASMCMD> ls

CONTROLFILE/

DATAFILE/

ONLINELOG/

PARAMETERFILE/

TEMPFILE/

spfileorcl.ora

ASMCMD> cd TEMPFILE

ASMCMD> ls

TEMP.283.730181265

 

 

3.5.2 备库的参数文件

 

       备库的初始化文件,在主库的基础上修改一下,把不用的删除掉就可以了。 对于设计到Data Guard的参数,修改一下参数的值就可以了。 最终备库的参数如下:

 

 

 

[oracle@rac3 dbs]$ more initorcl.ora

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'

*.compatible='10.2.0.1.0'

*.control_files='/u01/app/oracle/oradata/orcl/datafile/control01.ctl','/u01/app/oracle/oradata/orcl/

datafile/control02.ctl','/u01/app/oracle/oradata/orcl/datafile/control03.ctl'

*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=16

*.db_name='orcl'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.job_queue_processes=10

*.log_archive_dest_1='LOCATION=/u01/arch'

*.log_archive_dest_state_2='ENABLE'

*.open_cursors=300

*.pga_aggregate_target=59768832

*.processes=150

*.remote_login_passwordfile='exclusive'

*.sga_target=179306496

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'

 

 

*.db_unique_name=orcl_st  -- 注意,这个值要和主库参log_archive_dest_n里设置的一致,不然会报错误:ORA-16047: DGID mismatch between destination

*.log_archive_config='dg_config=(orcl,orcl_st)'

*.log_archive_dest_2='service=orcl1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=orcl1'

*.db_file_name_convert='+DATA/orcl/datafile','/u01/app/oracle/oradata/orcl/datafile','+DATA/orcl/tem

pfile','/u01/app/oracle/oradata/orcl/tempfile'

*.log_file_name_convert='+DATA/orcl/onlinelog','/u01/app/oracle/oradata/orcl/datafile',

'+FLASH_RECOVERY_AREA/orcl/onlinelog','/u01/app/oracle/oradata/orcl/datafile'

*.standby_file_management=auto

*.standby_archive_dest='/u01/arch'

*.fal_server='orcl1','orcl2'

*.fal_client='orcl2'

 

 

这里面关于log_file_name_conver 参数:

 

先从主库查看v$logfile:

 

SQL>Select * from v$logfile;

   GROUP# STATUS  TYPE    MEMBER

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

         2         ONLINE  +DATA/orcl/onlinelog/group_2.282.730181191

         2         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_2.262.73018

         1         ONLINE  +DATA/orcl/onlinelog/group_1.281.730181173

         1         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_1.261.73018

         3         ONLINE  +DATA/orcl/onlinelog/group_3.285.730181443

         3         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_3.263.73018

         4         ONLINE  +DATA/orcl/onlinelog/group_4.286.730181451

         4         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_4.264.73018

 

如果这里除了+DATA,还有+FLASH_RECOVERY_AREA, 那么这些redo 都需要在参数里指定进行转换。 不然通过rman ,这些路径也会被复制过去,但是standby上是无法访问这些路径的,所以在做switchover 切换的时候,就会报错。 这点是要注意的地方。

 

 

3.6  RMAN 备份主库并将备份文件传到standby

      

这里用的是RMAN 复制的方法来搭建standby 环境。 可以参考我的Blog

       RMAN复制 搭建 物理 Data Gurad 环境

      http://blog.csdn.net/tianlesoftware/archive/2010/07/23/5756750.aspx

 

备份文件,放在/u01/rmanback 目录下,我们在rac1节点进行备份。 在standby 节点也需要建同样的目录,还需要把备份文件copy到这个目录下。

 

 

[oracle@rac1 bin]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Oct 8 12:13:07 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: ORCL (DBID=1257961898)

RMAN> RUN {

allocate channel c1 type disk;

allocate channel c2 type disk;

sql 'alter system archive log current';

backup current controlfile for standby format='/u01/rmanbackup/control_%U';

BACKUP FORMAT '/u01/rmanbackup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE ;

sql 'alter system archive log current';

BACKUP FORMAT '/u01/rmanbackup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;

release channel c2;

release channel c1;

}

 

SCP 拷贝到 standby 上:

[oracle@rac1 rmanbackup]$ scp * 10.85.10.5://u01/rmanbackup/

 

RMAN备份有一些注意事项,具体参考我的blog

       RAC  RMAN 备份

http://blog.csdn.net/tianlesoftware/archive/2010/09/22/5901053.aspx

 

 

3.7用之前创建的初始化参数文件将备库启动到nomount 状态:

 

启动监听:

[oracle@rac3 admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 08-OCT-2010 12:41:43

 

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

 

Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 10.2.0.1.0 - Production

System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.85.10.5)(PORT=1521)))

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.85.10.5)(PORT=1521)))

STATUS of the LISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                08-OCT-2010 12:41:43

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.85.10.5)(PORT=1521)))

The listener supports no services

The command completed successfully

 

启动数据库:

 

[oracle@rac3 u01]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on Fri Oct 8 12:37:08 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup nomount pfile=?/dbs/initorcl.ora

ORACLE instance started.

Total System Global Area  180355072 bytes

Fixed Size                  1218388 bytes

Variable Size              62916780 bytes

Database Buffers          113246208 bytes

Redo Buffers                2973696 bytes

SQL>

 

3.8 rman还原数据库:

 

[oracle@rac1 admin]$ rman target / auxiliary sys/oracle@orcl_st

 

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Oct 8 13:25:31 2010

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

connected to target database: ORCL (DBID=1257961898)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby;

Finished Duplicate Db at 09-OCT-10

 

 

 

3.9 检查standby 数据库

 

SQL> select status from v$instance;

 

STATUS

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

MOUNTED

 

SQL> select name from v$datafile;

 

NAME

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

/u01/app/oracle/oradata/orcl/datafile/system.276.730181051

/u01/app/oracle/oradata/orcl/datafile/undotbs1.278.730181053

/u01/app/oracle/oradata/orcl/datafile/sysaux.277.730181053

/u01/app/oracle/oradata/orcl/datafile/users.279.730181053

/u01/app/oracle/oradata/orcl/datafile/undotbs2.284.730181347

/u01/app/oracle/oradata/orcl/datafile/tianlesoftware.dbf

/u01/app/oracle/oradata/orcl/datafile/anhuianqing.dbf

 

7 rows selected.

 

SQL> select name from v$tempfile;

 

NAME

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

/u01/app/oracle/oradata/orcl/tempfile/temp.283.730181265

 

 

将备库启动到mount standby 状态,并启动MRP 进程:

 

SQL> startup nomount;

ORACLE instance started.

Total System Global Area  180355072 bytes

Fixed Size                  1218388 bytes

Variable Size              62916780 bytes

Database Buffers          113246208 bytes

Redo Buffers                2973696 bytes

 

SQL> alter database mount standby database;

Database altered.

 

SQL> recover managed standby database disconnect from session;

Media recovery complete.

SQL>

 

3.10 添加standby redo log 日志

 

       RAC 每个Redo Thread 都需要创建对应的Standby Redo Log。 创建原则和单实例一样,包括日志文件大小相等,日志组数量要多1组。

 

RAC里查看联机日志:

 

[oracle@rac2 rmanbackup]$ export ORACLE_SID=orcl2

[oracle@rac2 rmanbackup]$ sqlplus /nolog

 

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 9 03:49:49 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> conn  / as sysdba;

Connected.

SQL> select thread#,group#,bytes/1024/1024 from v$log;

 

   THREAD#     GROUP# BYTES/1024/1024

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

         1          1              50

         1          2              50

         2          3              50

         2          4              50

 

从上面的结果看出, RAC 有两个Redo Thread,每个Thread 有两个日志组,每个日志文件大小有50MB,所以要针对每个thread 需要创建3 Standby Redo Log,大小为50MB

 

 

Alter database add standby logfile thread 1 group 5 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_05.log') size 50m;

 

Alter database add standby logfile thread 1 group 6 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_06.log') size 50m;

 

Alter database add standby logfile thread 1 group 7 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_07.log') size 50m;

 

Alter database add standby logfile thread 2 group 8 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_08.log') size 50m;

 

Alter database add standby logfile thread 2 group 9 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_09.log') size 50m;

 

Alter database add standby logfile thread 2 group 10 ('/u01/app/oracle/oradata/orcl/datafile/redo_st_10.log') size 50m;

 

添加完可以用: select * from v$logfile 查看日志情况。

 

 

 

3.11 先停止RAC 实例,然后用之前创建的pfile 启动rac 实例。

 

[oracle@rac1 u01]$ cd /u01/app/oracle/product/crs/bin/

[oracle@rac1 bin]$ srvctl stop database -d orcl

[oracle@rac1 bin]$ crs_stat -t

Name           Type           Target    State     Host

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

ora.orcl.db    application    OFFLINE   OFFLINE

ora....oltp.cs application    OFFLINE   OFFLINE

ora....cl1.srv application    OFFLINE   OFFLINE

ora....cl2.srv application    OFFLINE   OFFLINE

ora....l1.inst application    OFFLINE   OFFLINE

ora....l2.inst application    OFFLINE   OFFLINE

ora....SM1.asm application    ONLINE    ONLINE    rac1

ora....C1.lsnr application    ONLINE    ONLINE    rac1

ora.rac1.gsd   application    ONLINE    ONLINE    rac1

ora.rac1.ons   application    ONLINE    ONLINE    rac1

ora.rac1.vip   application    ONLINE    ONLINE    rac1

ora....SM2.asm application    ONLINE    ONLINE    rac2

ora....C2.lsnr application    ONLINE    ONLINE    rac2

ora.rac2.gsd   application    ONLINE    ONLINE    rac2

ora.rac2.ons   application    ONLINE    ONLINE    rac2

ora.rac2.vip   application    ONLINE    ONLINE    rac2

[oracle@rac1 bin]$ export ORACLE_SID=orcl1

[oracle@rac1 bin]$ sqlplus /nolog

 

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Oct 9 05:27:55 2010

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

SQL> conn / as sysdba;

Connected to an idle instance.

 

SQL> create spfile from pfile='/u01/tmp.ora';

File created.

 

启动所有节点:

SQL> startup

ORACLE instance started.

Total System Global Area  180355072 bytes

Fixed Size                  1218388 bytes

Variable Size             109054124 bytes

Database Buffers           67108864 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.

这里有遇到了点麻烦,参考:

 

ORA-01677 standby file name convert parameters differ from other instance 错误

http://blog.csdn.net/tianlesoftware/archive/2010/10/09/5930227.aspx

 

 

 

3.12 在主库查看日志传送情况

 

SQL> Select dest_name,status,error from v$archive_dest;

 

DEST_NAME            STATUS    ERROR

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

LOG_ARCHIVE_DEST_1   VALID

LOG_ARCHIVE_DEST_2   VALID

LOG_ARCHIVE_DEST_3   VALID

LOG_ARCHIVE_DEST_4   INACTIVE

LOG_ARCHIVE_DEST_5   INACTIVE

LOG_ARCHIVE_DEST_6   INACTIVE

LOG_ARCHIVE_DEST_7   INACTIVE

LOG_ARCHIVE_DEST_8   INACTIVE

LOG_ARCHIVE_DEST_9   INACTIVE

LOG_ARCHIVE_DEST_10  INACTIVE

 

10 rows selected.

 

两个节点都正常。

 

3.13 验证同步情况

 

在主备库分别切换日志:

 

SQL> alter system switch logfile;

System altered.

 

SQL> select sequence# from v$archived_log;

SEQUENCE#

----------

        15

        16

 

SQL> alter system switch logfile;

 

System altered.

 

SQL> select sequence# from v$archived_log;

 

SEQUENCE#

----------

        17

        18

 

在备库进行验证:

SQL> select sequence#,applied from v$archived_log;

 

 

 SEQUENCE# APP

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

        13 YES

         4 NO

        14 YES

        15 YES

        16 YES

        18 NO

        16 YES

        17 YES

        18 YES

        19 YES

 

同步成功。 至此RAC 为主库的,备库为单实例的 Oracle Data Guard 环境已经搭建完成。

 

 

四. Switchover 切换

 

之前blog上的一篇单实例间切换的例子:

Oracle Data Guard Switchover 切换

http://blog.csdn.net/tianlesoftware/archive/2010/07/27/5768602.aspx

 

RAC 环境下,切换Primary  Standby 时,只能有一个实例是活动的, 其他实例必须关闭。

 

这里我们关闭rac2节点。

 

SQL> select instance_name from v$instance;

 

INSTANCE_NAME

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

orcl2

 

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

 

RAC1 节点将主库切换到备库:

 

SQL> select instance_name from v$instance;

INSTANCE_NAME

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

orcl1

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

 

SWITCHOVER_STATUS

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

SESSIONS ACTIVE

 

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

Database altered.

 

SQL> shutdown immediate;

 

 

将备库切换成主库:

 

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

 

SWITCHOVER_STATUS

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

TO PRIMARY

 

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY with session shutdown;

 

SQL> shutdown immediate;

 

 

rac1(原来的主库)节点上创建standby redo log file

 

SQL> select thread#,group#,bytes/1024/1024 from v$log;

 

   THREAD#     GROUP# BYTES/1024/1024

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

         1          1              50

         1          2              50

         2          3              50

         2          4              50

 

SQL> alter database add standby logfile thread 1 group 5 size 50m;

SQL> alter database add standby logfile thread 1 group 6 size 50m;

SQL> alter database add standby logfile thread 1 group 7 size 50m;

SQL> alter database add standby logfile thread 2 group 8 size 50m;

SQL> alter database add standby logfile thread 2 group 9 size 50m;

SQL> alter database add standby logfile thread 2 group 10 size 50m;

 

 

添加之后可以通过v$logfile 视图查看:

SQL> select * from v$logfile;

rows will be truncated

 

 

    GROUP# STATUS  TYPE    MEMBER

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

         2         ONLINE  +DATA/orcl/onlinelog/group_2.282.730181191

         2         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_2.262.73018

         1         ONLINE  +DATA/orcl/onlinelog/group_1.281.730181173

         1         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_1.261.73018

         3         ONLINE  +DATA/orcl/onlinelog/group_3.285.730181443

         3         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_3.263.73018

         4         ONLINE  +DATA/orcl/onlinelog/group_4.286.730181451

         4         ONLINE  +FLASH_RECOVERY_AREA/orcl/onlinelog/group_4.264.73018

         5         STANDBY +DATA/orcl/onlinelog/group_5.292.731930683

         5         STANDBY +FLASH_RECOVERY_AREA/orcl/onlinelog/group_5.268.73193

 

 

Standby 日志添加完之后,就可以启动实例了。 同样要注意的是, 如果standby RAC 环境, MRP 只能在一个实例上执行,这和RAC的恢复操作一样,而其他实例只能运行RFS

 

 

这种切换的意义并不大,RAC 本身就是一个高可用性的系统,它有多个节点可以规避宕机的风险。 RAC + 逻辑standby 这种用法还是比较常见。 我们公司目前也是用这种搭配方法,逻辑standby 用来做报表数据库。

 

       这个实验捣鼓了3天的时间,从十一放假回来就开始捣鼓。 本本上跑了三个虚拟机,4G 的内存也是很吃紧, RAC 在家里跑不起来,启动之后总有一个节点会宕机,看了log也是和网络有点什么关系。 只能在公司里才能正常使用。 所以都是上班时间去公司捣鼓这些东西。 今天下班之前总算折腾完了。 

 

结束语: 路漫漫其修远兮,吾将上下而求索!

阅读(1401) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~