[20170309]关于在线日志与归档1.txt
--//当日志写满了,或者执行手工了切换,再或者rman备份时有时也会触发日志切换:
alter system switch logfile ;
alter system archive log current ;
--//本文简单探究日志归档是如何保存的.先探查os块.
1.环境:
--//启动到mount状态.
SYS@book> @ &r/ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SYS@book> @ &r/logfile
GROUP# STATUS TYPE MEMBER IS_ GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
------ ---------- ---------- ------------------------------- --- ------ ------- --------- ----------- --------- ------- --- ---------- ------------- ------------------- ------------ -------------------
1 ONLINE /mnt/ramdisk/book/redo01.log NO 1 1 695 52428800 512 1 YES INACTIVE 13276910949 2017-02-28 14:40:12 13276931102 2017-03-09 10:01:48
2 ONLINE /mnt/ramdisk/book/redo02.log NO 2 1 696 52428800 512 1 YES INACTIVE 13276931102 2017-03-09 10:01:48 13276931986 2017-03-09 10:02:36
3 ONLINE /mnt/ramdisk/book/redo03.log NO 3 1 697 52428800 512 1 NO CURRENT 13276931986 2017-03-09 10:02:36 2.814750E+14
4 STANDBY /mnt/ramdisk/book/redostb01.log NO
5 STANDBY /mnt/ramdisk/book/redostb02.log NO
6 STANDBY /mnt/ramdisk/book/redostb03.log NO
7 STANDBY /mnt/ramdisk/book/redostb04.log NO
7 rows selected.
--//仅仅拿seq#=696 来研究.
$ ls -l /mnt/ramdisk/book/redo02.log /u01/app/oracle/archivelog/book/1_696_896605872.dbf
-rw-r----- 1 oracle oinstall 52429312 2017-03-09 10:02:36 /mnt/ramdisk/book/redo02.log
-rw-r----- 1 oracle oinstall 1626112 2017-03-09 10:02:38 /u01/app/oracle/archivelog/book/1_696_896605872.dbf
--//可以发现2者大小不一样.你可以观察基本不会写满50M,大约4XM就会发生日志切换.
--//我以前oracle在归档时会删除一些类似空洞的空间,从而减少归档大小.拿这两个文件做一些简单探究:
2.首先探究日志文件的OS块:
--//oracle不管数据文件还是日志文件,第0块都是OS块,大小与块大小有关,日志一般块大小512字节.
--//所以从os角度看,建立50M的日志文件,实际大小是50M+512字节.
--//首先检查是否可以倍512整除.
52429312/512=102401 = 0x19001 (不包括OS块 是 0x19000)
1626112/512= 3176 = 0xc68 (不包括OS块 是 0xc67)
--然后对比前面的字节是否一样.
$ dd if=/mnt/ramdisk/book/redo02.log bs=512 count=3176 2>/dev/null | md5sum
812745bc5d7da07bcfa11e578b949226 -
$ md5sum /u01/app/oracle/archivelog/book/1_696_896605872.dbf
3e197986a3dfd1c392e052a14400d4c1 /u01/app/oracle/archivelog/book/1_696_896605872.dbf
--//可以发现不一样.也就是oracle日志转储归档时,不是简单的拷贝操作.
$ dd if=/mnt/ramdisk/book/redo02.log bs=512 count=1 | xxd -c 16 >| r0.txt
$ dd if=/u01/app/oracle/archivelog/book/1_696_896605872.dbf bs=512 count=1 | xxd -c 16 > d0.txt
$ diff r0.txt d0.txt
2c2
< 0000010: 67c8 0000 0002 0000 0090 0100 7d7c 7b7a g?.........}|{z
---
> 0000010: 0154 0000 0002 0000 670c 0000 7d7c 7b7a .T......g...}|{z
--// 7d7c7b7a 有看到熟悉的东西,数据文件的OS块也能看到一样的信息.}
--//你可以看出偏移0x18~0x1B处 在线日志是0090 0100 =>如果4个字节颠倒 00019000 这里就是日志块数量(不包括OS块).
备用日志是670c 0000 =>如果4个字节颠倒 00000c67 这里就是日志块数量(不包括OS块).
--//与前面的计算数量一致.
--//但是前面的67c8 ,0154 表示什么呢? 很自然的猜想检查和(因为数据库(8k数据块大小),这个位置就是检查和.例子:
BBED> p dba 4,135 chkval_kcbh
ub2 chkval_kcbh @16 0xe273
--//可以猜测这个位置也是检查和.做一个证明看看.
3.取出计算:
$ cut -c10-50 r0.txt >| aa1.txt
...
0000
0000
xor result: 0
$ cut -c10-50 d0.txt >| aa1.txt
0000
0000
xor result: 0
--//异或的结果都是0,说明oracle在归档时OS块在偏移0x18~0x1B处写入块归档的数量(不包括OS块),然后在0x10-0x11处计算检查和.
--//转载一个链接,我认为分析比较仔细的:http://www.ludatou.com/?p=1334
在ue打开的16进制中每行是16bytes,一共32行,这为第一个块file header block.这个block包含的信息有限,逐一分析:
$ bvi80 -s 512 -b 0 /mnt/ramdisk/book/redo02.log
00000000 00 22 00 00 00 00 C0 FF 00 00 00 00 00 00 00 00 ................
00000010 67 C8 00 00 00 02 00 00 00 90 01 00 7D 7C 7B 7A g...........}|{z
00000020 A0 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000200
--//注:这里是我测试机器上的redo文件}
从第一个字节开始到第二个字节为0x22,这2个字节通常为oracle 文件类型的标识,像数据文件的开头这里就为0xA2,这里的0x22就代表
redo log file.接着下来第一行就没有有意义的东西了其中的0xFFC0应该和scn中的base部分有关.再看看第二行的16个字节,可以发现在
第21和22字节0x0200换算成10进制格式则为512,这里即代表block size.从第25到28字节0x00019000换算成10进制后为102400,而
0x00019000代表redo block的数量,这里即为代表这个file的blocks或者理解为这个file的size.而在后续跟着的0x7a7b7c7d为文件标识符
,为oracle快速识别文件的一种标识.到这之后第一个块的信息就没啦!
--//实际上如果后面00的地方修改任意字符,使用
SYS@book> alter system dump logfile '/u01/app/oracle/archivelog/book/1_696_896605872.dbf' validate;
System altered.
--//oracle并不报错.