佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > oracle 數(shù)據(jù)庫(kù)啟動(dòng)階段分析

oracle 數(shù)據(jù)庫(kù)啟動(dòng)階段分析

熱門標(biāo)簽:網(wǎng)站排名優(yōu)化 百度競(jìng)價(jià)排名 服務(wù)外包 AI電銷 Linux服務(wù)器 地方門戶網(wǎng)站 鐵路電話系統(tǒng) 呼叫中心市場(chǎng)需求

Oracle Server主要由兩部分組成:Instance 和Database 。Instance 是指一組后臺(tái)進(jìn)程/線程和一塊共享內(nèi)存區(qū)域,而 Database是指存儲(chǔ)在磁盤上的一組物理文件。本文由數(shù)據(jù)庫(kù) 如何啟動(dòng)入手。

數(shù)據(jù)庫(kù)的啟動(dòng)

首先來(lái)分析一下數(shù)據(jù)庫(kù)的啟動(dòng)過(guò)程,Oracle 數(shù)據(jù)庫(kù)的啟動(dòng)主要包含 3 個(gè)步驟:

(1)啟動(dòng)數(shù)據(jù)庫(kù)到 nomount 狀態(tài);

(2)啟動(dòng)數(shù)據(jù)庫(kù)到 mount 狀態(tài);

(3)啟動(dòng)數(shù)據(jù)庫(kù)到 open 狀態(tài)。

下面逐個(gè)來(lái)看看各個(gè)步驟的具體過(guò)程以其含義。

1. 啟動(dòng)數(shù)據(jù)庫(kù)到nomount 狀態(tài)

在啟動(dòng)的第一步驟,Oracle 首先尋找參數(shù)文件(pfile/spfile ),然后根據(jù)參數(shù)文件中 的設(shè)置,創(chuàng)建實(shí)例,分配內(nèi)存,啟動(dòng)后臺(tái)進(jìn)程。

在這里可以看到,只要擁有了一個(gè)參數(shù)文件,就可以憑之啟動(dòng)實(shí)例(Instance), 這一步 驟并不需要任何控制文件或數(shù)據(jù)文件的參與。

在創(chuàng)建數(shù)據(jù)庫(kù)時(shí),如果在這一步驟就出現(xiàn)問題,那么通??赡苁窍到y(tǒng)配置(內(nèi)核參數(shù)等)存在問題,用戶需要檢查是否分配了足夠的系統(tǒng)資源等。 來(lái)看一下啟動(dòng)到 nomount 狀態(tài)的過(guò)程:

[oracle@dbtest dbs]$ cd $ORACLE_HOME/dbs
[oracle@dbtest dbs]$ ls
hc_orcl.dat init.ora initorcl.ora lkORCL orapworcl spfileorcl.ora
[oracle@dbtest dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed May 4 10:36:45 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size         2212696 bytes
Variable Size       922750120 bytes
Database Buffers     218103808 bytes
Redo Buffers        9383936 bytes
SQL>

注意這里,Oracle 根據(jù)參數(shù)文件的內(nèi)容,創(chuàng)建了 instance ,分配了相應(yīng)的內(nèi)存區(qū)域,啟 動(dòng)了相應(yīng)的后臺(tái)進(jìn)程。 此時(shí)觀察警報(bào)日志文件(alert_sid>.log ; show parameter dump查看路徑),可以看到這一階段的啟動(dòng)過(guò)程,讀取參數(shù) 文件,應(yīng)用參數(shù)啟動(dòng)實(shí)例,所有在參數(shù)文件中定義的非缺省參數(shù)都會(huì)記錄在警報(bào)日志文件中:

Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options.
Using parameter settings in server-side spfile /u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
System parameters with non-default values:
 processes        = 150
 sga_target        = 176M
 memory_target      = 1104M
 memory_max_target    = 1104M
 control_files      = "/u01/app/oracle/oradata/orcl/control01.ctl"
 control_files      = "/u01/app/oracle/flash_recovery_area/orcl/control02.ctl"
 db_block_size      = 8192
 compatible        = "11.2.0.0.0"
 db_recovery_file_dest  = "/u01/app/oracle/flash_recovery_area"
 db_recovery_file_dest_size= 3882M
 undo_tablespace     = "UNDOTBS1"
 remote_login_passwordfile= "EXCLUSIVE"
 db_domain        = "oracle.com"
 global_names       = FALSE
 dispatchers       = "(PROTOCOL=TCP) (SERVICE=orclXDB)"
 shared_servers      = 5
 audit_file_dest     = "/u01/app/oracle/admin/orcl/adump"
 audit_trail       = "DB"
 db_name         = "orcl"
 open_cursors       = 300
 diagnostic_dest     = "/u01/app/oracle"

然后后臺(tái)進(jìn)程依次啟動(dòng):

Wed May 04 10:36:55 2016
PMON started with pid=2, OS id=3128 
Wed May 04 10:36:55 2016
VKTM started with pid=3, OS id=3132 at elevated priority
VKTM running at (10)millisec precision with DBRM quantum (100)ms
Wed May 04 10:36:55 2016
GEN0 started with pid=4, OS id=3138 
Wed May 04 10:36:55 2016
DIAG started with pid=5, OS id=3142 
Wed May 04 10:36:55 2016
DBRM started with pid=6, OS id=3146 
Wed May 04 10:36:55 2016
PSP0 started with pid=7, OS id=3150 
Wed May 04 10:36:55 2016
DIA0 started with pid=8, OS id=3158 
Wed May 04 10:36:55 2016
MMAN started with pid=9, OS id=3162 
Wed May 04 10:36:55 2016
DBW0 started with pid=10, OS id=3166 
Wed May 04 10:36:55 2016
LGWR started with pid=11, OS id=3170 
Wed May 04 10:36:55 2016
CKPT started with pid=12, OS id=3175 
Wed May 04 10:36:55 2016
SMON started with pid=13, OS id=3179 
Wed May 04 10:36:55 2016
RECO started with pid=14, OS id=3184 
Wed May 04 10:36:55 2016
MMON started with pid=15, OS id=3189 
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
Wed May 04 10:36:55 2016
MMNL started with pid=16, OS id=3193 
starting up 5 shared server(s) ...
ORACLE_BASE from environment = /u01/app/oracle

這里注意一下 Oracle選擇參數(shù)文件的順序:

Oracle 首選spfilesid>.ora文件作為啟動(dòng)參數(shù)文件;如果該文件不 存在,Oracle選擇spfile.ora 文件;如果前兩者都不存在,Oracle將會(huì)選擇 initsid>.ora文件;如果以上 3 個(gè)文件都不存在,Oracle 將無(wú)法創(chuàng)建和啟動(dòng) instance ,Oracle將無(wú)法啟動(dòng)。

用戶可以在SQL*PLUS 中通過(guò)show parameter spfile 命令來(lái)檢查數(shù)據(jù)庫(kù)是否使用了 spfile文件,如果 value 不為Null,則數(shù)據(jù)庫(kù)使用了 spfile文件:

SQL> show parameter spfile

NAME                 TYPE    VALUE
------------------------------------ ----------- ------------------------------
spfile                string   /u01/app/oracle/product/11.2.0
                         /db_1/dbs/spfileorcl.ora
SQL>

這時(shí)候也可以從操作系統(tǒng)查看啟動(dòng)了的后臺(tái)進(jìn):

[root@dbtest trace]# ps -ef|grep ora_ 
oracle  3128   1 0 10:36 ?    00:00:00 ora_pmon_orcl
oracle  3132   1 0 10:36 ?    00:00:00 ora_vktm_orcl
oracle  3138   1 0 10:36 ?    00:00:00 ora_gen0_orcl
oracle  3142   1 0 10:36 ?    00:00:00 ora_diag_orcl
oracle  3146   1 0 10:36 ?    00:00:00 ora_dbrm_orcl
oracle  3150   1 0 10:36 ?    00:00:00 ora_psp0_orcl
oracle  3158   1 0 10:36 ?    00:00:00 ora_dia0_orcl
oracle  3162   1 0 10:36 ?    00:00:00 ora_mman_orcl
oracle  3166   1 0 10:36 ?    00:00:00 ora_dbw0_orcl
oracle  3170   1 0 10:36 ?    00:00:00 ora_lgwr_orcl
oracle  3175   1 0 10:36 ?    00:00:00 ora_ckpt_orcl
oracle  3179   1 0 10:36 ?    00:00:00 ora_smon_orcl
oracle  3184   1 0 10:36 ?    00:00:00 ora_reco_orcl
oracle  3189   1 0 10:36 ?    00:00:00 ora_mmon_orcl
oracle  3193   1 0 10:36 ?    00:00:00 ora_mmnl_orcl
oracle  3197   1 0 10:36 ?    00:00:00 ora_d000_orcl
oracle  3201   1 0 10:36 ?    00:00:00 ora_s000_orcl
oracle  3205   1 0 10:36 ?    00:00:00 ora_s001_orcl
oracle  3209   1 0 10:36 ?    00:00:00 ora_s002_orcl
oracle  3213   1 0 10:36 ?    00:00:00 ora_s003_orcl
oracle  3217   1 0 10:36 ?    00:00:00 ora_s004_orcl
root   3358 3253 0 10:50 pts/3  00:00:00 grep ora_

如果這3 個(gè)文件都不存在,Oracle 將無(wú)法啟動(dòng):

[oracle@dbtest dbs]$ mv init.ora init.ora.bak
[oracle@dbtest dbs]$ mv initorcl.ora initorcl.ora.bak
[oracle@dbtest dbs]$ mv spfileorcl.ora spfileorcl.ora.bak
[oracle@dbtest dbs]$ ls
hc_orcl.dat init.ora.bak initorcl.ora.bak lkORCL orapworcl spfileorcl.ora.bak
[oracle@dbtest dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed May 4 10:55:42 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora'

在Oracle整個(gè)啟動(dòng)過(guò)程中,參數(shù)文件是寫在應(yīng)用程序中的硬代碼,按照如上順序進(jìn)行查 找,不能改變Oracle的搜索路徑及行為,但是如果參數(shù)文件不在相應(yīng)的位置,在Linux/UNIX 系統(tǒng)上,可以通過(guò)符號(hào)鏈接來(lái)進(jìn)行重定位。

在參數(shù)文件中,通常需要最少的參數(shù)是 db_name,設(shè)置了這個(gè)參數(shù)之后,數(shù)據(jù)庫(kù)實(shí)例就可以啟動(dòng),來(lái)看一個(gè)簡(jiǎn)單的測(cè)試:

SQL> ! echo "db_name=julia" > initorcl.ora
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 217157632 bytes
Fixed Size         2211928 bytes
Variable Size       159387560 bytes
Database Buffers      50331648 bytes
Redo Buffers        5226496 bytes

這樣,就通過(guò)了最少的參數(shù)需求啟動(dòng)了 Oracle實(shí)例。

2. 啟動(dòng)數(shù)據(jù)庫(kù)到mount 狀態(tài)

啟動(dòng)到nomount 狀態(tài)以后,Oracle就可以從參數(shù)文件中獲得控制文件的位置信息, 這一部分信息在參數(shù)文件中的記錄類似如下所示(Oracle缺省會(huì)創(chuàng)建3 個(gè)控制文件,這 3 個(gè)控制文件的內(nèi)容完全一致,是Oracle為了安全而采用的鏡像手段,在生產(chǎn)環(huán)境中,通 常應(yīng)該將3 個(gè)控制文件存放在不同的物理硬盤上,避免因?yàn)榻橘|(zhì)故障而同時(shí)損壞3 個(gè)控制 文件):

SQL> show parameter control_files

NAME                 TYPE    VALUE
------------------------------------ ----------- ------------------------------
control_files            string   /u01/app/oracle/product/11.2.0
                         /db_1/dbs/cntrlorcl.dbf

在nomount 狀態(tài),可以查詢v$parameter視圖,獲得控制文件信息,這部分信息來(lái)自啟 動(dòng)的參數(shù)文件;當(dāng)數(shù)據(jù)庫(kù) mount 之后,可以查詢 v$controlfile視圖獲得關(guān)于控制文件的信 息,此時(shí),這部分信息來(lái)自控制文件:

[oracle@dbtest dbs]$ mv init.ora.bak init.ora
[oracle@dbtest dbs]$ mv initorcl.ora.bak initorcl.ora
[oracle@dbtest dbs]$ mv spfileorcl.ora.bak spfileorcl.ora
[oracle@dbtest dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed May 4 11:07:07 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size         2212696 bytes
Variable Size       922750120 bytes
Database Buffers     218103808 bytes
Redo Buffers        9383936 bytes
SQL> alter database mount;  
Database altered.
SQL> select * from v$controlfile; 
STATUS
-------
NAME
--------------------------------------------------------------------------------
IS_ BLOCK_SIZE FILE_SIZE_BLKS
--- ---------- --------------
/u01/app/oracle/oradata/orcl/control01.ctl
NO    16384      594
/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
NO    16384      594
STATUS
-------
NAME
--------------------------------------------------------------------------------
IS_ BLOCK_SIZE FILE_SIZE_BLKS
--- ---------- --------------

在mount 數(shù)據(jù)庫(kù)的過(guò)程中,Oracle需要找到控制文件并鎖定控制文件。如果控制文件全 部丟失此時(shí)就會(huì)報(bào)出如下錯(cuò)誤:

SQL> alter database mount; 
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info

這時(shí)候alert.log 文件中通常會(huì)記錄更為詳細(xì)的信息。

因?yàn)镺racle的3 個(gè)(缺省的)控制文件內(nèi)容完全相同,如果只是損失了其中 1~2 個(gè), 可以復(fù)制完好的控制文件,更改為相應(yīng)的名稱,就可以啟動(dòng)數(shù)據(jù)庫(kù);如果丟失了所有的控制 文件,那么就需要恢復(fù)或重建控制文件來(lái)打開數(shù)據(jù)庫(kù)。

在正常Mount 數(shù)據(jù)庫(kù)的過(guò)程中,數(shù)據(jù)庫(kù)的警報(bào)日志文件僅記錄如下信息:

alter database mount
Wed May 04 11:07:44 2016
Successful mount of redo thread 1, with mount id 1438756220
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: alter database mount

在這一步驟中,數(shù)據(jù)庫(kù)需要計(jì)算Mount id 并將其記錄在控制文件中,然后開始啟動(dòng) Heartbeat(心跳),每3 秒更新一次控制文件。

啟動(dòng)到Mount 狀態(tài),數(shù)據(jù)庫(kù)必須具備的另外一個(gè)重要文件是口令文件,該文件位于 $ORACLE_HOME/dbs 目錄下,缺省的名稱為 orapw 。 口令文件中存放 sysdba/sysoper 用戶的用戶名及口令:

[oracle@dbtest dbs]$ strings orapworcl 
]\[Z
ORACLE Remote Password file
INTERNAL
769C0CD849F9B8B2
5638228DAF52805F
[oracle@dbtest dbs]$

在數(shù)據(jù)庫(kù)沒有啟動(dòng)之前,數(shù)據(jù)庫(kù)內(nèi)建用戶是無(wú)法通過(guò)數(shù)據(jù)庫(kù)本身來(lái)驗(yàn)證身份的,通過(guò)口 令文件,Oracle 可以實(shí)現(xiàn)對(duì)用戶的身份認(rèn)證,在數(shù)據(jù)庫(kù)未啟動(dòng)之前登錄,進(jìn)而啟動(dòng)數(shù)據(jù)庫(kù)。 對(duì)于口令文件,Oracle 缺省查找 orapw 文件,如果該文件不存在,則繼續(xù)查找orapw 文件,如果兩者都不存在,則數(shù)據(jù)庫(kù)將會(huì)出現(xiàn)錯(cuò)誤。

如果口令文件丟失,通過(guò) orapw 工具即可重建,所以在通常的備份策略中可以不必包含 口令文件:

[oracle@dbtest dbs]$ orapwd
Usage: orapwd file=fname> entries=users> force=y/n> ignorecase=y/n> nosysdba=y/n>

 where
	file - name of password file (required),
	password - password for SYS will be prompted if not specified at command line,
	entries - maximum number of distinct DBA (optional),
	force - whether to overwrite existing file (optional),
	ignorecase - passwords are case-insensitive (optional),
	nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).
	
 There must be no spaces around the equal-to (=) character.
[oracle@dbtest dbs]$

通常在Linux/UNIX 平臺(tái)下,在$ORACLE_HOME/dbs 目錄下,還會(huì)存在另外一個(gè)文件,該文件命名規(guī)則為 lkSID>,lk指lock ,該文件在數(shù)據(jù)庫(kù)啟動(dòng)時(shí)創(chuàng)建,用于操作系統(tǒng)對(duì)數(shù)據(jù)庫(kù)的鎖定。當(dāng)數(shù)據(jù)庫(kù)啟動(dòng)時(shí)獲得鎖定,數(shù)據(jù)庫(kù)關(guān)閉時(shí)釋放。該文件內(nèi)容通常只有一行,提示不要?jiǎng)h除,該文件僅僅用于鎖定.

3. 啟動(dòng)數(shù)據(jù)庫(kù)open階段

由于控制文件中記錄了數(shù)據(jù)庫(kù)中數(shù)據(jù)文件、日志文件的位置信息、檢查點(diǎn)信息等重要信 息,所以在數(shù)據(jù)庫(kù)的 open階段,Oracle可以根據(jù)控制文件中記錄的這些信息找到這些文件, 然后進(jìn)行檢查點(diǎn)及完整性檢查。

如果不存在問題就可以啟動(dòng)數(shù)據(jù)庫(kù),如果存在不一致或文件丟失則需要進(jìn)行恢復(fù)。

進(jìn)一步地說(shuō),實(shí)際上在數(shù)據(jù)庫(kù) open的過(guò)程中,Oracle 進(jìn)行的檢查中包括以下兩項(xiàng):

第一次檢查數(shù)據(jù)文件頭中的檢查點(diǎn)計(jì)數(shù)(Checkpoint cnt )是否和控制文件中的檢查點(diǎn) 計(jì)數(shù)(Checkpoint cnt )一致。此步驟檢查用以確認(rèn)數(shù)據(jù)文件是來(lái)自同一版本,而不是從備 份中恢復(fù)而來(lái)(因?yàn)?Checkpoint Cnt 不會(huì)被凍結(jié),會(huì)一直被修改)。 下面通過(guò)一個(gè)簡(jiǎn)單的測(cè)試來(lái)說(shuō)明一下 Checkpoint Cnt的作用。

如果檢查點(diǎn)計(jì)數(shù)檢查通過(guò),則數(shù)據(jù)庫(kù)進(jìn)行第二次檢查。第二次檢查數(shù)據(jù)文件頭的開始SCN 和控制文件中記錄的該文件的結(jié)束 SCN 是否一致,如果控制文件中記錄的結(jié)束 SCN 等于數(shù)據(jù) 文件頭的開始 SCN,則不需要對(duì)那個(gè)文件進(jìn)行恢復(fù)。

總結(jié)

以上就是本文關(guān)于oracle 數(shù)據(jù)庫(kù)啟動(dòng)階段分析的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以參閱:Oracle創(chuàng)建帶有參數(shù)的視圖代碼介紹 、 Oracle分頁(yè)查詢性能優(yōu)化代碼詳解 、 oracle 虛擬專用數(shù)據(jù)庫(kù)詳細(xì)介紹等,感謝大家對(duì)本站的支持。有什么問題可以隨時(shí)留言,小編會(huì)竭盡所能給您想要的答案。

您可能感興趣的文章:
  • Oracle 跨庫(kù) 查詢 復(fù)制表數(shù)據(jù) 分布式查詢介紹
  • oracle中通配符和運(yùn)算符的使用方法介紹
  • Oracle RMAN自動(dòng)備份控制文件方法介紹
  • Oracle EBS工具選項(xiàng):關(guān)閉其他表單修改方法
  • 淺談oracle rac和分布式數(shù)據(jù)庫(kù)的區(qū)別

標(biāo)簽:湘潭 蘭州 衡水 湖南 銅川 仙桃 黃山 崇左

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle 數(shù)據(jù)庫(kù)啟動(dòng)階段分析》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    岱山县| 南木林县| 阿瓦提县| 郑州市| 林西县| 长岛县| 南京市| 安国市| 丰城市| 徐州市| 噶尔县| 察隅县| 南京市| 松原市| 巴南区| 和静县| 宁阳县| 兴安盟| 长寿区| 县级市| 抚松县| 元谋县| 合江县| 普格县| 壶关县| 大石桥市| 南漳县| 开平市| 张北县| 将乐县| 杭锦旗| 松原市| 定襄县| 精河县| 读书| 内丘县| 青冈县| 开阳县| 伊宁市| 卓资县| 常宁市|