濮阳杆衣贸易有限公司

主頁 > 知識庫 > oracle 數(shù)據(jù)庫啟動階段分析

oracle 數(shù)據(jù)庫啟動階段分析

熱門標(biāo)簽:400電話是不是免費申請 安陽外呼系統(tǒng)免費 貴陽電話外呼系統(tǒng)哪家好 濟南地圖標(biāo)注公司 南寧人工智能電銷機器人費用 海南400電話哪里辦理 呼倫貝爾智能手機地圖標(biāo)注 圖像地圖標(biāo)注 分布式呼叫中心

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

數(shù)據(jù)庫的啟動

首先來分析一下數(shù)據(jù)庫的啟動過程,Oracle 數(shù)據(jù)庫的啟動主要包含 3 個步驟:

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

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

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

下面逐個來看看各個步驟的具體過程以其含義。

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

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

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

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

[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ū)域,啟 動了相應(yīng)的后臺進程。 此時觀察警報日志文件(alert_sid>.log ; show parameter dump查看路徑),可以看到這一階段的啟動過程,讀取參數(shù) 文件,應(yīng)用參數(shù)啟動實例,所有在參數(shù)文件中定義的非缺省參數(shù)都會記錄在警報日志文件中:

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"

然后后臺進程依次啟動:

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文件作為啟動參數(shù)文件;如果該文件不 存在,Oracle選擇spfile.ora 文件;如果前兩者都不存在,Oracle將會選擇 initsid>.ora文件;如果以上 3 個文件都不存在,Oracle 將無法創(chuàng)建和啟動 instance ,Oracle將無法啟動。

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

SQL> show parameter spfile

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

這時候也可以從操作系統(tǒng)查看啟動了的后臺進:

[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 個文件都不存在,Oracle 將無法啟動:

[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整個啟動過程中,參數(shù)文件是寫在應(yīng)用程序中的硬代碼,按照如上順序進行查 找,不能改變Oracle的搜索路徑及行為,但是如果參數(shù)文件不在相應(yīng)的位置,在Linux/UNIX 系統(tǒng)上,可以通過符號鏈接來進行重定位。

在參數(shù)文件中,通常需要最少的參數(shù)是 db_name,設(shè)置了這個參數(shù)之后,數(shù)據(jù)庫實例就可以啟動,來看一個簡單的測試:

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

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

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

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

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視圖,獲得控制文件信息,這部分信息來自啟 動的參數(shù)文件;當(dāng)數(shù)據(jù)庫 mount 之后,可以查詢 v$controlfile視圖獲得關(guān)于控制文件的信 息,此時,這部分信息來自控制文件:

[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ù)庫的過程中,Oracle需要找到控制文件并鎖定控制文件。如果控制文件全 部丟失此時就會報出如下錯誤:

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

這時候alert.log 文件中通常會記錄更為詳細的信息。

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

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

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ù)庫需要計算Mount id 并將其記錄在控制文件中,然后開始啟動 Heartbeat(心跳),每3 秒更新一次控制文件。

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

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

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

如果口令文件丟失,通過 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 平臺下,在$ORACLE_HOME/dbs 目錄下,還會存在另外一個文件,該文件命名規(guī)則為 lkSID>,lk指lock ,該文件在數(shù)據(jù)庫啟動時創(chuàng)建,用于操作系統(tǒng)對數(shù)據(jù)庫的鎖定。當(dāng)數(shù)據(jù)庫啟動時獲得鎖定,數(shù)據(jù)庫關(guān)閉時釋放。該文件內(nèi)容通常只有一行,提示不要刪除,該文件僅僅用于鎖定.

3. 啟動數(shù)據(jù)庫open階段

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

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

進一步地說,實際上在數(shù)據(jù)庫 open的過程中,Oracle 進行的檢查中包括以下兩項:

第一次檢查數(shù)據(jù)文件頭中的檢查點計數(shù)(Checkpoint cnt )是否和控制文件中的檢查點 計數(shù)(Checkpoint cnt )一致。此步驟檢查用以確認數(shù)據(jù)文件是來自同一版本,而不是從備 份中恢復(fù)而來(因為 Checkpoint Cnt 不會被凍結(jié),會一直被修改)。 下面通過一個簡單的測試來說明一下 Checkpoint Cnt的作用。

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

總結(jié)

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

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

標(biāo)簽:滁州 涼山 許昌 遼源 郴州 焦作 合肥 南充

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle 數(shù)據(jù)庫啟動階段分析》,本文關(guān)鍵詞  oracle,數(shù)據(jù)庫,啟動,階段,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《oracle 數(shù)據(jù)庫啟動階段分析》相關(guān)的同類信息!
  • 本頁收集關(guān)于oracle 數(shù)據(jù)庫啟動階段分析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    项城市| 长兴县| 通化市| 汝阳县| 浙江省| 延边| 巴塘县| 玉溪市| 梁山县| 信阳市| 漠河县| 连山| 茂名市| 丰台区| 壤塘县| 禄劝| 宝清县| 文成县| 东兰县| 富平县| 西和县| 谢通门县| 平泉县| 临沧市| 彰化县| 温宿县| 永平县| 恩施市| 巧家县| 合川市| 永泰县| 临桂县| 抚顺市| 安宁市| 阳信县| 隆化县| 高州市| 辉南县| 莱芜市| 湘潭市| 荣成市|