Chinaunix首页 | 论坛 | 博客
  • 博客访问: 510496
  • 博文数量: 101
  • 博客积分: 1635
  • 博客等级: 上尉
  • 技术积分: 1282
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-05 01:51
文章分类

全部博文(101)

文章存档

2019年(2)

2018年(16)

2013年(14)

2012年(69)

我的朋友

分类: Oracle

2018-10-15 10:08:57

在oracle中存在很多种scn,但是,只有如下几种是我们比较关注的。
commit scn/cleanout scn
database scn/on disk scn/thread scn/datafile checkpoint scn/start scn
offline scn/online scn
resetlogs scn
stop scn
low/high scn
下面我们通过实验来展示,描述上述几种scn:
++++++commit scn/cleanout scn
SQL> create table t1( a number);


Table created.


SQL> insert into t1 values(10);


1 row created.


SQL> /


1 row created.


SQL> /


1 row created.


SQL> /


1 row created.


SQL> commit;


Commit complete.


SQL> select dbms_rowid.rowid_relative_fno(rowid) file#,dbms_rowid.rowid_block_number(rowid) blk# from t1;


   FILE#       BLK#
---------- ----------
         4      12430
         4      12430
         4      12430
         4      12430
         4      12430
         4      12430
         4      12430


SQL> oradebug setmypid
Statement processed.
SQL> alter system dump datafile 4 block 12430;


System altered.


SQL> oradebug tracefile_name
/home/oracle/app/diag/rdbms/oracleogg/oracleogg/trace/oracleogg_ora_6019.trc


*** 2015-09-14 13:17:04.448
Start dump data blocks tsn: 4 file#:4 minblk 12430 maxblk 12430
Block dump from cache:
Dump of buffer cache at level 4 for tsn=4 rdba=16789646
BH (0x853dc2d0) file#: 4 rdba: 0x0100308e (4/12430) class: 1 ba: 0x850a4000
  set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 2 pwc: 19,28
  dbwrid: 0 obj: 87366 objn: 87366 tsn: 4 afn: 4 hint: f
  hash: [0x8d52ee80,0x8d52ee80] lru: [0x853dc4f8,0x853dc288]
  obj-flags: object_ckpt_list
  ckptq: [0x82ff43f0,0x853dc540] fileq: [0x8dfcb918,0x853dc550] objq: [0x853dc520,0x853dc2b0] objaq: [0x853dc530,0x853dc2c0]
  st: XCURRENT md: NULL fpin: 'ktspbwh2: ktspfmdb' tch: 4
  flags: buffer_dirty redo_since_read
  LRBA: [0x77.ee.0] LSCN: [0x0.1a0bd9] HSCN: [0x0.1a0be0] HSUB: [1]
Block dump from disk:
buffer tsn: 4 rdba: 0x0100308e (4/12430)
scn: 0x0000.001308e9 seq: 0x02 flg: 0x04 tail: 0x08e90602
frmt: 0x02 chkval: 0x240c type: 0x06=trans data
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007F36615B5A00 to 0x00007F36615B7A00
7F36615B5A00 0000A206 0100308E 001308E9 04020000  [.....0..........]
7F36615B5A10 0000240C 00000001 000154B0 001308E4  [.$.......T......]
Block header dump:  0x0100308e
 Object id on Block? Y
 seg/obj: 0x154b0  csc: 0x00.1308e4  itc: 3  flg: E  typ: 1 - DATA
     brn: 0  bdba: 0x1003088 ver: 0x01 opc: 0
     inc: 0  exflg: 0


 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   0xffff.000.00000000  0x00000000.0000.00  C---    0  scn 0x0000.001308e4
0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000
0x03   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000
bdba: 0x0100308e
data_block_dump,data header at 0x7f36615b5a7c
===============
tsiz: 0x1f80
hsiz: 0xae
pbl: 0x7f36615b5a7c
     76543210
flag=--------
ntab=1
nrow=78
frre=-1
fsbo=0xae
fseo=0x3f0
avsp=0x342
tosp=0x342
0xe:pti[0]      nrow=78 offs=0
0x12:pri[0]     offs=0x1f2e
0x14:pri[1]     offs=0x1ed3
0x16:pri[2]     offs=0x1e77
0x18:pri[3]     offs=0x1e1f
0x1a:pri[4]     offs=0x1dc6
0x1c:pri[5]     offs=0x1d69
0x1e:pri[6]     offs=0x1d06
0x20:pri[7]     offs=0x1ca3
0x22:pri[8]     offs=0x1c4a
0x24:pri[9]     offs=0x1beb
0x26:pri[10]    offs=0x1b8c
0x28:pri[11]    offs=0x1b34
0x2a:pri[12]    offs=0x1ada
0x2c:pri[13]    offs=0x1a7f
0x2e:pri[14]    offs=0x1a20
0x30:pri[15]    offs=0x19c0
0x32:pri[16]    offs=0x195e
0x34:pri[17]    offs=0x1907
0x36:pri[18]    offs=0x18a8
0x38:pri[19]    offs=0x1849
0x3a:pri[20]    offs=0x17f6
0x3c:pri[21]    offs=0x179c
0x3e:pri[22]    offs=0x1743
0x40:pri[23]    offs=0x16ed


针对上面的scn相关内容进行解释:
scn: 0x0000.001308e9 这其实就是block scn,转换为十进制为: 1247465
 csc: 0x00.1308e4 这是cleanout scn,最后一次的full cleanout时的scn值,转换为10进制后为:1247460
Scn/Fsc 0x0000.001308e4 :这里表 commit scn或fast commit scn




我们来dump  controlfile和datafile header的信息,进行观察:
oradebug setmypid
alter session set events 'immediate trace name CONTROLF level 4';
alter session set events 'immediate trace name FILE_HDRS level 3';


+++++++++++offline scn/online scn
当表空间或数据文件被offline时,其对应的数据文件的scn会写入一个值,被称为offline scn.
archivelog模式下,当表空间offlline时,对对应的数据文件头stop scn会更新,同时controlfile中该datafile的stopscn信息也会更新。
当online后,对应的数据文件头的online scn等于datafile checkpoint scn值。
当online后,controlfile中关于该表空间对应的datafile和对应的数据文件头的stop scn都会重新被置于最大值。


+++++++++++++++什么是resetlogs scn?顾名思义就是open resetlogs方式打开数据库是对应的scn值。
stop scn,顾名思义是指数据库或数据文件在某个时刻处于停止状态时的scn值,当处于run状态时,该值是被设置为无穷大的。
转储控制文件的过程:
shudown immediate;
startup mount;


oradebug setmypid;
alter session set events 'immediate trace name CONTROLF level 4';
oradebug tracefile_name
oradebug close_trace




说明:level 1----dump controlfile header
level 2----level 1+datafile 文件头信息
level 3------level+可重用信息
level 10 ------level 3+其他全部信息


转储数据文件:
alter system dump datafile 1 block 59490;
alter system set events 'immediate trace name file_hdrs level 3';
+++++ high scn/low scn
日志文件的scn
oracle 的redo log日志文件中,其实也存在着一种scn,那就是high scn/low scn。我们首先通过视图来查询了解一下:


select recid,sequence#,first_change#,next_change# from v$log_history;


95         95       1470210      1495090
那什么是low scn 和high scn?如果上面的查询来解释,那么久可以简单的理解为:
first_change#就是low scn,而 next_change#值就是high scn.
简单的讲,redo log scn指redo log 在进行切换时刻对应的scn的值,而scn又对应着时间,在进行实例恢复时,是需要
通过该值来确认需要应用哪些archivelog或者redo log的。
 oradebug setmypid;
 alter session set events 'immediate trace name loghist level 1';
 
 DUMP OF LOG HISTORY: 95 history records
Earliest record:
 RECID #1 Recno 1 Record timestamp  07/23/15 15:44:00 Thread=1 Seq#=1 Link-Recid=0 kccic-Recid=1
  Low scn: 0x0000.00000001 07/23/15 15:43:12 Next scn: 0x0000.00004c00
Latest record:
 RECID #95 Recno 95 Record timestamp  09/06/15 14:44:04 Thread=1 Seq#=95 Link-Recid=94 kccic-Recid=1
  Low scn: 0x0000.00166f02 08/29/15 22:08:03 Next scn: 0x0000.0016d032
  
  我们看到95的这个low scn:1470210 netx scn:1495090




--------controlfile dump
LOG FILE #3:
  name #3: /home/oracle/app/oradata/oracleogg/redo03.log
 Thread 1 redo log links: forward: 0 backward: 2
 siz: 0x19000 seq: 0x00000060 hws: 0x3 bsz: 512 nab: 0x6ce flg: 0x8 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.00166f02--这里的prev scn其实就对应上面查询的first change#值。
 Low scn: 0x0000.0016d032 09/06/2015 14:44:04--这里的low scn对应上面的next change值(因为这里查看current log信息,前面是dump的redo log history)
 Next scn: 0xffff.ffffffff 01/01/1988 00:00:00
 这里的next scn其实有点类似datafile 的stop scn,对于current log来说,总是被设置为无穷大的。


阅读(5852) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~