真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

checkpoint時(shí)的SCN寫文件動(dòng)作

參考自:http://blog.csdn.net/tianlesoftware/article/details/5251916

當(dāng)發(fā)生checkpoint時(shí),會(huì)把SCN寫到四個(gè)地方去:三個(gè)地方于control file內(nèi),一個(gè)在datafile header。

一、實(shí)驗(yàn),如下:
--Control fil e三個(gè)地方為:
1.1 System checkpoint SCN ===========> (SYSTEM CHECKPOINT SCN in control file)
SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
           3779864

1.2 Datafile checkpoint SCN ===============> (DATAFILE CHECKPOINT SCN in control file)
SQL> set lines 200
SQL> col name for a60
SQL> select name,checkpoint_change#from v$datafile;

NAME                                                         CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3779864
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3779864
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3779864
/u01/app/oracle/oradata/DBdb/users01.dbf                                3779864
/u01/app/oracle/oradata/DBdb/example01.dbf                              3779864


1.3 Stop SCN ======================> (STOP SCN in control file)
SQL> select name,last_change# from v$datafile;

NAME                                                         LAST_CHANGE#
------------------------------------------------------------ ------------
/u01/app/oracle/oradata/DBdb/system01.dbf
/u01/app/oracle/oradata/DBdb/sysaux01.dbf
/u01/app/oracle/oradata/DBdb/undotbs01.dbf
/u01/app/oracle/oradata/DBdb/users01.dbf
/u01/app/oracle/oradata/DBdb/example01.dbf

正常datafile在read-write mode下  last_change#一定是NULL


--另外一個(gè)地方在datafile header內(nèi)

1.4 Start SCN ================================> (DATAFILE HEADER)
SQL> select name, checkpoint_change# from v$datafile_header;

NAME                                                         CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3779864
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3779864
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3779864
/u01/app/oracle/oradata/DBdb/users01.dbf                                3779864
/u01/app/oracle/oradata/DBdb/example01.dbf                              3779864

SQL>   

二、相關(guān)問題

2.1 為什么儲(chǔ)存在CONTROL FILE中要分為兩個(gè)地方(SYSTEM CHECKPOINT SCN,DATAFILE CHECKPOINT SCN) ?

當(dāng)你把一個(gè)tbs設(shè)為read-only時(shí),他的SCN會(huì)凍結(jié)停止,此時(shí)DATAFILE CHECKPOINT SCN是不會(huì)再遞增改變的, 但是整體的SYSTEM CHECKPOINT SCN卻仍然會(huì)不斷遞增前進(jìn)。
所以,這就是為什么需要分別在兩個(gè)地方儲(chǔ)存SCN

2.2 正常shutdown database后,SCN會(huì)發(fā)生什么變化?我們可以把數(shù)據(jù)庫開在mount mode,如下:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             549456976 bytes
Database Buffers          281018368 bytes
Redo Buffers                2371584 bytes
Database mounted.
SQL>
SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
           3782319

SQL> select name,checkpoint_change# from v$datafile;

NAME                                                         CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3782319
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3782319
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3782319
/u01/app/oracle/oradata/DBdb/users01.dbf                                3782319
/u01/app/oracle/oradata/DBdb/example01.dbf                              3782319

SQL> select name,checkpoint_change#,last_change# from v$datafile;

NAME                                                         CHECKPOINT_CHANGE# LAST_CHANGE#
------------------------------------------------------------ ------------------ ------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3782319      3782319
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3782319      3782319
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3782319      3782319
/u01/app/oracle/oradata/DBdb/users01.dbf                                3782319      3782319
/u01/app/oracle/oradata/DBdb/example01.dbf                              3782319      3782319

可以看到儲(chǔ)存在control file中的三個(gè)SCN位置都是相同,注意此時(shí)的stop scn不會(huì)是NULL,而是等于start scn

SQL> select name,checkpoint_change# from v$datafile_header;

NAME                                                         CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3782319
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3782319
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3782319
/u01/app/oracle/oradata/DBdb/users01.dbf                                3782319
/u01/app/oracle/oradata/DBdb/example01.dbf                              3782319

當(dāng)clean shutdown時(shí),checkpoint會(huì)進(jìn)行,并且此時(shí)datafile的stop scn和start scn會(huì)相同。 等到我門開啟數(shù)據(jù)庫時(shí),Oracle檢查datafile header中的start scn和存于control file中的datafile的scn是否相同, 如果相同,接著檢查start scn和stop scn是否相同,如果仍然相同,數(shù)據(jù)庫就會(huì)正常開啟,否則就需要recovery... 等到數(shù)據(jù)庫開啟后,儲(chǔ)存在control file中的stop scn就會(huì)恢復(fù)為NULL值,此時(shí)表示datafile是open在正常模式下了。

如果不正常SHUTDOWN (shutdown abort),則mount數(shù)據(jù)庫后,你會(huì)發(fā)現(xiàn)stop scn并不是等于其它位置的scn, 而是等于NULL,這表示Oracle在shutdown時(shí)沒有進(jìn)行checkpoint,下次開機(jī)必須進(jìn)行crash recovery。

crash recovery:
必須先進(jìn)行roll forward(從redo log file中從目前的start SCN開始,重做后面的已提交之交易)。再從roll back segment 做rollback未完成(dead transaction)交易。檢驗(yàn)controlfile中的SCN會(huì)等于datafile header的SCN

2.3 先進(jìn)行備份:(數(shù)據(jù)庫處于mount狀態(tài),冷備);
RMAN> backup database tag='full database';

Starting backup at 28-NOV-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/DBdb/users01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/DBdb/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/DBdb/undotbs01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/DBdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/DBdb/example01.dbf
channel ORA_DISK_1: starting piece 1 at 28-NOV-17
   channel ORA_DISK_1: finished piece 1 at 28-NOV-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/backupset/2017_11_28/o1_mf_nnndf_FULL_DATABASE_f1t8rv9q_.bkp tag=FULL DATABASE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 28-NOV-17
channel ORA_DISK_1: finished piece 1 at 28-NOV-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/backupset/2017_11_28/o1_mf_ncsnf_FULL_DATABASE_f1t8z23m_.bkp tag=FULL DATABASE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 28-NOV-17

RMAN>

--shutdown abort數(shù)據(jù)庫:
SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database open;

Database altered.

SQL> shutdown abort;
ORACLE instance shut down.
SQL>
--啟庫:
SQL>  conn / as sysdba
Connected to an idle instance.
SQL>
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             549456976 bytes
Database Buffers          281018368 bytes
Redo Buffers                2371584 bytes
SQL>
SQL> alter database mount;

Database altered.

--查詢scn狀態(tài):
SQL> select checkpoint_change# from v$database;

CHECKPOINT_CHANGE#
------------------
           3782322

SQL> select name,checkpoint_change#,last_change# from v$datafile;

NAME                                                         CHECKPOINT_CHANGE# LAST_CHANGE#
------------------------------------------------------------ ------------------ ------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3782322
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3782322
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3782322
/u01/app/oracle/oradata/DBdb/users01.dbf                                3782322
/u01/app/oracle/oradata/DBdb/example01.dbf                              3782322

stop scn并不是等于其它位置的scn, 而是等于NULL,表示需要進(jìn)行crash recovery

SQL> select name,checkpoint_change# from v$datafile_header;

NAME                                                         CHECKPOINT_CHANGE#
------------------------------------------------------------ ------------------
/u01/app/oracle/oradata/DBdb/system01.dbf                               3782322
/u01/app/oracle/oradata/DBdb/sysaux01.dbf                               3782322
/u01/app/oracle/oradata/DBdb/undotbs01.dbf                              3782322
/u01/app/oracle/oradata/DBdb/users01.dbf                                3782322
/u01/app/oracle/oradata/DBdb/example01.dbf                              3782322


2.4 crash recovery 和media recovery 的比較
啟動(dòng)數(shù)據(jù)庫時(shí),如果發(fā)現(xiàn)STOP SCN = NULL,表示需要進(jìn)行crash recovery;啟動(dòng)數(shù)據(jù)庫時(shí),如果發(fā)現(xiàn)有datafile header的START SCN 不等于儲(chǔ)存于CONTROLFILE的DATAFILE SCN,表示需要進(jìn)行Media recovery

STOP SCN equal NULL ==> NEED CRASH RECOVERY

DATAFILE HEADER START SCN not equal CONTROLFILE SCN ==> NEED MEDIA RECOVERY


三、RECOVERY DATABASE 兩種常見問題
3.1 RECOVER DATABASE UNTIL CANCEL ==> OPEN DATABASE RESETLOG
==> DATAFILE HEADER SCN一定會(huì)小于CONTROLFILE的DATAFILE SCN

如果你有進(jìn)行RESTORE DATAFILE,則該RESTORE的DATAFILE HEADER SCN一定會(huì)小于目前CONTROLFILE的DATAFILE SCN,此時(shí)會(huì)無法開啟數(shù)據(jù)庫,必須進(jìn)行media recovery。 重做archive log直到該datafile header的SCN=current scn

restore datafile后,可以mount database然后去檢查controlfile and datafile header的SCN

select 'controlfile' "SCN location",name,checkpoint_change#
from v$datafile where name like '%users01%'
union
select 'file header',name,checkpoint_change#
from v$datafile_header where name like '%users01%';


3.2  RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE; ===> OPEN DATABASE RESETLOG

==> DATAFILE HEADER SCN一定會(huì)大于CONTROLFILE的DATAFILE SCN

如果只是某TABLE被DROP掉,沒有破壞數(shù)據(jù)庫整體數(shù)據(jù)結(jié)構(gòu),還可以用NCOMPLETE RECOVERY解決 如果是某個(gè)TABLESPACE OR DATAFILE被DROP掉,因?yàn)闄n案結(jié)構(gòu)已經(jīng)破壞,目前的CONTROL FILE內(nèi)已經(jīng)沒有 該DATAFILE的信息,就算你只RESTORE DATAFILE然后進(jìn)行INCOMPLETE RECOVERY也無法救回被DROP的DATA FILE。

只好RESOTRE 之前備份的CONTROL FILE(里頭被DROP DATAFILE Metadata此時(shí)還存在),不過RESTOREC CONTROL FILE后 此時(shí)Oracle會(huì)發(fā)現(xiàn)CONTROL FILE內(nèi)的SYSTEM SCN會(huì)小于目前的DATAFILE HEADER SCN,也不等于目前儲(chǔ)存于LOG FILE內(nèi)的SCN, 此時(shí)就必須使用RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE到DROP DATAFILE OR DROP TABLESPACE之前的SCN。

另一種特殊狀況就是,萬一不幸地所有CONTROL FILE都遺失了,也必須用這種方式救回,所以請(qǐng)做MULTIPLEXING。




網(wǎng)頁名稱:checkpoint時(shí)的SCN寫文件動(dòng)作
網(wǎng)站網(wǎng)址:http://weahome.cn/article/pjscid.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部