快照DataGuard是11R2的一个功能,可以用于临时的测试后回到主从模式,测试坏境为LGWR ASYNC的最大性能模式。
一、设置snapshot standby
关闭日志应用进程MRP
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
关闭备数据库,启动到MOUNT阶段
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT;
设置快速回复区域,但是注意这里并不需要FLASHBACK DATABASE支持,但是实际上应该还是FLASHBACK DATABASE
(Ensure that a fast recovery area has been configured. It is not necessary for
flashback database to be enabled.)
SQL> alter system set db_recovery_file_dest_size=30g;
System altered.
SQL> alter system set db_recovery_file_dest='/home/oradba/flash_area';
System altered.
如果不设置会报错
ERROR at line 1:
ORA-38784: Cannot create restore point 'SNAPSHOT_STANDBY_REQUIRED_04/24/2015
10:30:47'.
ORA-38786: Recovery area is not enabled.
执行转换
ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;
转换操作可能比较慢,Oracle 可能会为备库建立日志文件如果没有的话,这比较耗时
SQL> ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oradba/archive
Oldest online log sequence 1
Next log sequence to archive 1
Current log sequence 1
完成后完全是一个新的数据库
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 1 TEST 2151380215 PARENT 1 17-SEP-11
2 2 TEST 2151380215 PARENT 995548 18-JUL-14
3 3 TEST 2151380215 PARENT 142690086 10-NOV-14
4 4 TEST 2151380215 CURRENT 168265840 24-APR-15
最后就是打开数据库可以使用了
SQL> alter database open;
Database altered.
SQL> select DATABASE_ROLE from v$database;
DATABASE_ROLE
----------------
SNAPSHOT STANDBY
注意:
1、snapshot standby 产生自身的归档日志,但是ALTER SYSTEM SWITCH LOGFILE 并不会马上归档,会等待5分钟归档1个日志
2、snapshot standby 确实会接受来自主库的日志,同时STANDBY LOGFILE也会接受来自主库的日志
SNAPSHOT STANDBY 日志归档和STANDBY归档速度从日志来看为5分钟归档一个,也就是说如果测试量巨大会造成日志组使用完,而造成HANG,
但是STANDBY LOG即使不能分配了也会接受归档到FLASH BACK AREA中。
从日志来看:
Fri Apr 24 11:05:43 2015
Archived Log entry 9 added for thread 1 sequence 807 ID 0x80d48cbc dest 1:
Fri Apr 24 11:07:36 2015
Thread 1 advanced to log sequence 4 (LGWR switch)
Current log# 8 seq# 4 mem# 0: /oradba/data/test/redo04
Thread 1 advanced to log sequence 5 (LGWR switch)
Current log# 9 seq# 5 mem# 0: /oradba/data/test/redo05
Thread 1 advanced to log sequence 6 (LGWR switch)
Current log# 10 seq# 6 mem# 0: /oradba/data/test/redo06
Thread 1 advanced to log sequence 7 (LGWR switch)
Current log# 11 seq# 7 mem# 0: /oradba/data/test/redo07
Thread 1 advanced to log sequence 8 (LGWR switch)
Current log# 12 seq# 8 mem# 0: /oradba/data/test/redo08
Thread 1 advanced to log sequence 9 (LGWR switch)
Current log# 13 seq# 9 mem# 0: /oradba/data/test/redo09
Thread 1 advanced to log sequence 10 (LGWR switch)
Current log# 14 seq# 10 mem# 0: /oradba/data/test/redo10
Thread 1 advanced to log sequence 11 (LGWR switch)
Current log# 15 seq# 11 mem# 0: /oradba/data/test/redo11
Thread 1 advanced to log sequence 12 (LGWR switch)
Current log# 1 seq# 12 mem# 0: /oradba/data/test/redo01.log
Thread 1 advanced to log sequence 13 (LGWR switch)
Current log# 2 seq# 13 mem# 0: /oradba/data/test/redo02.log
Fri Apr 24 11:07:46 2015
Thread 1 cannot allocate new log, sequence 14
Checkpoint not complete
Current log# 2 seq# 13 mem# 0: /oradba/data/test/redo02.log
ORACLE Instance test - Can not allocate log, archival required
Thread 1 cannot allocate new log, sequence 14
All online logs needed archiving
Current log# 2 seq# 13 mem# 0: /oradba/data/test/redo02.log
Fri Apr 24 11:10:44 2015
Archived Log entry 10 added for thread 1 sequence 3 ID 0x81b3f444 dest 1:
Fri Apr 24 11:10:44 2015
Thread 1 advanced to log sequence 14 (LGWR switch)
Current log# 3 seq# 14 mem# 0: /oradba/data/test/redo03.log
Fri Apr 24 11:15:44 2015
Archived Log entry 11 added for thread 1 sequence 4 ID 0x81b3f444 dest 1:
注意这里11:05:43 2015进行了一次归档,然后我大量的进行切换,观察到ALTER SYSTEM switchlog HANG住,
观察到日志:
Checkpoint not complete
Current log# 2 seq# 13 mem# 0: /oradba/data/test/redo02.log
ORACLE Instance test - Can not allocate log, archival required
而等待到Fri Apr 24 11:10:44 2015 日志进行了归档
Archived Log entry 10 added for thread 1 sequence 3 ID 0x81b3f444 dest 1
而Fri Apr 24 11:15:44 2015 有进行了一个日志的归档
Archived Log entry 11 added for thread 1 sequence 4 ID 0x81b3f444 dest 1:
而对于RFS 进程来说即使STANDBY LOG 不够也会接受进行到FLASHBACK AREA中
如下也能够证明:
SQL> select COMPLETION_TIME,SEQUENCE#,NAME FROM v$archived_log;
COMPLETION_TIME SEQUENCE# NAME
------------------- ---------- ---------------------------------------------------------------------
2015-04-23 17:58:08 802 /oradba/archive/1_802_863273736.dbf
2015-04-23 18:06:16 803 /oradba/archive/1_803_863273736.dbf
2015-04-24 09:57:08 804 /oradba/archive/1_804_863273736.dbf
2015-04-24 10:31:07 805 /oradba/archive/1_805_863273736.dbf
2015-04-24 10:40:40 806 /oradba/archive/1_806_863273736.dbf
2015-04-24 10:55:42 1 /oradba/archive/1_1_877862036.dbf
2015-04-24 10:59:41 811 /home/oradba/flash_area/TESTDG1/archivelog/2015_04_24/o1_mf_1_811_bmm
2015-04-24 11:00:42 2 /oradba/archive/1_2_877862036.dbf
2015-04-24 11:05:43 807 /oradba/archive/1_807_863273736.dbf
2015-04-24 11:10:44 3 /oradba/archive/1_3_877862036.dbf
2015-04-24 11:15:44 4 /oradba/archive/1_4_877862036.dbf
o1_mf_1_811_bmm就是接受过来的LOGFILE。
不管怎么说snapshot standby 产生自身的归档日志和snapshot standby 确实会接受来自主库的日志是成立的
二、回到主备模式
1、shutdown immediate;
2、startup mount;
3、ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
4、shutdown immediate;
5、startup
6、ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
在CentOS 6.4下安装Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虚拟机中安装步骤
Debian 下 安装 Oracle 11g XE R2
Oracle Data Guard 重要配置参数
基于同一主机配置 Oracle 11g Data Guard
探索Oracle之11g DataGuard
Oracle Data Guard (RAC+DG) 归档删除策略及脚本
Oracle Data Guard 的角色转换
Oracle Data Guard的日志FAL gap问题
Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 处理方法
: