关于SCN的总结测试 (68天)
发布日期:2021-06-30 13:23:38 浏览次数:2 分类:技术文章

本文共 6653 字,大约阅读时间需要 22 分钟。

scn是数据库对自身变化的一个标记。通过一个序列号能够反映出数据库在那个时间点正在进行的操作,scn没有选用时间来作为基准单位,可能也是因为时间的不确定性,比如当前时间为2014年3月14号晚上八点整,如果修改了系统时间,改为晚上七点钟,name重启数据库以后,那个时间段的操作就都乱套了。这个scn在一般的库上都看似比较大,根据数据库的设计角度来说,这个scn能够使用很长很长的时间。scn的变化也基本分为四类,实例级别scn,数据文件scn,数据文件头scn,结束scn,为了测试scn的变化情况,准备了下面的场景1)全局检查点更新 如alter system checkpoint,数据库级scn应该会发生变化。2)resize 数据文件 把数据文件的大小进行改变3)切换redo日志文件4)归档当前日志文件5)创建表6)插入数据7)插入一些数据,频繁的commit8)插入一些数据,频繁的rollback测试的结果如下,对于发生变化的部分都用黄色进行了标注。可以比对测试场景对比学习一下。有些场景没有涉及到,目的只是向大家分享一下日常的操作中scn的变化。

测试场景 database level datafile&header redo log
chk_change# ctl_change# ctl_time curr_scn archive_change# chk_change# last_change# first_change# nxt_change#
beginning 3626097 3626320 2014-05-09 02:56:11 3626335 3626097 pool_data 3626318
others 3626097
504377 514666
alter system checkpoint; 3626336 3626336 2014-05-09 02:56:36 3626337 3626097 3626336
504377 514666
resize datafile 3626336 3626338 2014-05-09 02:56:38 3626346 3626097 3626336
504377 514666
alter system switch logfile; 3626336 3626349 2014-05-09 02:56:38 3626350 3626097 3626336
504377 514666
alter system archive log current; 3626336 3626354 2014-05-09 02:56:39 3626355 3626354 3626336
504377 514666
create table aaaa as select * from dba_objects; 3626336 3626354 2014-05-09 02:56:39 3626417 3626354 3626336
504377 514666
insert into aaaa select *from aaaa;
commit;
3626336 3626354 2014-05-09 02:56:39 3626442 3626354 3626336
504377 514666
insert,commit;insert,commit;
insert,commit;…
3626336 3626354 2014-05-09 02:56:39 3626459 3626354 3626336
504377 514666
insert,insert,insert...rollback 3626336 3626354 2014-05-09 02:56:39 3626462 3626354 3626336
504377 514666

生成scn快照的脚本如下,对于每一个操作,都可以使用下面的脚本从数据库级,数据文件,数据文件头,在线日志等维度进行scn的查验。sqlplus -s n1/n1 <<EOFset pages 20prompt ######scn from database levelcol checkpoint_change# format 99999999999999999col RESETLOGS_CHANGE# format 99999999999999999col PRIOR_RESETLOGS_CHANGE# format 99999999999999999 col CONTROLFILE_CHANGE# format 99999999999999999 col ARCHIVELOG_CHANGE# format 99999999999999999 col CURRENT_SCN format 99999999999999999col control_time format a20set linesize 200select RESETLOGS_CHANGE# ,RESETLOGS_TIME,PRIOR_RESETLOGS_CHANGE#,CHECKPOINT_CHANGE#,CONTROLFILE_CHANGE# ,to_char(CONTROLFILE_TIME,'yyyy-mm-dd hh24:mi:ss') control_time,ARCHIVELOG_CHANGE#,CURRENT_SCN from v\$database;prompt #####scn from datafilecol checkpoint_change# format 99999999999999999col creation_change# format 99999999999999999col checkpoint_change# format 99999999999999999col last_change# format 99999999999999999col online_change# format 99999999999999999col online_time format a20col last_time format a20col checkpoint_time format a20col creation_time format a9col file# format 999set linesize 200select file#,creation_change#,creation_time,checkpoint_change#,to_char(checkpoint_time,'yyyy-mm-dd hh24:mi:ss') checkpoint_time,last_change#,to_char(last_time,'yyyy-mm-dd hh24:mi:ss')last_time,offline_change#,online_change#,to_char(online_time,'yyyy-mm-dd hh24:mi:ss')online_time from v\$datafile;prompt #####scn from datafile headercol tablespace_name format a10col resetlogs_change# format 99999999999999999col creation_time format a9--col undo_opt_current_change# format 99999999999999999col checkpoint_time format a20set linesize 200select file#,creation_change#,creation_time,tablespace_name,resetlogs_change#,resetlogs_time,checkpoint_change#,checkpoint_time,checkpoint_count from v\$datafile_header;prompt #####scn from redo col first_change# format 99999999999999999col next_change# format 99999999999999999col sequence# format 99999999999999999select *from (select recid,sequence#,first_change#,next_change# from v\$log_history )where rownum<20;EOFexit对如上的测试场景中scn的变化进行总结,一共会生成9个快照。ksh showscn.sh >beginning_snshowscn.shot.lst0sqlplus -s n1/n1 <<EOFalter system checkpoint; --全局,数据文件,数据文件头部scn都递增,保持一致EOFksh showscn.sh > checkpoint_snshowscn.shot.lst1sqlplus -s n1/n1 <<EOFalter database datafile '/u03/ora11g/oradata/TEST01/pool_data02.dbf' resize 160M; -->只有数据库级scn递增EOFksh showscn.sh > resize_datafile_snshowscn.shot.lst2sqlplus -s n1/n1 <<EOFalter system switch logfile; -->日志文件scn递增EOFksh showscn.sh > redo_switch_snshowscn.shot.lst3sqlplus -s n1/n1 <<EOFalter system archive log current;EOFksh showscn.sh >archive_current_snshowscn.shot.lst4sqlplus -s n1/n1 <<EOFcreate table aaaa as select * from dba_objects;EOFksh showscn.sh >create_tab_snshowscn.shot.lst5sqlplus -s n1/n1 <<EOFinsert into aaaa select *from aaaa;commit;EOFksh showscn.sh >insert_tab_snshowscn.shot.lst6sqlplus -s n1/n1 <<EOFinsert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;insert into aaaa select *from aaaa where rownum<10;commit;EOFksh showscn.sh >over_commit_snshowscn.shot.lst7sqlplus -s n1/n1 <<EOFinsert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;insert into aaaa select *from aaaa where rownum<10;rollback;EOFksh showscn.sh >rollback_snshowscn.shot.lst8运行脚本的日志如下:System altered.Database altered.System altered.System altered.Table created.13470 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete.9 rows created.Commit complete9 rows created.9 rows created.9 rows created.9 rows created.9 rows created.9 rows created.9 rows created.9 rows created.Rollback complete.生成的快照如下:-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 beginning_snshowscn.shot.lst0-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 checkpoint_snshowscn.shot.lst1-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 resize_datafile_snshowscn.shot.lst2-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 redo_switch_snshowscn.shot.lst3-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 archive_current_snshowscn.shot.lst4-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 create_tab_snshowscn.shot.lst5-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 insert_tab_snshowscn.shot.lst6-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 over_commit_snshowscn.shot.lst7-rw-r--r-- 1 ora11g dba 3144 May 9 02:56 rollback_snshowscn.shot.lst8

转载地址:https://jeanron100.blog.csdn.net/article/details/102506256 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:利用shell脚本生成动态sql(67天)
下一篇:生产系统中EXP-00000的问题及解决(66天)

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月23日 11时03分29秒