聊聊Oracle 11g的Snapshot Standby Database(下)
3、Snapshot Standby行为研究
下面我们分析一下Snapshot Standby的工作性质和行为性质。我们在主库方向研究当前状态。
--主库日志情况
SQL> select group#, sequence#, archived, status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 98 YES INACTIVE
2 99 NO CURRENT
3 97 YES INACTIVE
SQL> select recid,sequence#, archived, applied from v$archived_log where name='vlifesb' and sequence#>90;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
123 91 YES YES
126 92 YES YES
128 93 YES YES
130 94 YES YES
132 95 YES YES
134 96 YES YES
136 97 YES NO
138 98 YES NO
8 rows selected
注意:发送到vlifesb端的归档日志是连续的,没有发生中断现象。但是97、98号日志显然没有进行apply。此时,我们强行进行switch logfile动作。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> select group#, sequence#, archived, status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 101 YES INACTIVE
2 102 NO CURRENT
3 100 YES INACTIVE
SQL> select recid,sequence#, archived, applied from v$archived_log where name='vlifesb' and sequence#>90;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
123 91 YES YES
126 92 YES YES
128 93 YES YES
130 94 YES YES
132 95 YES YES
134 96 YES YES
136 97 YES NO
138 98 YES NO
140 99 YES NO
142 100 YES NO
144 101 YES NO
11 rows selected
注意:当进行切换的时候,归档日志是被传输过去的,但是同样没有被apply。也就是说:切换到snapshot之后,Standby还是在不断地接受Primary数据库进行积累。到Standby端我们看一下情况。
--Standby日志
SQL> select group#, sequence#, archived, status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 1 NO CURRENT
3 0 YES UNUSED
2 0 YES UNUSED
SQL> select recid,sequence#, archived, applied from v$archived_log where recid>87;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
88 92 YES YES
89 93 YES YES
90 94 YES YES
91 95 YES YES
92 96 YES YES
93 97 YES NO
94 98 YES NO
95 99 YES NO
96 100 YES NO
97 101 YES NO
10 rows selected
SQL> select * from v$standby_log;
GROUP# DBID THREAD# SEQUENCE# BYTES BLOCKSIZE USED ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME LAST_CHANGE# LAST_TIME
---------- ---------------------------------------- ---------- ---------- ---------- ---------- ---------- -------- ---------- ------------- ----------- ------------ ----------- ------------ -----------
4 4207470439 1 102 104857600 512 80896 YES ACTIVE 1794468 2015/10/22 1794623 2015/10/22
5 UNASSIGNED 1 0 104857600 512 0 NO UNASSIGNED
6 UNASSIGNED 0 0 104857600 512 0 YES UNASSIGNED
在Standby端,我们似乎看到两套体系。从Primary传输来的归档日志通过Standby途径,不断的在Archived Redo Log中集合积累,只是没有被Apply。同时,online redo log体系中,原有的日志sequence系列被打乱了,从1开始重新计数。这个的确是体现出reset log的特点。
思考一下:Snapshot Standby既然是支持更新修改,从整体上看就是在数据上和Primary“分道扬镳”。Redo Log进行reset动作之后,也就体现出这点特性。
之后,Snapshot可以开启open。
SQL> alter database open;
Database altered.
开启之后,我们尝试在Standby端进行DML操作。
--独立事务
SQL> create table t_sn as select * from dba_objects;
Table created
SQL> select count(*) from t_sn;
COUNT(*)
----------
86280
这个独立事务是在Standby端进行的,并没有在Primary端实现。下面进行一系列的Standby端Redo Log切换。
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
SQL> alter system switch logfile;
System altered
当前online redo log在不断切换,反映最新的Snapshot数据分散情况。
SQL> select group#, sequence#, archived, status from v$log;
GROUP# SEQUENCE# ARCHIVED STATUS
---------- ---------- -------- ----------------
1 4 YES INACTIVE
2 5 NO CURRENT
3 3 YES INACTIVE
SQL> select recid,sequence#, archived, applied from v$archived_log where recid>87;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
88 92 YES YES
89 93 YES YES
90 94 YES YES
91 95 YES YES
92 96 YES YES
93 97 YES NO
94 98 YES NO
95 99 YES NO
96 100 YES NO
97 101 YES NO
98 1 YES NO
99 2 YES NO
100 3 YES NO
101 4 YES NO
14 rows selected
注意:在归档日志中,Primary传递过来的Standby Redo Log归档,和Snapshot自身生成的另一个朝代online redo log归档,都在一个列表中。
为了更清晰显示,我们在Primary主库上进行测试DML操作。
SQL> select count(*) from t_m;
COUNT(*)
----------
99
SQL> delete t_m;
99 rows deleted
SQL> commit;
Commit complete
SQL> select count(*) from t_m;
COUNT(*)
----------
0
下面实验进行将snapshot恢复为physical standby。
4、恢复Physical Standby
注意:如果将snapshot standby恢复为physical standby,在Open状态是不允许的,需要切换到mount状态。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 2471931904 bytes
Fixed Size 2255752 bytes
Variable Size 738198648 bytes
Database Buffers 1711276032 bytes
Redo Buffers 20201472 bytes
Database mounted.
使用convert进行切换。
SQL> alter database convert to physical standby;
Database altered.
此时Standby端的alert log关键信息如下:
Thu Oct 22 11:21:09 2015
alter database convert to physical standby
ALTER DATABASE CONVERT TO PHYSICAL STANDBY (vlifesb)
Killing 3 processes with pids 7474,7461,7463 (all RFS) in order to disallow current and future RFS connections. Requested by OS process 7457
Flashback Restore Start
Flashback Restore Complete
Drop guaranteed restore point
Guaranteed restore point dropped
Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/VLIFESB/flashback/o1_mf_c27f0mj2_.flb
Clearing standby activation ID 4208505925 (0xfad8b445)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause. –重建control file
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
Shutting down archive processes
Archiving is disabled
Thu Oct 22 11:21:12 2015
ARCH shutting down
Thu Oct 22 11:21:12 2015
ARCH shutting down
Thu Oct 22 11:21:12 2015
ARCH shutting down
ARC3: Archival stopped
Thu Oct 22 11:21:12 2015
ARCH shutting downARC2: Archival stopped
ARC1: Archival stopped
ARC0: Archival stopped
Completed: alter database convert to physical standby
从日志上,我们可以看到Oracle实际上在进行flashback操作,恢复控制文件和清理日志操作。切换回去之后,Oracle需要将数据库重新启动。
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 2471931904 bytes
Fixed Size 2255752 bytes
Variable Size 738198648 bytes
Database Buffers 1711276032 bytes
Redo Buffers 20201472 bytes
Database mounted.
Database opened.
SQL>
此时,Standby状态恢复到Read Only+Physical Standby状态。
SQL> select open_mode, database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY PHYSICAL STANDBY
5、相关测试实验
此时,Physical Standby角色恢复,但是没有启动Redo Log Apply动作。此时在归档日志中,旧朝代和新朝代的归档日志同时存在。
SQL> select recid,sequence#, archived, applied from v$archived_log where recid>87;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
88 92 YES YES
89 93 YES YES
90 94 YES YES
91 95 YES YES
92 96 YES YES
93 97 YES NO
94 98 YES NO
95 99 YES NO
96 100 YES NO
97 101 YES NO
98 1 YES NO
99 2 YES NO
100 3 YES NO
101 4 YES NO
102 102 YES NO
103 103 YES NO
16 rows selected
启动Redo Log应用过程。
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered
日志信息:
Thu Oct 22 11:28:08 2015
alter database recover managed standby database using current logfile disconnect from session
Attempt to start background Managed Standby Recovery process (vlifesb)
Thu Oct 22 11:28:08 2015
MRP0 started with pid=30, OS id=7593
MRP0: Background Managed Standby Recovery process started (vlifesb)
started logmerger process
Thu Oct 22 11:28:13 2015
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 4 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Clearing online redo logfile 1 /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_1_c261g1mo_.log
Clearing online log 1 of thread 1 sequence number 104
Clearing online redo logfile 1 complete
Clearing online redo logfile 2 /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_2_c261g2d0_.log
Clearing online log 2 of thread 1 sequence number 5
Clearing online redo logfile 2 complete
Clearing online redo logfile 3 /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_3_c261g34d_.log
Clearing online log 3 of thread 1 sequence number 103
Completed: alter database recover managed standby database using current logfile disconnect from session
Clearing online redo logfile 3 complete
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_97_c2jnsh3g_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_98_c2jnvbw6_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_99_c2jo0hdc_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_100_c2jo0jjm_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_101_c2jo0kky_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_102_c2jod77o_.arc
Media Recovery Log /u01/app/oracle/fast_recovery_area/VLIFESB/archivelog/2015_10_22/o1_mf_1_103_c2joqhh0_.arc
Media Recovery Waiting for thread 1 sequence 104 (in transit)
Recovery of Online Redo Log: Thread 1 Group 4 Seq 104 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/VLIFESB/onlinelog/o1_mf_4_c265gc9q_.log
Mem# 1: /u01/app/oracle/fast_recovery_area/VLIFESB/onlinelog/o1_mf_4_c265gcfk_.log
清理Redo Log,同时进行Apply过程。
SQL> select recid,sequence#, archived, applied from v$archived_log where recid>87;
RECID SEQUENCE# ARCHIVED APPLIED
---------- ---------- -------- ---------
88 92 YES YES
89 93 YES YES
90 94 YES YES
91 95 YES YES
92 96 YES YES
93 97 YES YES
94 98 YES YES
95 99 YES YES
96 100 YES YES
97 101 YES YES
98 1 YES NO
99 2 YES NO
100 3 YES NO
101 4 YES NO
102 102 YES YES
103 103 YES IN-MEMORY
16 rows selected
从97号日志开始,逐个进行日志apply过程。但是不同朝代的1-4日志,就被闲置起来。
检查两个数据表的情况:在新的备库Standby上,数据表t_m的主库操作被传递过去。在备库Standby为snapshot期间,数据表t_sn不复存在。
--Standby端测试
SQL> select count(*) from t_m;
COUNT(*)
----------
0
--Primary、Standby端测试
SQL> select count(*) from t_sn;
select count(*) from t_sn
ORA-00942: 表或视图不存在
6、结论
Oracle Snapshot是11g中新推出的Standby类型,在一些应用场景上,这种类型备库会越来越扮演重要的角色。
转:http://blog.itpub.net/17203031/viewspace-1816341/
聊聊Oracle 11g的Snapshot Standby Database(下)的更多相关文章
- 聊聊Oracle 11g的Snapshot Standby Database(上)
Oracle 11g是Data Guard的重要里程碑版本.在11g中,Active DataGuard.Advanced Compression等特性大大丰富了Data Guard的功能和在实践领域 ...
- snapshot standby database
快照备库接收和归档主库发送来的redo,但是不会应用:切换成physical standby之后会自动开启redo apply.快照standby不可以参加主备切换:在最大保护性模式下,如果只有一个备 ...
- Oracle 11g即时客户端在windows下的配置
Oracle 11g即时客户端在windows下的配置 by:授客QQ:1033553122 instantclient-basic-nt-11.2.0.3.0.zip客户端压缩包为例 步骤 1. 假 ...
- oracle 11g RAC 在Windows 7下安装
oracle 11g RAC 在Windows 7下安装 完全要参考RAC11gR2OnWindows.pdf 难点总是在Grid Infrastructure 而安装Grid Infrastruct ...
- 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境
Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...
- Oracle 11G RAC:生产环境下架构
转: it168网站 原创 作者:刘炳林 在真实环境搭建一套Oracle RAC就好比是一堂劳动课,劳动前需要准备好劳动工具,对劳动课内容有充分的认识;按照步骤一步一步进行,需要考虑劳动过程中可能遇 ...
- Oracle 11g中的snapshot standby特性
在Oracle 11g中,data guard最吸引人的,除了active data guard的实时查询特性(即可以以只读方式打开物理standby数据库的同时MRP进程能继续做recover),快 ...
- ORACLE 11gR2 DG(Physical Standby)日常维护02
环境:RHEL 6.5 + Oracle 11.2.0.4 三.监控DG的状态 3.1监控DG备库的状态 3.2监控主库传输日志链路的状态 四.备库切换为snapshot standby 4.1备库切 ...
- [Oracle] 临时将Physical Standby激活
Oracle 10g/11g下如何将物理Standby库临时激活用于测试 在实际运营环境中, 我们经常碰到类似这样的需求: 譬如想不影响现网业务评估DB补丁在现网环境中运行的时间, 或者是想在做DB切 ...
随机推荐
- nyoj762——分解质因数+容斥+二分
第k个互质数 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的 ...
- 每天学一点---图形图像GDI编程
首先先了解什么是 GDI 呢?GDI 是从 Windows 95 到 Windows 2000 随附的旧版绘图装置接口 (Graphics Device Interface), 是属于绘图方面的 AP ...
- Linux命令nohup+screen 转
如果想在关闭ssh连接后刚才启动的程序继续运行怎么办,可以使用nohup.但是如果要求第二天来的时候,一开ssh,还能查看到昨天运行的程序的状态,然后继续工作,这时nohup是不行了,需要使用scre ...
- Qt:表格 tableWidget
1.设置行数和列数 //设置行数 tableWidget->setRowCount(); //设置列数 tableWidget->setColumnCount(); 2.隐藏表头 tabl ...
- Linux(CentOS7)下发送邮件(使用Gmail作为发件服务器)
参考下述文章的思路,补充了在Gmail上的相关设置 https://gist.github.com/ilkereroglu/aa6c868153d1c5d57cd8 1.安装mailx yum ins ...
- resizable可调整尺寸组件
Resizable 可调整尺寸不依赖于其他组件 1.用法:通过标记创建可调整尺寸(resizable)对象 <div class="easyui-resizable" sty ...
- 将VIM打造成强大的IDE
转载自:所需即所获:像 IDE 一样使用 vim 如侵犯您的版权,请联系:2378264731@qq.com --------------------------------------------- ...
- 剑指offer--50.滑动窗口的最大值
时间限制:1秒 空间限制:32768K 热度指数:157641 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的 ...
- keepererrorcode = connectionloss for 错误处理
自己的环境在虚拟机上,于是使用同事的环境调试问题,发现无法初始化成功,提示keepererrorcode = connectionloss for,于是上网查了下资料整理如下: 1.对比代码中引用的j ...
- win10 安装MongoDB
win10上面安装mongodb的时候,注意不要勾选上Install MongoDB Compass, 否则会退出报错!!!! mongodb的安装 我是在E盘建立的一个mongodb文件夹,用来安装 ...