ORACLE11g R2【RAC+ASM→RAC+ASM】

ORACLE11g R2【RAC+ASM→RAC+ASM】

本演示案例所用环境:RAC+ASM+OMF


 


primary


standby


OS Hostname


node1,node2


dgnode1,dgnode2


OS Version


RHEL6.5


RHEL6.5


DB Version


11.2.0.4


11.2.0.4


db_name


stephen


stephen


db_unique_name


stephen


standby


service_names


stephen


standby


instance_name


stephen1,stephen2


standby1,standby2

Primary database configure

1.启用primary force logging

SQL> select force_logging from v$database;

SQL> alter database force logging;

2.配置redo传输认证

(1) tnsnames.ora

STEPHEN =

(DESCRIPTION =

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

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = stephen)

)

)

STANDBY =

(DESCRIPTION =

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

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = standby)

)

)

 

(2) tnsping命令解析网络服务名,命令须返回OK.

此时,standby端未配置监听,无法解析,可以standby配置后再测试。

$ tnsping standby

 

(3) 密码文件

若无密码文件,则在一个节点创建密码文件并拷贝至其余节点。格式:orapw<ORACLE_SID>

cd $ORACLE_HOME/dbs

orapwd file=orapwstephen1 password=oracle ignorecase=y force=y

scp orapwstephen1 node2:$ORACLE_HOME/dbs/orapwstephen2

3.添加standby logfiles

添加standby logfile 的要求:

(1) 确保主和备数据库上的日志文件大小是相同的

(2) 确定备库重做日志文件组的适当数目

Standby logfile数 = (每个线程的logfile数+1)* 线程数

(3) 检查create database时指定的MAXLOGFILES和MAXLOGMEMBERS参数,可以通过trace controlfile出来查看

(4) RAC环境创建standby logfile,指定thread#创建

每个thread的standby logfile数 = 每个thread的logfile数 + 1

检查当前环境的logfile:

set lines 200 pages 300

col member for a60

select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$log a,v$logfile b where a.group#=b.group#

union all

select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$standby_log a,v$logfile b where a.group#=b.group#;

根据查询的logfile 信息上文添加standby logfile的要求,添加合理的standby logfile,然后用上面的sql再次查看当前环境的logfile:

alter database add standby logfile thread 1

group 5 ‘+DATA‘ size 50M,

group 6 ‘+DATA‘ size 50M,

group 7 ‘+DATA‘ size 50M;

alter database add standby logfile thread 2

group 8 ‘+DATA‘ size 50M,

group 9 ‘+DATA‘ size 50M,

group 10 ‘+DATA‘ size 50M;

4.修改primary参数文件

备份spfile:

create pfile=‘/tmp/pfile.bak‘ from spfile;

修改以下参数,其中stephen,standby分别为primary,standby的db_unqiue_name/TNS-Alias,详见参数详解部分:

alter system set log_archive_config=‘dg_config=(stephen,standby)‘ sid=‘*‘;

alter system set log_archive_dest_1=‘location=+DATA valid_for=(all_logfiles,all_roles) db_unique_name=stephen‘ sid=‘*‘;

alter system set log_archive_dest_2=‘service=standby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=standby‘ sid=‘*‘;

alter system set log_archive_max_processes=30 sid=‘*‘; #根据需求调整个数

--确认以下参数,若不为默认值则修改:

alter system set remote_login_passwordfile=exclusive scope=spfile sid=‘*‘;

# remote_login_passwordfile=exclusive/shared

alter system set log_archive_dest_state_1=enable sid=‘*‘;

alter system set log_archive_dest_state_2=enable sid=‘*‘;

--可修改归档日志格式,与datafile区分:

alter system set log_archive_format=‘%t_%s_%r.arc‘ scope=spfile sid=‘*‘;

--备角色参数:

alter system set fal_server=standby sid=‘*‘;

alter system set standby_file_management=auto sid=‘*‘;

alter system set db_file_name_convert=‘+DATA/STANDBY‘,‘+DATA/STEPHEN‘ scope=spfile sid=‘*‘;

alter system set log_file_name_convert=‘+DATA/STANDBY‘,‘+DATA/STEPHEN‘ scope=spfile sid=‘*‘;

注:以上参数,指定spfile修改的,在实例重启后生效。

采用OMF时,主、备库均只能使用一个ASM磁盘组,否则禁用OMF:

alter system reset db_create_file_dest sid=‘*‘;

alter system reset db_create_online_log_dest_n sid=‘*‘; #n为数值变量

alter system reset db_recovery_file_dest sid=‘*‘;

5.打开归档模式

首先确认当前数据库是否是归档模式,如果不是,则打开归档模式。

archive log list;

srvctl stop database -d stephen

srvctl start database -d stephen -o mount

alter database archivelog;  --在一个节点执行即可

alter database open; --各节点执行

6.备份primary database

rman target / <<EOF

run{allocate channel c1 type disk;

allocate channel c2 type disk;

backup full database format ‘/backup/full_%U.bak‘ plus archivelog;

sql ‘alter system switch logfile‘;

backup current controlfile for standby format ‘/backup/c_%U.bak‘;

release channel c1;

release channel c2;

}

EOF

Standby database configure

前期准备

首先安装CRS,RDBMS软件,配置ASM,netca创建监听。

1.配置各节点环境变量

export ORACLE_BASE=/oracle/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_SID=standby1 #根据节点修改

export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib #不同平台变量名不一样

2.配置redo传输认证

(1) tnsnames.ora

配置各节点的$ORACLE_HOME/network/admin/tnsnames.ora文件:

STEPHEN =

(DESCRIPTION =

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

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = stephen)

)

)

STANDBY =

(DESCRIPTION =

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

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = standby)

)

)

重载各节点监听:

lsnrctl reload

 

(2) tnsping命令解析网络服务名,命令须返回OK.

$ tnsping stephen

 

(3) 密码文件

使用主库的密码文件:

scp $ORACLE_HOME/dbs/orapwstephen1 dgnode1:$ORACLE_HOME/dbs/orapwstandby1

scp $ORACLE_HOME/dbs/orapwstephen1 dgnode2:$ORACLE_HOME/dbs/orapwstandby2

3.创建目录

在各节点创建相关目录:

mkdir -p $ORACLE_BASE/admin/standby/{adump,dpdump,pfile}

创建ASM目录:

export ORACLE_SID=+ASM1

SQL> alter diskgroup data add directory ‘+DATA/STANDBY‘;

4.参数文件

用primary的pfile加以修改,以保证某些参数与primary保持一致,注意主备库内存的大小适当的调整内存相关参数。

scp node1:/tmp/pfile.bak $ORACLE_HOME/dbs/initstandby1.ora

修改pfile为需要的standby pfile,特别注意以下事例的参数设定:

*.audit_file_dest=‘/u01/app/oracle/admin/standby/adump‘

*.cluster_database_instances=2

*.cluster_database=true

*.db_create_file_dest=‘+DATA‘

*.db_name=‘stephen‘

*.db_unique_name=‘standby‘

*.service_names=‘standby‘

standby1.instance_name=‘standby1‘

standby2.instance_name=‘standby2‘

standby2.instance_number=2

standby1.instance_number=1

*.remote_listener=‘cluster-scan:1521‘

standby1.local_listener=‘(ADDRESS=(PROTOCOL=TCP)(HOST=dgnode1-vip)(PORT=1521))‘

standby2.local_listener=‘(ADDRESS=(PROTOCOL=TCP)(HOST=dgnode2-vip)(PORT=1521))‘

*.remote_login_passwordfile=‘exclusive‘

standby2.thread=2

standby1.thread=1

*.undo_management=‘AUTO‘

standby1.undo_tablespace=‘UNDOTBS1‘

standby2.undo_tablespace=‘UNDOTBS2‘

*.log_archive_config=‘dg_config=(stephen,standby)‘

*.log_archive_dest_1=‘location=+DATA valid_for=(all_logfiles,all_roles) db_unique_name=standby‘

*.log_archive_dest_2=‘service=stephen lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=stephen‘

*.log_archive_max_processes=30  #根据需求调整个数

*.remote_login_passwordfile=exclusive  # exclusive/shared

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.log_archive_format=‘%t_%s_%r.arc‘

*.fal_server=stephen

*.standby_file_management=auto

*.db_file_name_convert=‘+DATA/STEPHEN‘,‘+DATA/STANDBY‘

*.log_file_name_convert=‘+DATA/STEPHEN‘,‘+DATA/STANDBY‘

以pfile启动数据库实例到nomount阶段,只需要启动一个实例用来做恢复即可:

SQL> startup nomount pfile=‘?/dbs/initstandby1.ora‘;

注意:以下恢复操作,只在一个节点做。

5.恢复standby controlfile

SQL> startup nomount;

RMAN> restore standby controlfile to ‘+DATA‘ from ‘/backup/c_0aqn43be_1_1.bak‘;

修改control_files参数执行controlfile位置:

alter system set control_files=‘+DATA/standby/controlfile/current.257.896669437‘ scope=spfile sid=‘*‘;

重启实例:

shutdown immediate;

startup nomount pfile=‘?/dbs/initstandby1.ora‘;

alter database mount standby database;

6.恢复数据文件

查询primary database的数据文件信息:

set lines 300 pages 300

col name for a60

col member for a60

select file#,name from v$datafile

union all

select file#,name from v$tempfile;

启动standby到mount阶段,恢复数据文件:

RMAN> run{

set newname for datafile 1 to ‘+DATA‘;

set newname for datafile 2 to ‘+DATA‘;

set newname for datafile 3 to ‘+DATA‘;

set newname for datafile 4 to ‘+DATA‘;

set newname for datafile 5 to ‘+DATA‘;

set newname for tempfile 1 to ‘+DATA‘;

restore database;

switch datafile all;

switch tempfile all;

recover database;

}

查看standby database log file:

set lines 200 pages 300

col member for a60

select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$log a,v$logfile b where a.group#=b.group#

union all

select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$standby_log a,v$logfile b where a.group#=b.group#;

7.注册OCR

注册DB,Instance到OCR:

srvctl add database -d standby -o $ORACLE_HOME

srvctl add instance -d standby -i standby1 -n dgnode1

srvctl add instance -d standby -i standby2 -n dgnode2

查看资源状态:

crsctl status res -t -w "TYPE = ora.database.type"

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

NAMETARGET  STATE        SERVER                   STATE_DETAILS

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

Cluster Resources

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

ora.standby.db

1        OFFLINE  OFFLINE

2        OFFLINE  OFFLINE

启用DB跟随CRS启动:

srvctl enable database -d standby

8.创建spfile

SQL> create spfile=‘+DATA‘ from pfile=‘?/dbs/initstandby1.ora‘;

关闭数据库实例,修改各节点pfile,然后以spfile启动数据库:

SQL> shutdown immediate

通过asmcmd命令查看spfile的位置

asmcmd find +DATA/standby spfile*

+DATA/standby/parameterfile/spfile.256.896665481

修改各节点pfile:

cd $ORACLE_HOME/dbs

echo "spfile=‘+DATA/standby/parameterfile/spfile.256.896665481">initstandby1.ora

echo "spfile=‘+DATA/standby/parameterfile/spfile.256.896665481">initstandby2.ora

以spfile启动实例到mount阶段(Data Guard)或open read only阶段(Active Data Guard):

--启动到mount:

srvctl start database -d standby -o mount

--启动到open read only:

srvctl start database -d standby -o ‘read only‘

查看资源状态:

crsctl status res -t -w "TYPE = ora.database.type"

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

NAMETARGET  STATE        SERVER                   STATE_DETAILS

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

Cluster Resources

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

ora.standby.db

1        OFFLINE  OFFLINE dgnode 1                  Open,Readonly

2        OFFLINE  OFFLINE dgnode 2                  Open,Readonly

如果状态显示为Open,此为ORACLE BUG,参考MOS DOC 1622876.1

9.应用日志

应用日志只需要在一个节点执行即可,日志应用可选择应用archive log或redo log.

应用archive log:

recover managed standby database disconnect;

实时应用redo logfile:

recover managed standby database using current logfile disconnect;

取消应用日志:

recover managed standby database cancel;

打开数据库至read only模式并开始实时复制:

recover managed standby database using current logfile disconnect;

10.观察日志传输

跟踪primary,standby database的alert log,观察是否有错误发生,也可以看到应用日志的相关信息。

确认standby是否应用日志:

--primary端多切几次日志,观察alert log信息。

alter system switch logfile;

alter system switch logfile;

--观察主备库日志序列号

archive log list;

--primary端查询v$archived_log视图,确认日志是否被应用:

set lines 300 pages 300

col name for a20

select name,dest_id,thread#,sequence#,standby_dest,applied,registrar,completion_time from v$archived_log

where standby_dest=‘YES‘

order by thread#,sequence#;

--primary端查询primary,standby的最大日志序列号是否一致:

select ‘Primary :‘ "DB Role",thread#,max(sequence#)

from v$archived_log

where standby_dest=‘NO‘

group by thread#

union

select ‘Standby :‘ "DB Role",thread#,max(sequence#)

from v$archived_log

where standby_dest=‘YES‘ and applied=‘YES‘

group by thread#

order by thread#;

时间: 2024-10-22 04:58:07

ORACLE11g R2【RAC+ASM→RAC+ASM】的相关文章

ORACLE11g R2【RAC+ASM→单实例FS】

ORACLE11g R2[RAC+ASM→单实例FS] 11g R2 RAC+ASMà单实例FS的DG,建议禁用OMF. 本演示案例所用环境:   primary standby OS Hostname node1,node2 std OS Version RHEL6.5 RHEL6.5 DB Version 11.2.0.4 11.2.0.4 db_name stephen stephen db_unique_name stephen standby service_names stephen

ORACLE11g R2【单实例 FS→单实例FS】

ORACLE11g R2[单实例 FS→单实例FS] 本演示案例所用环境:   primary standby OS Hostname pry std OS Version RHEL6.5 RHEL6.5 DB Version 11.2.0.4 11.2.0.4 db_name stephen stephen db_unique_name stephen standby service_names stephen standby instance_name stephen standby Pri

ORACLE10g R2【RAC+ASM→RAC+ASM】

ORACLE10g R2[RAC+ASM→RAC+ASM] 本演示案例所用环境:RAC+ASM+OMF   primary standby OS Hostname node1,node2 dgnode1,dgnode2 OS Version RHEL5.8 RHEL5.8 DB Version 10.2.0.5 10.2.0.5 db_name stephen stephen db_unique_name stephen standby service_names stephen standby

ORACLE10g R2【RAC+ASM→单实例FS】

ORACLE10g R2[RAC+ASM→单实例FS] 10g R2 RAC+ASMà单实例FS的DG,建议禁用OMF. 本演示案例所用环境:   primary standby OS Hostname node1,node2 std OS Version RHEL5.8 RHEL5.8 DB Version 10.2.0.5 10.2.0.5 db_name stephen stephen db_unique_name stephen standby service_names stephen

【翻译自mos文章】在rac中,使用asmcmd命令从 文件系统 move system datafile 到asm磁盘组的方法

在rac中,使用asmcmd命令从 文件系统  move system datafile 到asm磁盘组的方法. 参考原文: How to move a SYSTEM datafile from filesystem to the ASM diskgroup using ASMCMD on RAC. (Doc ID 1607292.1) 适用于: Oracle Database - Enterprise Edition - Version 11.2.0.1 to 11.2.0.3 [Releas

全套Oracle数据库安装实施视频课程套餐[涉及RAC,Linux,Win,ASM,Udev,FS]

全套Oracle数据库安装实施视频课程套餐[涉及RAC,Linux,Win,ASM,Udev,FS] 套餐介绍:高薪必学的Oracle数据库实施教程. 基础:Oracle数据库基础体系结构,ASM,RAC集群架构与概念. 实战:VMware/Windows2008/Linux操作系统安装, Windows/Linux操作系统上Oracle 11g R2 RAC集群安装与单机布署,Linux上ASM基于udev与asmlib的配置,Linux上Oracle11g基于文件系统及ASM与GRID布署,

【翻译自mos文章】使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法

使用asmcmd命令在本地和远程 asm 实例之间 拷贝asm file的方法 参考原文: How to Copy asm files between remote ASM instances using ASMCMD command (Doc ID 785580.1) 适用于: Oracle Database - Enterprise Edition - Version 11.1.0.6 to 11.2.0.2 [Release 11.1 to 11.2] Information in thi

【翻译自mos文章】在11gR2 rac环境中,文件系统使用率紧张,并且lsof显示有很多oraagent_oracle.l10 (deleted)

在11gR2 rac环境中,文件系统使用率紧张,并且lsof显示有很多oraagent_oracle.l10 (deleted) 参考原文: High Space Usage and "lsof" Output Shows Many 'oraagent_oracle.l10 (deleted)' in GI environment (Doc ID 1598252.1) 适用于: Oracle Database - Enterprise Edition - Version 11.2.0.

【TTS】传输表空间AIX asm -&gt; linux asm

[TTS]传输表空间AIX asm -> linux asm 一.1  BLOG文档结构图       一.2  前言部分   一.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① 异构平台下传输表空间的实施 ② 传输表空间基于表空间的read only和rman2种方式 ③ 平台字节序.自包含概念 ④ expdp/impdp的应用     Tips:        ① 若文章代码格式有错乱,推荐使用搜狗或3