這篇文章給大家介紹Oracle 12c 備份與恢復(fù)中resetlogs的概念及用法是什么,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
成都創(chuàng)新互聯(lián)專(zhuān)注于榆社網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供榆社營(yíng)銷(xiāo)型網(wǎng)站建設(shè),榆社網(wǎng)站制作、榆社網(wǎng)頁(yè)設(shè)計(jì)、榆社網(wǎng)站官網(wǎng)定制、小程序定制開(kāi)發(fā)服務(wù),打造榆社網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供榆社網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
備份與恢復(fù)是一門(mén)重要的功課,其中一些基礎(chǔ)知識(shí)和用法會(huì)隨著實(shí)戰(zhàn)次數(shù)的增加而理解的越來(lái)越深刻。今天通過(guò)一個(gè)最簡(jiǎn)單的例子來(lái)體會(huì)一下resetlogs。
resetlogs: 重置online redolog。當(dāng)數(shù)據(jù)庫(kù)實(shí)例啟動(dòng)時(shí)需要具有redolog,如果該文件不可用或者不存在了,可以使用resetlogs開(kāi)啟數(shù)據(jù)庫(kù)。在開(kāi)啟的過(guò)程中oracle會(huì)根據(jù)控制文件中的redo路徑創(chuàng)建全新的redolog。在不完全恢復(fù)或者OGG部署時(shí)經(jīng)常會(huì)用到resetlogs方式開(kāi)啟數(shù)據(jù)庫(kù)。原因就是當(dāng)前的redo不可用,或者不能用。
實(shí)驗(yàn)步驟如下:
1, 一致性停庫(kù)
2, 手工刪除redolog
3, 啟動(dòng)數(shù)據(jù)庫(kù)到mount狀態(tài)
4, resetlogs方式打開(kāi)數(shù)據(jù)庫(kù)
1. 一致性停庫(kù)
[oracle@snow ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sat May 2 04:29:37 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
確認(rèn)數(shù)據(jù)文件、日志文聯(lián)、控制文件、臨時(shí)文件的物理位置
SYS@cdb > select name from v$datafile
2 union select name from v$controlfile
3 union select member from v$logfile
4 union select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/cdb/control01.ctl
/home/oracle/dbfile/cdb/control02.ctl
/home/oracle/dbfile/cdb/pdb1/SAMPLE_SCHEMA_users01.dbf
/home/oracle/dbfile/cdb/pdb1/example01.dbf
/home/oracle/dbfile/cdb/pdb1/pdb1_temp01.dbf
/home/oracle/dbfile/cdb/pdb1/sysaux01.dbf
/home/oracle/dbfile/cdb/pdb1/system01.dbf
/home/oracle/dbfile/cdb/pdbseed/pdbseed_temp01.dbf
/home/oracle/dbfile/cdb/pdbseed/sysaux01.dbf
/home/oracle/dbfile/cdb/pdbseed/system01.dbf
/home/oracle/dbfile/cdb/redo01.log
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/cdb/redo02.log
/home/oracle/dbfile/cdb/redo03.log
/home/oracle/dbfile/cdb/sysaux01.dbf
/home/oracle/dbfile/cdb/system01.dbf
/home/oracle/dbfile/cdb/temp01.dbf
/home/oracle/dbfile/cdb/undotbs01.dbf
/home/oracle/dbfile/cdb/users01.dbf
18 rows selected.
一致性停止數(shù)據(jù)庫(kù),確保redolog中的事務(wù)已經(jīng)寫(xiě)入磁盤(pán)
SYS@cdb > shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@cdb >
2. 手工刪除redolog
[oracle@snow ~]$ cd dbfile/cdb/
[oracle@snow cdb]$ ll
total 2135948
-rw-r----- 1 oracle oinstall 17973248 May 2 04:30 control01.ctl
-rw-r----- 1 oracle oinstall 17973248 May 2 04:30 control02.ctl
drwxr-x--- 2 oracle oinstall 4096 May 2 03:07 pdb1
drwxr-x--- 2 oracle oinstall 4096 May 2 03:01 pdbseed
-rw-r----- 1 oracle oinstall 52429312 May 2 04:30 redo01.log
-rw-r----- 1 oracle oinstall 52429312 May 2 04:29 redo02.log
-rw-r----- 1 oracle oinstall 52429312 May 2 04:29 redo03.log
-rw-r----- 1 oracle oinstall 796925952 May 2 04:30 sysaux01.dbf
-rw-r----- 1 oracle oinstall 817897472 May 2 04:30 system01.dbf
-rw-r----- 1 oracle oinstall 92282880 May 2 04:29 temp01.dbf
-rw-r----- 1 oracle oinstall 372252672 May 2 04:30 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 2 04:30 users01.dbf
[oracle@snow cdb]$ rm -rf redo*.log
[oracle@snow cdb]$ ll
total 1982336
-rw-r----- 1 oracle oinstall 17973248 May 2 04:30 control01.ctl
-rw-r----- 1 oracle oinstall 17973248 May 2 04:30 control02.ctl
drwxr-x--- 2 oracle oinstall 4096 May 2 03:07 pdb1
drwxr-x--- 2 oracle oinstall 4096 May 2 03:01 pdbseed
-rw-r----- 1 oracle oinstall 796925952 May 2 04:30 sysaux01.dbf
-rw-r----- 1 oracle oinstall 817897472 May 2 04:30 system01.dbf
-rw-r----- 1 oracle oinstall 92282880 May 2 04:29 temp01.dbf
-rw-r----- 1 oracle oinstall 372252672 May 2 04:30 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 2 04:30 users01.dbf
3. 啟動(dòng)數(shù)據(jù)庫(kù)到mount狀態(tài)
[oracle@snow cdb]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sat May 2 04:53:23 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@cdb > startup mount;
ORACLE instance started.
Total System Global Area 1503199232 bytes
Fixed Size 2288584 bytes
Variable Size 973079608 bytes
Database Buffers 520093696 bytes
Redo Buffers 7737344 bytes
Database mounted.
4.restlogs方式打開(kāi)數(shù)據(jù)庫(kù)
注意:執(zhí)行alter database open resetlog時(shí)會(huì)提示“RESETLOGS”選項(xiàng)需要在不完全恢復(fù)后使用,按照要求我們執(zhí)行一次recover database until cancel, 再次執(zhí)行alter database open resetlog就可以成功打開(kāi)數(shù)據(jù)庫(kù)并重新創(chuàng)建了redolog。
如果在數(shù)據(jù)庫(kù)處于mount狀態(tài)時(shí)先執(zhí)行recover,再執(zhí)行resetlogs就不會(huì)報(bào)錯(cuò)。
SYS@cdb > alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01139: RESETLOGS option only valid after an incomplete database recovery
SYS@cdb > recover database until cancel;
Media recovery complete.
SYS@cdb > alter database open resetlogs;
Database altered.
如果在數(shù)據(jù)庫(kù)處于mount狀態(tài)時(shí)先執(zhí)行recover,再執(zhí)行resetlogs就不會(huì)報(bào)錯(cuò)。
實(shí)例啟動(dòng)后,看到新的redolog被創(chuàng)建在之前的位置
SYS@cdb > exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@snow cdb]$ ll
total 2135948
-rw-r----- 1 oracle oinstall 17973248 May 2 04:54 control01.ctl
-rw-r----- 1 oracle oinstall 17973248 May 2 04:54 control02.ctl
drwxr-x--- 2 oracle oinstall 4096 May 2 03:07 pdb1
drwxr-x--- 2 oracle oinstall 4096 May 2 03:01 pdbseed
-rw-r----- 1 oracle oinstall 52429312 May 2 04:54 redo01.log
-rw-r----- 1 oracle oinstall 52429312 May 2 04:54 redo02.log
-rw-r----- 1 oracle oinstall 52429312 May 2 04:54 redo03.log
-rw-r----- 1 oracle oinstall 796925952 May 2 04:54 sysaux01.dbf
-rw-r----- 1 oracle oinstall 817897472 May 2 04:54 system01.dbf
-rw-r----- 1 oracle oinstall 92282880 May 2 04:54 temp01.dbf
-rw-r----- 1 oracle oinstall 372252672 May 2 04:54 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 2 04:54 users01.dbf
很多初學(xué)者在第一次接觸resetlogs選項(xiàng)都是在一些比較復(fù)雜的恢復(fù)場(chǎng)景時(shí)才遇到的。希望這個(gè)初級(jí)的小實(shí)驗(yàn)可以幫助你理解resetlogs。
關(guān)于Oracle 12c 備份與恢復(fù)中resetlogs的概念及用法是什么就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。