oracle 啟動三步驟
oracle啟動會經過三個過程,分别是nomount、mount、open
一、nomount 階段
nomount 階段,可以看到執行個體已經啟動。oracle程序會根據參數檔案開創共享記憶體池。
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
SQL>
可以看到共享記憶體已經開辟
[[email protected] dbs]# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 98304 oracle 600 393216 2 dest
0x00000000 131073 oracle 600 393216 2 dest
0x00000000 163842 oracle 600 393216 2 dest
0x00000000 196611 oracle 600 393216 2 dest
0x00000000 229380 oracle 600 393216 2 dest
0x00000000 262149 oracle 600 393216 2 dest
0x00000000 294918 oracle 600 393216 2 dest
0x00000000 327687 oracle 600 393216 2 dest
0x00000000 360456 oracle 600 393216 2 dest
0x33554094 1048585 oracle 660 4096 0
0x00000000 425994 oracle 600 393216 2 dest
0x00000000 458763 oracle 600 393216 2 dest
0x00000000 491532 oracle 600 393216 2 dest
0x00000000 524301 oracle 600 393216 2 dest
0x00000000 557070 oracle 600 393216 2 dest
0x00000000 688143 oracle 600 393216 2 dest
0x00000000 720912 oracle 600 393216 2 dest
程序已經開啟
oracle 2965 1 0 04:44 ? 00:00:00 ora_pmon_test
oracle 2967 1 0 04:44 ? 00:00:00 ora_vktm_test
oracle 2971 1 0 04:44 ? 00:00:00 ora_gen0_test
oracle 2973 1 0 04:44 ? 00:00:00 ora_diag_test
oracle 2975 1 0 04:44 ? 00:00:00 ora_dbrm_test
oracle 2977 1 0 04:44 ? 00:00:00 ora_psp0_test
oracle 2979 1 0 04:44 ? 00:00:00 ora_dia0_test
oracle 2981 1 0 04:44 ? 00:00:01 ora_mman_test
oracle 2983 1 0 04:44 ? 00:00:00 ora_dbw0_test
oracle 2985 1 0 04:44 ? 00:00:00 ora_lgwr_test
oracle 2987 1 0 04:44 ? 00:00:00 ora_ckpt_test
oracle 2989 1 0 04:44 ? 00:00:00 ora_smon_test
oracle 2991 1 0 04:44 ? 00:00:00 ora_reco_test
oracle 2993 1 0 04:44 ? 00:00:00 ora_mmon_test
oracle 2995 1 0 04:44 ? 00:00:00 ora_mmnl_test
oracle 2997 1 0 04:44 ? 00:00:00 ora_d000_test
oracle 2999 1 0 04:44 ? 00:00:00 ora_s000_test
檢視參數配置檔案位置
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
spfile string /u01/app/oracle/product/11.2.4
/db_1/dbs/spfiletest.ora
SQL>
移除配置檔案後startup nomount,報錯如下:
SQL> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file ‘/u01/app/oracle/product/11.2.4/db_1/dbs/inittest.ora‘
SQL>
二、mount 階段
mount階段,oracle會根據nomount階段的參數檔案來尋找控制檔案的名稱和位置,一旦查找到立即鎖定該控制檔案,控制檔案裡記錄了資料庫中的資料檔案、日志檔案、檢查點資訊等非常重要的資訊。啟動mount時,會先自動啟動nomount
startup mount
mount階段可以看到,比nomount階段多了一個database mounted的提示。
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
SQL>
檢視控制檔案位置
SQL> show parameter control
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
control_file_record_keep_time integer 7
control_files string /u01/app/oracle/oradata/test/c
ontrol01.ctl, /u01/app/oracle/
flash_recovery_area/test/contr
ol02.ctl
control_management_pack_access string DIAGNOSTIC+TUNING
SQL>
将配置檔案移除,然後在啟動一次。
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
ORA-00205: error in identifying control file, check alert log for more info
SQL>
三、open階段
open階段會根據控制檔案記錄的資訊,定位到資料庫檔案、日志檔案等,正式開啟執行個體和資料庫之間的橋梁。如果資料檔案或者日志檔案缺少,那麼open失敗。
open之後,如果有使用歸檔日志功能,便可看到歸檔日志的程序。
SQL> alter database open;
Database altered.
SQL>
檢視日志檔案和日志檔案的位置
SQL> select file_name from dba_data_files;
FILE_NAME
------------------------------------------------
/u01/app/oracle/oradata/test/users01.dbf
/u01/app/oracle/oradata/test/undotbs01.dbf
/u01/app/oracle/oradata/test/sysaux01.dbf
/u01/app/oracle/oradata/test/system01.dbf
SQL>
SQL> select group#,member from v$logfile;
GROUP# MEMBER
-------------------------------------
3 /u01/app/oracle/oradata/test/redo03.log
2 /u01/app/oracle/oradata/test/redo02.log
1 /u01/app/oracle/oradata/test/redo01.log
移動一個資料檔案後啟動,報錯如下
SQL> startup;
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: ‘/u01/app/oracle/oradata/test/users01.dbf‘
SQL>
如果我随便複制一個檔案進去可不可以呢?啟動如下:
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 4 failed verification check
ORA-01110: data file 4: ‘/u01/app/oracle/oradata/test/users01.dbf‘
ORA-01210: data file header is media corrupt
總結
我們可以使用statup來啟動oracle資料庫,也可以用shutdwon來關閉。如果使用startup啟動,其實已經經過了三個過程。
總的來說,沒有參數檔案,執行個體無法建立,資料庫無法nomount成功,沒有配置檔案,資料庫無法mount;沒有資料檔案,資料庫無法打開使用。