要了解數據庫的啟動和停止需要先了解“實例”()和“數據庫”()這兩個名詞的定義:
這兩個詞有時可以互換使用,不過二者的概念完全不同。實例和數據庫之間的關系是:數據庫可以由多個實例mount和open,而實例可以在任何時間點mount和open一個數據庫。
(SID)
SID是實例在服務器上的唯一名字,在UNIX和Linux機器上,用SID和 home值來創建共享內存的鍵值,即SID和 home指定一個實例,SID也是用來定位參數文件。
有了對以上概念的認識,下面來看數據庫的啟動和關閉過程。
1、實例和數據庫的啟動
啟動數據庫的方式有很多種,最簡單的啟動數據庫的方式是就是使用執行命令。
先來看官方給的圖:
從上圖可以看出庫從狀態到open狀態經歷以下階段:
1) 啟動實例oracle數據庫啟停步驟,不mount數據庫
實例被啟動,但還沒關聯數據庫,對應的命令是
for ain a - and, if not found, for a text(h the )
Reads the file to the of
the SGA based on the
the
Opens trace files and all to thein valid
2) 數據庫被mount
實例被啟動,打開數據庫的控制文件關聯一個數據庫。數據庫對用戶還是close狀態。對就的命令是alter mount;
To mount the , the the names of the files in and opens the files. reads the files to find the names of the data files and the redo log files that it will to when the .
In a, the is and only to . can keep the while . , the is not for .
3) 數據庫被open
實例被啟動,關聯的數據庫被open。數據庫中的數據可以被用戶訪問。對應的命令是alter open。
2、實例和數據庫的關閉
通常關閉數據庫使用執行命令
再看官方給的圖:
從上圖中也可以看出從數據庫open狀態到狀態也經歷三個階段:
1) 數據庫被關閉
數據庫還是mount狀態,但在線數據文件和日志文件被關閉了。
The close is in a . The of the on the is or .
When a is as part of any other , data in the SGA to the data files and redo log files. Next, the data files and redo log files. Any data files of have been . When the , any that was .
At this stage, the is and for . The files open after a is .
If , then the of an open and shuts down the . does not write data in the of the SGA to the data files and redo log files. The of the , which .
2) 數據庫被
實例是啟動的,但不再通過控制文件關聯數據庫。
After the is , the to it from the . After a is , the files of the . At this point, the in .
3) 實例被
實例被。
The final step in is down the . When the is shut down, the SGA is from and the are .
數據庫關閉的4種模式:ABORT、、、。下面的表格介紹了各模式下數據庫的行為。
L
new user
No
No
No
No
Waits until end
No
No
No
Yes
Waits until end
No
No
Yes
Yes
aand open files
No
Yes
Yes
Yes
下面通過實例演示數據庫的啟動和關閉過程,例子中版本為11.2.0.1
1、啟動數據庫
當前沒有任何進程和共享內存,設置好和環境變量
執行 / as 連接到一個空實例,當前仍然沒有共享內存,只增加了一個進程的進程
使用 啟動數據庫實例,該命令默認查找參數文件啟動實例,也可以使用 pfile='/dir/init.ora'指定參數文件啟動,在內存中分配共享內存并創建后臺進程。
查看當前的實例狀態,當前狀態只能查少量的視圖如v$,但大部分視圖無法查詢如v$、v$,會報錯:ORA-01507: not
使用alter mount命令mount數據庫,這種狀態只能查詢部分視圖oracle數據庫啟停步驟,dba開頭的大部分視圖都不能查詢會報錯:ORA-01219: not open: on fixed /views only
使用alter open命令open數據庫:
當前數據庫被打開,可以對外提供服務。
2、關閉數據庫
整個啟動和關閉的過程都會記錄在alert日志文件中。11g的alert日志目錄是$/diag/rdbms//sid/trace。文件名為.log。
參考:
《編程藝術 深入數據庫體系結構》