oracle結構梳理----checkpoint——啟動與關閉
----SCN:system_change_number
select dbms_flashback.get_system_change_number from dual;
select dbms_flashback.get_system_change_number scnno,
SCN_TO_TIMESTAMP(dbms_flashback.get_system_change_number) time
from dual;---時間與SCN對應的關係
select current_scn from v$database;
select timestamp_to_scn(SYSTIMESTAMP) as scn from dual;---轉換
--在控制檔案中
(1)SYSTEM CHECKPOINT SCN
select checkpoint_change# from v$database; --1054470322784儲存在控制檔案中
(2)Datafile checkpoint SCN
select file#,name,checkpoint_change# from v$datafile;
(3)Stop SCN(END SCN)
select file#,name,last_change# from v$datafile;
alter tablespace users read only;
alter tablespace users read write;
--一個在資料檔案頭內:
4) StartSCN
SELECT FILE#, NAME, checkpoint_change#, STATUS, TABLESPACE_NAME FROM V$DATAFILE_HEADER;
系統檢查點和資料檔案檢查點不一致時,則會啟動SMON程式,進行資料庫恢復.
stop scn 是最後一次修改scn號
select checkpoint_change#,last_change# from v$datafile;
shutdown abort
startup mount ----會在last_change中記錄SCN值
SQL> shutdown abort
ORACLE 例程已經關閉。
SQL> startup mount
ORACLE 例程已經啟動。
Total System Global Area 1703624704 bytes
Fixed Size 2255864 bytes
Variable Size 1275069448 bytes
Database Buffers 419430400 bytes
Redo Buffers 6868992 bytes
資料庫裝載完畢。
SQL> select checkpoint_change#,last_change# from v$datafile;
CHECKPOINT_CHANGE# LAST_CHANGE#
------------------ ---------------
1054471237178 1054471237178
1054471237178 1054471237178
1054471237178 1054471237178
1054471237178 1054471237178
1054471237178 1054471237178
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1054471237178
SQL> alter database open;
資料庫已更改。
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1054471237181
SQL> select checkpoint_change#,last_change# from v$datafile;
CHECKPOINT_CHANGE# LAST_CHANGE#
------------------ ---------------
1054471237181
1054471237181
1054471237181
1054471237181
1054471237181
SQL> alter system checkpoint
2 /
系統已更改。
SQL> shutdown abort
ORACLE 例程已經關閉。
SQL> startup mount
ORACLE 例程已經啟動。
Total System Global Area 1703624704 bytes
Fixed Size 2255864 bytes
Variable Size 1275069448 bytes
Database Buffers 419430400 bytes
Redo Buffers 6868992 bytes
資料庫裝載完畢。
SQL> select checkpoint_change#,last_change# from v$datafile;
CHECKPOINT_CHANGE# LAST_CHANGE#
------------------ ---------------
1054471237709
1054471237709
1054471237709
1054471237709
1054471237709
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1054471237709
----------------------------------------------------------------------------
SQL> alter system checkpoint;
系統已更改。
SQL> shutdown immediate
資料庫已經關閉。
已經解除安裝資料庫。
ORACLE 例程已經關閉。
SQL> startup mount
ORACLE 例程已經啟動。
Total System Global Area 1703624704 bytes
Fixed Size 2255864 bytes
Variable Size 1275069448 bytes
Database Buffers 419430400 bytes
Redo Buffers 6868992 bytes
資料庫裝載完畢。
SQL> select checkpoint_change#,last_change# from v$datafile;
CHECKPOINT_CHANGE# LAST_CHANGE#
------------------ ---------------
1054471258835 1054471258835
1054471258835 1054471258835
1054471258835 1054471258835
1054471258835 1054471258835
1054471258835 1054471258835
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
1054471258835
-----------------所以當資料庫是正常關閉時,系統scn和資料檔案中的scn會保持一致,但是如果是不正常關閉,而且在資料庫open中有隊資料檔案進行寫,那麼會導致系統scn和檔案scn
-----------不一致,從而在再次open資料庫是會觸發smon程式進行前滾在回滾,使得資料庫恢復成一致狀態。
--檢查點的分類:
--第一種分法
--1.database checkpoint,資料庫級的檢查點: 會觸發的情況:
1)alter system checkpoint;
2) alter system switch logfile;
3) alter database begin backup;
4) 正常關閉例項shutdown(immediate,transcational,normal)
--2.表空間和資料檔案檢查點:會出發的情況:
1) alter tablespace ... read only
2) alter datafile .... shrink
3) alter tablespace .... offline;
4) alter tablespace.... begin backup
--第二種分類方法
1. 完全檢查點 :手動觸發的,和關閉資料庫時候發生的均為完全檢查點
2. 增量檢查點
--完全檢查點:
1》alter system checkpoint
2》正常關閉shutdown(immediate,transcational,normal)
------checkpiont的幾個概念
----RBA(Redo Byte Address)
當一個checkpoint事件發生的時候,checkpoint程式會記錄下當時所寫的重做日誌塊的地址即RBA,此時記錄的RBA被稱為checkpoint RBA。
Low RBA(LRBA), High RBA(HRBA)
RBA就是重做日誌塊(redo log block)的地址,相當與資料檔案中的ROWID,透過這個地址來定位重做日誌塊。
RBA由三個部分組成:
1.日誌檔案序列號(4位元組)
2.日誌檔案塊編號(4位元組)
3.重做日誌記錄在日誌塊中的起始偏移位元組數(2位元組)
LRBA
資料快取(buffer cache)中一個髒塊第一次被更新的時候產生的重做日誌記錄在重做日誌檔案中所對應的位置就稱為LRBA。
HRBA
資料快取(buffer cache)中一個髒塊最近一次(最後一次)被更新的時候產生的重做日誌記錄在重做日誌檔案中所對應的位置就稱為HRBA。
HRBA 最後一次變髒
LRBA 第一次變髒
--Buffer checkpoint Queues(BCQ)
前滾到最後的狀態,回滾到最後一次提交的狀態
Oracle將所有在資料快取中被修改的髒塊按照LRBA順序的組成一個checkpoint佇列,這個佇列主要記錄了buffer cache第一次發生變化的時間順序.
HRBA
--checkpoint RBA ( Target Rba )
當一個checkpoint事件發生的時候,checkpoint程式會記錄下當時所寫的重做日誌塊的地址即RBA,此時記錄的RBA被稱為checkpoint RBA。
--====================資料庫啟動與關閉
---
1) 第1步是NOMOUNT,讀取初始化引數(SPFILE或PFILE),初始化在SPFILE或PFILE裡設定的記憶體及程式,並知道了控制檔案的地址。
spfile
pfile
2) 第2步MOUNT就是要從控制檔案讀取物理檔案的結構
3) 但是MOUNT後的資料檔案,控制檔案也許資料不一致,有可能是異常關閉的,所以後續要做一個一致性檢查,這屬於第3步,資料庫OPEN
例項恢復:mount之後先前滾後回滾在開啟資料庫
介質恢復:需要DBA手動干預
alter database backup controlfile to trace as 'D:\control_file.txt';---將控制檔案備份成文字格式
---啟動方式
⊙ STARTUP FORCE
相當於SHUTDOWN ABORT + STARTUP
⊙ STARTUP RESTRICT 受限模式
select logins from v$instance;
⊙ STARTUP RECOVER--該命令相當於STARTUP MOUNT + RECOVER DATABASE
---關閉方式
1. shutdown abort
---no allow new connections,no wait until current sessions end,no until current transactiona end ,no force a checkpoint and close files
2. shutdown immediate---不用等待事務完成,也不用等待使用者退出,
? 檢查點,寫髒資料到資料檔案,
? 回滾沒有提交的事務
? 釋放相關資源
? 不需要做例項恢復
---no allow new connections,no wait until current sessions end,no until current transactiona end , yes force a checkpoint and close files
3. shutdown transactional
---no allow new connections,yes wait until current sessions end,yes until current transactiona end ,yes force a checkpoint and close files
4. shutdown normal
---no allow new connections,no wait until current sessions end,yes until current transactiona end ,yes force a checkpoint and close files
shutdown immediate
startup nomount---後臺程式伺服器程式都已啟動,會啟動instance和後臺程式
alter database mount;---mount只是get the name of the datafiles and redo log files.
alter database open;----此時才能檢視資料庫中的檔案
startup restrict
select * from user_sys_privs where PRIVILEGE='RESTRICTED SESSION';
alter system disable restricted session;
select logins from v$instance;
alter system enable restricted session; ----可以將資料庫改成受限模式
--How a Database Is Mounted
The instance mounts a database to associate the database with that instance.
To mount the database, the instance finds the database control files and opens them.
Control files are specified in the CONTROL_FILES initialization parameter in the parameter file used
to start the instance. Oracle then reads the control files to get the names of the database's datafiles and redo log files.'
---Restricted Mode of Instance Startupaaa
You can start an instance in restricted mode (or later alter an existing instance to be in restricted mode).
This restricts connections to only those users who have been granted the RESTRICTED SESSION system privilege.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30018455/viewspace-1415560/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle啟動與關閉Oracle
- Oracle RAC 啟動與關閉Oracle
- Oracle 10g RAC 啟動與關閉Oracle 10g
- Oracle單例項+ASM啟動與關閉Oracle單例ASM
- Oracle資料庫的啟動與關閉Oracle資料庫
- ORACLE DataGuard 關閉啟動Oracle
- ORACLE啟動模式及關閉Oracle模式
- mysql啟動與關閉(手動與自動)MySql
- SHELL指令碼實現Oracle自啟動與關閉指令碼Oracle
- 啟動/關閉與冷備份Oracle資料庫Oracle資料庫
- Oracle 11gR2 RAC叢集服務啟動與關閉總結Oracle
- Hadoop 2.7.4 關閉與啟動Hadoop
- Oracle9i / 10g RAC 啟動與關閉Oracle
- Oracle監聽啟動後自動關閉Oracle
- oracle自動啟動和關閉的方法Oracle
- MySQL啟動和關閉命令總結MySql
- Oracle體系結構梳理Oracle
- 開啟與關閉oracle的歸檔Oracle
- Oracle11g RAC啟動關閉情況大概總結Oracle
- Oracle例項的啟動和關閉Oracle
- oracle 啟動 關閉步驟詳解Oracle
- oracle資料庫的啟動關閉與各種服務Oracle資料庫
- Oracle cloud control 12c 的啟動與關閉OracleCloud
- oracle資料庫的啟動與關閉過程詳解Oracle資料庫
- Oracle自動啟動和關閉的方法 (轉)Oracle
- 【體系結構】與Checkpoint相關的問題解決思路
- 2 Day DBA-管理Oracle例項-關閉和啟動Oracle例項-使用OEMDC關閉和啟動Oracle例項Oracle
- Oracle回收站功能開啟與關閉Oracle
- Oracle DG主備啟動關閉順序Oracle
- Oracle DG主備啟動和關閉流程Oracle
- oracle 例項啟動和關閉解讀Oracle
- oracle啟動和關閉指令碼for LinuxOracle指令碼Linux
- Oracle資料庫的啟動和關閉Oracle資料庫
- ORACLE RAC 的啟動和關閉順序Oracle
- Oracle10g RAC 關閉及啟動Oracle
- oracle結構梳理---資料字典Oracle
- oracle 10g rac下啟動關閉與更改歸檔模式Oracle 10g模式
- RAC 資料庫的啟動與關閉資料庫