learn by doing,less theory,more results.
internal mechanism of ogg:
在上一章已经把ogg基本安装,配置完成。接下来讲解internal mechanism (内部机制)。
ogg跟db关系:
ogg extract 内部组成:
1.通过extract参数文件,登录数据库,直接读取online redo log和archive log日志内容,优先读取online redo log日志,如果找不到数据则去读取archive log日志,如果还是找不到想要的数据则通过redo parsing去解析redo log日志,然后写到trail 文件, data pump读取trail文件传输到远端。
when extract encounters the start of a tranaction in the redolog(in oracle,this is the first execute DML SQL statement) it satrts caahing to memory all of the data that is spectified to be captured for that tranaction.
extract must cache a transaction even if it contains no capture data,because future operation of that transaction might contain data that is to be captured.
由此可见,extract捕获所有已提交的transaction数据放在内存中(并不是只捕获bobo下的表事务数据),并写到trail文件中。如果一个事务回退,直接释放内存,并不会写到trail文件中。由此可见trail文件中存放的都是已提交的事务。
extract checkpoint :
查看extract进程当前检查点信息:
GGSCI (localhost.localdomain) 3> info ext1,showch
EXTRACT EXT1 Last Started 2017-10-30 18:50 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:10 ago)
Log Read Checkpoint Oracle Redo Logs
2017-10-31 20:27:29 Seqno 22, RBA 13527552
SCN 0.1178527 (1178527)
Current Checkpoint Detail:
Read Checkpoint #1
Oracle Redo Log
Startup Checkpoint (starting position in the data source):
Thread #: 1
Sequence #: 10
RBA: 3072016
Timestamp: 2017-10-30 18:48:44.000000
SCN: Not available
Redo File:
Recovery Checkpoint (position of oldest unprocessed transaction in the data source):
Thread #: 1
Sequence #: 22
RBA: 13526544
Timestamp: 2017-10-31 20:27:29.000000
SCN: 0.1178526 (1178526)
Redo File: /u01/app/oracle/oradata/SOURCE/onlinelog/o1_mf_1_dzf7qdmj_.log
Current Checkpoint (position of last record read in the data source):
Thread #: 1
Sequence #: 22
RBA: 13527552
Timestamp: 2017-10-31 20:27:29.000000
SCN: 0.1178527 (1178527)
Redo File: /u01/app/oracle/oradata/SOURCE/onlinelog/o1_mf_1_dzf7qdmj_.log
BR Previous Recovery Checkpoint:
Thread #: 0
Sequence #: 0
RBA: 0
Timestamp: 2017-10-30 18:50:31.825487
SCN: Not available
Redo File:
BR Begin Recovery Checkpoint:
Thread #: 1
Sequence #: 22
RBA: 3069440
Timestamp: 2017-10-31 18:51:07.000000
SCN: 0.1171143 (1171143)
Redo File:
BR End Recovery Checkpoint:
Thread #: 1
Sequence #: 22
RBA: 3069440
Timestamp: 2017-10-31 18:51:07.000000
SCN: 0.1171143 (1171143)
Redo File:
Write Checkpoint #1
GGS Log Trail
Current Checkpoint (current write position):
Sequence #: 0
RBA: 1763
Timestamp: 2017-10-31 20:28:06.104919
Extract Trail: /u01/gg/dirdat/ex
CSN state information:
CRC: 6-9F-5A-B9
Latest CSN: 1171852
Latest TXN: 1.26.825
Latest CSN of finished TXNs: 1171852
Completed TXNs: 1.26.825
Header:
Version = 2
Record Source = A
Type = 10
# Input Checkpoints = 1
# Output Checkpoints = 1
File Information:
Block Size = 2048
Max Blocks = 100
Record Length = 2048
Current Offset = 0
Configuration:
Data Source = 3
Transaction Integrity = 1
Task Type = 0
Status:
Start Time = 2017-10-30 18:50:32
Last Update Time = 2017-10-31 20:28:06
Stop Status = A
Last Result = 400
SQL> select group#,sequence#,status from v$log;
GROUP# SEQUENCE# STATUS
---------- ---------- ----------------
1 22 CURRENT
2 20 INACTIVE
3 21 INACTIVE
在第一章配置extract的时候,有一个begin now参数,记住当前时间并转换成scn
SQL> select to_char(scn_to_timestamp(1178527),'yyyy-mm-dd hh24:mm:ss') from dual;
TO_CHAR(SCN_TO_TIME
-------------------
2017-10-31 20:10:28
解析:
RBA 13527552:读取第22号日志的13527552位置
Read Checkpoint #1:单节点是thread 1,如果是rac 双节点 这里就不一定为1.
startup checkpoint - the first checkpoint that is made in the data source when the process starts.
recovery checkpoint - the position in the data source of the record containing the oldest transaction not yet processes by extract.
current checkpoint - the postition of the last record read by extract in the data source.
RBA(relative byte address):相对于文件头的偏移量,已发送字节数位置,可以通过rba得到某个字节数。
write checkpoint 使用rba参考位置
redo stream 使用scn参考
rc 记录数据库最早发生事务的scn,事务提交rc就会向前移动,并把对应的数据从内存写到trail文件,释放内存。如果数据库突然宕机,只要最早的事务未提交,rc就不会变化。
GGSCI (localhost.localdomain) 4> info ext1 detail
EXTRACT EXT1 Last Started 2017-10-30 18:50 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:10 ago)
Log Read Checkpoint Oracle Redo Logs
2017-11-01 07:44:00 Seqno 26, RBA 10543616
SCN 0.1240880 (1240880)
Target Extract Trails:
Remote Trail Name Seqno RBA Max MB
/u01/gg/dirdat/ex 0 1763 300
Extract Source Begin End
/u01/app/oracle/oradata/SOURCE/onlinelog/o1_mf_2_dzf7qdqs_.log 2017-10-30 18:48 2017-11-01 07:44
Not Available * Initialized * 2017-10-30 18:48
Current directory /u01/gg
Report file /u01/gg/dirrpt/EXT1.rpt
Parameter file /u01/gg/dirprm/ext1.prm
Checkpoint file /u01/gg/dirchk/EXT1.cpe
Process file /u01/gg/dirpcs/EXT1.pce
Stdout file /u01/gg/dirout/EXT1.out
Error log /u01/gg/ggserr.log
可见,检查点文件在‘/u01/gg/dirchk/EXT1.cpe’,这是个二进制文件,我们可以dump出来看看,
hexdump -Cv -n 4096 /u01/gg/dirchk/EXT1.cpe >/tmp/ext1.txt