Oracle 10g RAC Data Guard

                                                           Oracle 10g RAC Data Guard
                                                                            铁钉写于2010.07.29

一、 测试环境
OS: Redhat Linux AS4U7 32bit
Oracle: Oracle 10g r2 10.2.0.1 path 10.2.0.4
主机名 SID eth0 VIP 存储
RAC01 racdb1 192.168.17.81 192.168.17.83
rac01-vip
ASM ASM_RAC
RAC02 racdb2 192.168.17.82 192.168.17.84
rac02-vip
ASM ASM_RAC
DG01 standby 192.168.17.86 文件系统
/opt/oracle/oradata/<standby>
二、 配置要求
RAC 为 Pirmary 角色,用于生产环境,使用 Data Guard 技术,实现数据的安全;
三、 listener 和 tnsname 配置
RAC 的节点,除VIP以外,一律使用IP,而不能使用主机名。
四、 主库配置前期准备
(一) 主库 archive 配置
做物理Data Guard,必须将主数据库设置为归档模式。
( 01) archive 目录
将archive日志文件存放于,各个节点的 /opt/archive 目录, 在RAC01,RAC02,DG01 下建立该目录:
建立目录:
mkdir /opt/archive
( 02) 关闭RAC 数据库
重要: 主库RAC,2个节点必须都关掉,再执行后面的操作
SQL>shutdown immediate; # 关闭数据库
( 03) RAC01 节点操作
SQL>startup mount;
SQL>alter database archivelog;
SQL>alter database open;

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled # 已启用归档
Archive destination /opt/archive
Oldest online log sequence 51
Next log sequence to archive 52
( 04) RAC02 节点操作
SQL>startup
SQL>archive log list;
Database log mode Archive Mode
Automatic archival Enabled # 已启用归档
Archive destination /opt/archive
Oldest online log sequence 10
Next log sequence to archive 11
Current log sequence 11
Current log sequence 52
(二) 主库 强制日志配置
( 01) 将数据库改成强制logging
在RAC01 节点操作即可:
SQL> alter database force logging;
Database altered.
(三) 主库 参数修改
1) 通过spfile生新pfile。
SQL> create pfile='/home/oracle/rac_spfile_source.ora' from spfile;
File created.
2) 主库pfile文件
racdb1.__db_cache_size=167772160
racdb2.__db_cache_size=184549376
racdb1.__java_pool_size=4194304
racdb2.__java_pool_size=4194304
racdb1.__large_pool_size=4194304
racdb2.__large_pool_size=4194304
racdb1.__shared_pool_size=100663296
racdb2.__shared_pool_size=83886080
racdb1.__streams_pool_size=0
racdb2.__streams_pool_size=0
*.archive_lag_target=1800
*.audit_file_dest='/opt/oracle/admin/racdb/adump'
*.background_dump_dest='/opt/oracle/admin/racdb/bdump'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='10.2.0.3.0'
*.control_files='+RAC_ASM/racdb/controlfile/current.281.724929461'
*.core_dump_dest='/opt/oracle/admin/racdb/cdump'
*.db_block_size=8192
*.db_create_file_dest='+RAC_ASM'
*.db_domain=''
*.db_file_multiblock_read_count=8
*.db_file_name_convert='/opt/oracle/oradata/standby/','+RAC_ASM/racdb/datafile/','/opt/
oracle/oradata/standby/','+RAC_ASM/racdb/tempfile/'
*.db_name='racdb'
*.db_unique_name='RACDB'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdbXDB)'
racdb1.fal_client='RACDB1'
racdb2.fal_client='RACDB2'
*.fal_server='STANDBY'
racdb2.instance_number=2
racdb1.instance_number=1
*.job_queue_processes=10
*.log_archive_config='DG_CONFIG=(racdb,standby)'
racdb1.log_archive_dest_1='LOCATION=/opt/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=racdb'
racdb2.log_archive_dest_1='LOCATION=/opt/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=racdb'
*.log_archive_dest_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=standby'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_max_processes=8
*.log_file_name_convert='/opt/oracle/oradata/standby/','+RAC_ASM/racdb/onlinelog/'
*.nls_language='ENGLISH'
*.nls_territory='UNITED KINGDOM'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_listener='LISTENERS_RACDB'
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.standby_file_management='AUTO'
racdb2.thread=2
racdb1.thread=1
*.undo_management='AUTO'
racdb1.undo_tablespace='UNDOTBS1'
racdb2.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/opt/oracle/admin/racdb/udump'
(四) 备库 参数修改
1) 备库pfile文件
*.__db_cache_size=167772160
*.__java_pool_size=4194304
*.__large_pool_size=4194304
*.__shared_pool_size=100663296
*.__streams_pool_size=0
*.archive_lag_target=1800
*.audit_file_dest='/opt/oracle/admin/standby/adump'
*.background_dump_dest='/opt/oracle/admin/standby/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/opt/oracle/oradata/standby/control01.ctl'
*.core_dump_dest='/opt/oracle/admin/standby/cdump'
*.db_block_size=8192
*.db_create_file_dest=''/opt/oracle/oradata/standby/'
*.db_domain=''
*.db_file_multiblock_read_count=8
*.db_file_name_convert='+RAC_ASM/racdb/datafile/','/opt/oracle/oradata/standby/','+RAC_
ASM/racdb/tempfile/','/opt/oracle/oradata/standby/'
*.db_name='racdb'
*.db_unique_name='standby'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdbXDB)'
*.fal_client='standby'
*.fal_server='racdb'
*.job_queue_processes=10
*.log_archive_config='DG_CONFIG=(racdb,standby)'
*.log_archive_dest_1='LOCATION=/opt/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=standby'
*.log_archive_dest_2='SERVICE=racdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=racdb'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_max_processes=8
*.log_file_name_convert='+RAC_ASM/racdb/onlinelog/','/opt/oracle/oradata/standby/'
*.nls_language='ENGLISH'
*.nls_territory='UNITED KINGDOM'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=285212672
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/opt/oracle/admin/standby/udump'
2) 备库建立相关目录
mkdir /opt/oracle/oradata/standby
mkdir /opt/oracle/admin/standby
cd /opt/oracle/admin/standby/
mkdir adump
mkdir bdump
mkdir cdump
mkdir udump
(五) 主库 rman 备份
1) 主库建立存放备份文件目录
mkdir /opt/rmaset
2) rman备份
rman target /
RMAN> run {
2> backup database format '/opt/rmanset/full_%d%t%s%p' tag 'fullbackup';
3> }
Starting backup at 2010-07-20 08:47:01
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=135 instance=rac1 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=+RAC_ASM/rac/datafile/system.261.721147219
input datafile fno=00003 name=+RAC_ASM/rac/datafile/sysaux.263.721147227
input datafile fno=00002 name=+RAC_ASM/rac/datafile/undotbs1.262.721147225
input datafile fno=00004 name=+RAC_ASM/rac/datafile/undotbs2.265.721147231
input datafile fno=00005 name=+RAC_ASM/rac/datafile/users.266.721147233
channel ORA_DISK_1: starting piece 1 at 2010-07-20 08:47:03
channel ORA_DISK_1: finished piece 1 at 2010-07-20 08:47:18
piece handle=/opt/rmanset/full_RAC724841223151 tag=FULLBACKUP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2010-07-20 08:47:20
channel ORA_DISK_1: finished piece 1 at 2010-07-20 08:47:21
piece handle=/opt/rmanset/full_RAC724841238161 tag=FULLBACKUP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2010-07-20 08:47:21
RMAN> exit
3) rman备份复制到备库
将RAC 节点上备份的文件,全部复制到备库.
4) 在主库为备用数据库创建控制文件:
$ sqlplus / as sysdba
SQL> alter database create standby controlfile as '/home/oracle/control01.ctl'
将主库生成的 standby 控制文件,复制到备库 /opt/oracle/oradata/standby目录下
(六) 备库 rman 恢复
1) 备库mount操作
lsnrctl start
sqlplus "/as sysdba"
SQL>startup nomount pfile='/opt/oracle/pfile.ora';
SQL>alter database mount standby database;
2) 在备库还原数据文件库:
rman target /
RMAN> restore database;
Starting restore at 20-JUL-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /opt/oracle/oradata/standby/system.261.721147219
restoring datafile 00002 to /opt/oracle/oradata/standby/undotbs1.262.721147225
restoring datafile 00003 to /opt/oracle/oradata/standby/sysaux.263.721147227
restoring datafile 00004 to /opt/oracle/oradata/standby/undotbs2.265.721147231
restoring datafile 00005 to /opt/oracle/oradata/standby/users.266.721147233
channel ORA_DISK_1: reading from backup piece /opt/rmanset/full_RAC724841223151
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/rmanset/full_RAC724841223151 tag=FULLBACKUP
channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 20-JUL-10
RMAN> exit
(七) Standby redo log 重做日志组配置
( 01) 主库添加Standby Redo Log
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 5 ('+RAC_ASM/racdb/onlinelog/log5.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 6 ('+RAC_ASM/racdb/onlinelog/log6.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 7 ('+RAC_ASM/racdb/onlinelog/log7.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 GROUP 8 ('+RAC_ASM/racdb/onlinelog/log8.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 GROUP 9 ('+RAC_ASM/racdb/onlinelog/log9.log') SIZE 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 GROUP 10 ('+RAC_ASM/racdb/onlinelog/log10.log') SIZE 50M;
( 02) 备库添加Standby Redo Log
SQL> alter database add standby logfile thread 1 group 5 ('/opt/oracle/oradata/standby/log5.log') size 50M;
SQL> alter database add standby logfile thread 1 group 6 ('/opt/oracle/oradata/standby/log6.log') size 50M;
SQL> alter database add standby logfile thread 1 group 7 ('/opt/oracle/oradata/standby/log7.log') size 50M;
SQL> alter database add standby logfile thread 2 group 8 ('/opt/oracle/oradata/standby/log8.log') size 50M;
SQL> alter database add standby logfile thread 2 group 9 ('/opt/oracle/oradata/standby/log9.log') size 50M;
SQL> alter database add standby logfile thread 2 group 10 ('/opt/oracle/oradata/standby/log10.log') size 50M;
( 03) 备库置于恢复模式
将备用数据库置为恢复模式:在备库里使用命令
SQL> alter database recover managed standby database disconnect from session;
(八) 测试Data Guard 的同步工作情况
主库添加数据
将RAC 的2个节点都启动,用于测试2个数据库的数据,是否可以同步到standby端。
( 01) RAC02 增加数据(增加2条记录):
SQL> select * from xscj;
ID CJ
---------- ----------
80 90
2 90
3 90
4 78
5 90
99 90
6 rows selected. # xscj 表,原始6条数据
SQL> insert into xscj values(21,21);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into xscj values(22,22);
1 row created.
SQL> commit;
SQL> alter system switch logfile;
System altered.
( 02) RAC01 增加数据(增加2条记录):
SQL> select * from xscj;
ID CJ
---------- ----------
80 90
2 90
3 90
4 78
5 90
99 90
21 21
22 22
8 rows selected. #RAC01上,查询到RAC02上已增加的2条记录。
SQL> insert into xscj values(11,11);
1 row created.
SQL> insert into xscj values(12,12);
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
( 03) 备库核实数据是否同步
取消备库恢复模式
SQL> alter database recover managed standby database cancel;
SQL> alter database open read only;
节点1 节点2 上的变化,成功同步到standby 数据库
SQL> select * from gao.xscj;
ID CJ
---------- ----------
80 90
2 90
3 90
4 78
5 90
99 90
21 21
22 22
11 11
12 12
10 rows selected. #RAC01,RAC02上新增加的数据,成功同步到备库。
五、 switchover切换
当前状态:
RAC01,RAC02,是主库角色(即 primary角色);
DG01,是备库角色(即standby角色)。
要求:
将RAC 中的2 个节点由primary切为 standby 角色;
将DG01 由standby 切为primary 角色。
(一) 主切备
( 01) 查看主库的switchover_status
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY session active
SQL> alter database commit to switchover to physical standby with session shutdown;
( 02) 关闭主数据库:
SQL> shutdown immediate
ORA-01507: 未装载数据库
ORACLE 例程已经关闭。
( 03) 启动到mount状态:
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 289406976 bytes
Fixed Size 1248600 bytes
Variable Size 109052584 bytes
Database Buffers 176160768 bytes
Redo Buffers 2945024 bytes
数据库装载完毕。
( 04) 查看RAC数据库角色
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED
( 05) 置于恢复模式
SQL> alter database recover managed standby database using current logfile disconnect from
session;
查看数据库角色
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED
(二) 备切主
DG01 切为主库角色,在DG01 上操作。
( 01) 查看数据库角色
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> alter database commit to switchover to primary with session shutdown;
数据库已更改
( 01) 重启数据库:
SQL> shutdown immediate
ORA-01507: 未装载数据库
ORACLE 例程已经关闭。
SQL> startup;
ORACLE 例程已经启动。
Total System Global Area 289406976 bytes
Fixed Size 1248576 bytes
Variable Size 92275392 bytes
Database Buffers 188743680 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
数据库已经打开。
( 02) 检查数据库角色
SQL> select open_mode,database_role,switchover_status from v$database;
OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
---------- ---------------- --------------------
READ WRITE PRIMARY TO STANDBY
六、 Switchover 后,测试 Data Guard 传输
当前角色:
RAC 中的2个节点,现在是standby 角色;
DG01 现在是Primary角色。
切换后进行 DataGuard 数据传输测试:
(一) 重启所有RAC节点
RAC01, RAC02 全部都重新启动操作系统
[oracle@rac02 ~]$ crs_stat -t -v
ora.rac01.gsd application 0/5 0/0 ONLINE ONLINE rac01
ora.rac01.ons application 0/3 0/0 ONLINE ONLINE rac01
ora.rac01.vip application 0/0 0/0 ONLINE ONLINE rac01
ora....SM2.asm application 0/5 0/0 ONLINE ONLINE rac02
ora....02.lsnr application 0/5 0/0 ONLINE ONLINE rac02
ora.rac02.gsd application 0/5 0/0 ONLINE ONLINE rac02
ora.rac02.ons application 0/3 0/0 ONLINE ONLINE rac02
ora.rac02.vip application 0/0 0/0 ONLINE ONLINE rac01
ora....mrac.cs application 0/0 0/1 ONLINE ONLINE rac01
ora....db1.srv application 0/0 0/0 ONLINE ONLINE rac01
ora....db2.srv application 0/0 0/0 ONLINE ONLINE rac02
ora.racdb.db application 0/0 0/1 ONLINE ONLINE rac01
ora....b1.inst application 0/5 0/0 ONLINE ONLINE rac01
ora....b2.inst application 0/5 0/0 ONLINE ONLINE rac02
(二) 重新将数据库置为,接收归档日志,并恢复中
( 01) 先关闭RAC 的所有数据库
[oracle@rac01 ~]$ srvctl stop database -d racdb
( 02) 把RAC 的数据库启动以 mount
[oracle@rac01 ~]srvctl start database -d racdb -o mount
( 03) 把节点RAC01置于恢复状态:
[oracle@rac01 ~]$ sqlplus "/as sysdba"
SQL> alter database recover managed standby database disconnect from session;
Database altered.
( 04) 查询节点RAC01的状态,正处于恢复中
SQL> select open_mode,database_role,switchover_status from v$database;
OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
---------- ---------------- --------------------
MOUNTED PHYSICAL STANDBY SESSIONS ACTIVE
七、 switchover 角色还原
当前角色:
当前 RAC 中的2 个节点是 standby 角色;
DG01 服务器,是Primary 角色。
要求:
RAC 的2 个节点,切换为primary 角色;
DG01 服务器,还原为standby角色。
(一) 主切备
( 01) 查看DG01数据库switchover_status
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY session active
SQL> alter database commit to switchover to physical standby with session shutdown;
( 02) 关闭主数据库( standby实例 ):
SQL> shutdown immediate
ORA-01507: 未装载数据库
ORACLE 例程已经关闭。
( 03) 启动到mount状态( standby实例 ):
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 289406976 bytes
Fixed Size 1248600 bytes
Variable Size 109052584 bytes
Database Buffers 176160768 bytes
Redo Buffers 2945024 bytes
数据库装载完毕。
查看数据库角色
SQL> select open_mode,database_role,switchover_status from v$database;
OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
---------- ---------------- --------------------
MOUNTED PHYSICAL STANDBY TO PRIMARY
( 04) 置于恢复模式:
SQL> alter database recover managed standby database using current logfile disconnect from
session;
(二) 备切主
RAC 节点切为 主库角色
( 01) 查看数据库角色
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> alter database commit to switchover to primary with session shutdown;
( 02) 重启数据库:
SQL> shutdown immediate
ORA-01507: 未装载数据库
ORACLE 例程已经关闭。
SQL> startup;
ORACLE 例程已经启动。
Total System Global Area 289406976 bytes
Fixed Size 1248576 bytes
Variable Size 92275392 bytes
Database Buffers 188743680 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
数据库已经打开。
( 03) 检查数据库角色
SQL> select open_mode,database_role,switchover_status from v$database;
OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
---------- ---------------- --------------------
READ WRITE PRIMARY TO STANDBY
八、 Failover 切换
注意:必须主库不能正常启动,无法使用,才能做fail over 切换,如要做fail over测试,可将主
数据库关闭。
以下操作在备库进行:
$ sqlplus / as sysdba
已连接。
强制完成Standby database redo log app
如果备库有 Standby redo logfile
SQL> alter database recover managed standby database finish force;
数据库已更改。
SQL> alter database commit to switchover to primary;
数据库已更改。
SQL> alter database open;
第 1 行出现错误:
ORA-01507: 未装载数据库
SQL> shutdown immediate;
ORA-01507: 未装载数据库
ORACLE 例程已经关闭。
SQL> startup open;
ORACLE 例程已经启动。
Total System Global Area 289406976 bytes
Fixed Size 1248600 bytes
Variable Size 109052584 bytes
Database Buffers 176160768 bytes
Redo Buffers 2945024 bytes
数据库装载完毕。
数据库已经打开。
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY

你可能感兴趣的:(oracle,RAC,Data,休闲,guard)