再做 Oracle 11gR2 RAC+DG3

上一部分配置了dg备库asm磁盘组,RAC主库准备, 这一部分继续dg备库准备,初始化文件,

控制文件,数据库文件恢复, standby logfile创建,RAC主库到dg备库日志同步等内容

将node1节点/rman_backup下面的数据库备份文件, 初始化文件,控制文件,

归档日志全部拷贝的dg的/rman_backup下面

这是node1 /rman_backup/下的备份文件

40

将这些文件通过FTP,或者其他方式传送到dg备库的/rman_backup目录下,传送完成如下:

41

物理备库创建口令文件

dg编辑.bash_profile如下:

export PATH

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_HOSTNAME=dg.localdomain

export ORACLE_SID=phydb

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_HOME/product/11.2.0/db_1

export ORACLE_UNQNAME=phydb

export TNS_ADMIN=$ORACLE_HOME/network/admin

export ORACLE_TERM=xterm

export PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

export LANG=en_US

export NLS_LANG=american_america,AL32UTF8

export NLS_DATE_FORMAT=’yyyy/mm/dd hh24/mi:ss’

umask 022

执行source .bash_profile 使环境变量立即生效

输出dg备库的环境变量

dg -> env | grep ORA

ORACLE_UNQNAME=phydb

ORACLE_SID=phydb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOSTNAME=dg.localdomain

ORACLE_TERM=xterm

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

 

dg备库初始化文件修改

初始化文已从node1的/rman_backup下复制到dg的/rman_backup下, 名为initphydb.ora ,

dg备库/rman_backup下的initphydb.ora拷贝到$ORACLE_HOME/dbs下,修改后dg才能使用。

初始化文件修改如下:

phydb.__db_cache_size=180355072

phydb.__java_pool_size=4194304

phydb.__large_pool_size=4194304

phydb.__oracle_base=’/u01/app/oracle’

phydb.__pga_aggregate_target=335544320

phydb.__sga_target=402653184

phydb.__shared_pool_size=239075328

*.audit_file_dest=’/u01/app/oracle/admin/phydb/adump’

*.audit_trail=’db’

*.cluster_database=false

*.compatible=’11.2.0.0.0′

*.control_files=’+DATA/phydb/controlfile/cont.ctl’

*.core_dump_dest=’/u01/app/oracle/diag/rdbms/phydb/cdump’

*.db_block_size=8192

*.db_create_file_dest=’+DATA’

*.db_file_name_convert=’+DATA/devdb/’,’+DATA/phydb/’

*.db_name=’devdb’

*.db_recovery_file_dest_size=4070572032

*.db_unique_name=’phydb’

*.diagnostic_dest=’/u01/app/oracle’

*.dispatchers='(PROTOCOL=TCP) (SERVICE=phydbXDB)’

*.fal_client=’phydb’

*.fal_server=’devdb1′,’devdb2′

*.log_archive_config=’dg_config=(devdb,phydb)’

*.log_archive_dest_1=’location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles)

db_unique_name=phydb’

*.log_archive_dest_2=’service=devdb1 valid_for=(online_logfiles,primary_role)

db_unique_name=devdb’

*.log_archive_format=’ARC_%t_%S_%r.arc’

*.log_file_name_convert=’+DATA/devdb/’,’+DATA/phydb/’

*.memory_target=842006528

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile=’exclusive’

*.service_names=’phydb’

*.standy_file_management=’auto’

*.thread=1

*.undo_management=’auto’

*.undo_tablespace=’UNDOTBS1

 

创建adump和cdump

mkdir -p /u01/app/oracle/admin/phydb/adump

midir -p /u01/app/oracle/diag/rdbms/phydb/cdump

建立+DATA/ 下的phydb 即+DATA/phydb/

grid用户登录dg

执行asmcmd然后在+data/下创建phydb目录

43

44

 

配置RAC主库,dg备库tnsnames.ora

查看node2的 tnsnames.ora

su – oracle

cat $ORACLE_HOME/network/admin/tnsnames.ora

发现缺少devdb,devdb1连接信息,补充后tnsname.ora信息如下

DEVDB =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = devdb)

(INSTANCE_NAME = devdb)

)

)

devdb1 =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = devdb

(INSTANCE_NAME = devdb1)

)

)

devdb2 =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = devdb)

(INSTANCE_NAME = devdb2)

)

)

phydb =

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = phydb)

)

)

将node2中修改好的tnsnames.ora复制到node1和dg的 $ORACLE_HOME/network/admin/下

这就保证了连接信息的一致性

dg备库检测,确认能否访问scan-ip , node1 , node2 , dg

conn scott/tiger@devdb

conn scott/tiger@devdb1

conn scott/tiger@devdb2

至此dg备库准备工作就完成了.

 

dg备库启动到mount状态

刚只是把RAC主库的控制文件复制到/rman_backup目录下,dg必须应用该控制文件.才能切换到mount状态.

dg先启动到nomount状态,然后RMAN恢复控制文件

[root@dg ~]# su – oracle

dg -> sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 22 22:21:40 2016

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

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 839282688 bytes

Fixed Size 2217992 bytes

Variable Size 587204600 bytes

Database Buffers 247463936 bytes

Redo Buffers 2396160 bytes

 

RMAN恢复控制文件

[root@dg ~]# su – oracle

dg -> rman target /

Recovery Manager: Release 11.2.0.1.0 – Production on Fri Jul 22 22:25:33 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

connected to target database: DEVDB (not mounted)

RMAN> restore standby controlfile from ‘/rman_backup/standby_0fr8au65_1_1.ctl’;

starting restore at 2016/06/22 00:06:15

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=24 device type=DISK

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete. elapsed time: 00:00:03

output file name=+DATA/phydb/controlfile/cont.ctl

Finished restore at 2016/06/22 00:06:18

dg备库有了控制文件后就可以mount了.

dg切换到oracle用户,sqlplus 进入后直接mount就行

SQL> alter database mount;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE

————————————————————

MOUNTED

 

RMAN恢复dg备库

dg -> rman target /

RMAN> run

{allocate channel c1 type disk;

allocate channel c2 type disk;

allocate channel c3 type disk;

allocate channel c4 type disk;

restore database;

release channel c1;

release channel c2;

release channel c3;

release channel c4;

}

备库恢复过程如下:

46

47

现在dg备库已经恢复好了.

 

dg备库创建standby logfile

创建standby logfile 用来接收主库传递过来的重做日志,然后定期利用这个日志进行数据同步与恢复

创建standby logfile 遵循的规则是:首先大小一定和主库的大小一样大, 其次要比实例下面的日志组个数多1.

接下来为主库的每一个实例(线程)创建standby 日志文件, 当然在创建前查看一下相关数据信息

RAC主库node1 查看日志组情况

SQL > select * from v$log; , 每个节点2组日志.

dg48

创建standby_log

alter database add standby logfile thread 1 group 5 size 50m, group 6 size 50m , group 7 size 50m;

alter database add standby logfile thread 2 group 8 size 50m, group 9 size 50m , group 10 size 50m;

49

gd50

查看一下刚才创建的standby redo logfile

SQL> select group#,DBID,THREAD#,SEQUENCE#,STATUS from v$standby_log;

GROUP# DBID THREAD# SEQUENCE# STATUS

———- ————— ———- ———- ———-

5 UNASSIGNED 1 0 UNASSIGNED

6 UNASSIGNED 1 0 UNASSIGNED

7 UNASSIGNED 1 0 UNASSIGNED

8 UNASSIGNED 2 0 UNASSIGNED

9 UNASSIGNED 2 0 UNASSIGNED

10 UNASSIGNED 2 0 UNASSIGNED

6 rows selected.

可以看见standby logfile日志组5,6,7在THREAD1中,5,6,7在THREAD2中.

 

配置主库到备库的日志同步

node1和node2切换到oracle用户,测试实例连通性

sqlplus / as sysdba

conn sys/Oracle168@devdb as sysdba

conn sys/Oracle168@devdb1 as sysdba

conn sys/Oracle168@devdb2 as sysdba

conn sys/Oracle168@phydb as sysdba

 

node1配置让RAC主库的归档日志传输到dg备库上去

alter system set log_archive_dest_2=’service=phydb lgwr sync

valid_for=(online_logfiles,primary_role) db_unique_name=phydb’ sid=’*’;

show parameter log_archive;

dg52

node2重启一次,然后执行 show parameter log_archive; 如果log_archive_dest_state_2也是enable的,

那么配置正确.

rman target /

list archivelog all; 出现如下图所示的,则归档已经产生.

dg54

 

测试RAC主库切换日志,dg备库是否同步

检查RAC主库和dg备库状态

SQL> select dbid,name,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status

from gv$database;

DBID NAME CURRENT_SCN PROTECTION_MODE DATABASE_ROLE FOR OPEN_MODE SWITCHOVER_STATUS

———- ——— ———– ——————– —————- — ——————– ——————–

818758572 DEVDB 3454281 MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY

818758572 DEVDB 3454280 MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY

SQL> select dbid,name,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status

from gv$database;

DBID NAME CURRENT_SCN PROTECTION_MODE DATABASE_ROLE FORCE_LOGOPEN_MODE SWITCHOVER_STATUS

———- ——— ———– ——————– —————- — ——————– ——————–

818758572 DEVDB 3284512 MAXIMUM PERFORMANCE PHYSICAL STANDBY YES MOUNTED NOT ALLOWED

返回的结果显示,RAC主库node1和node2, DATABASE_ROLE都是PRIMARY的;FORCE_LOGING是开启的,

OPEN_MODE是READ WRITE的; SWITCHOVER_STATUS是TO STANDBY的.

dg备库,DATABASE_ROLE是PHYSICAL STANDBY的;FORCE_LOGING是开启的;OPEN_MODE是MOUNTED的

SWITCHOVER_STATUS是NOT ALLOWED的

状态满足日志同步要求.

测试node1到dg备库的同步,下图说明了同步成功.

dg55

dg56

node2到dg的同步操作方法一样就不再演示了.

Leave a Reply