要檢查 Oracle DB 是否啟動與運作,可以照下列程序檢查,若能夠通過檢查,就表示Oracle正常運作。
這個程序在HP-UX 11.11 & Oracle 9.2 上測試過
1. Check Oracle process
檢查作業系統是否有Oracle的process,而且對應的DB SID出現於結果中,表示該Oracle instance應該是執行中。例如主機內現有兩個Oracle instance執行中,其中一個SID一個是ADEV,另一個DB的SID為ATEST,檢查結果就會看到兩個對應的process存在。
Example:
# ps -ef | grep dbw
oracle 2401 1 0 Oct 19 ? 2:31 ora_dbw0_ADEV
oracle 2464 1 0 Oct 19 ? 2:38 ora_dbw0_ATEST
2. Check OPEN_MODE of Oracle instance
切換使用者帳號為 oracle,指定instance並使用sqlplus登入Oracle,查詢該instance的OPEN_MODE,應出現READ WRITE的字眼(除非有特殊需求,通常Oracle是起在READ WRITE模式的,這樣才能正常讀寫囉~)。
Example:
# su – oracle
# export ORACLE_SID=ADEV
# sqlplus “/as sysdba”
SQL> desc v$database
SQL> select name from v$database;
SQL> select open_mode from v$database;
OPEN_MODE
——————–
READ WRITE
3. Check STATUS of Oracle instance
切換使用者帳號為 oracle,指定instance並使用sqlplus登入Oracle,查詢該instance的STATUS,應出現OPEN的字眼,若出現其他字眼,則Oracle可能沒有正常啟動。
Example:
# su – oracle
# export ORACLE_SID=ADEV
# sqlplus “/as sysdba”
SQL> desc v$instance;
SQL> select status from v$instance;
STATUS
————
OPEN
4. Check LISTENER
4.1 檢查作業系統中 LISTENER 的process是否已經啟動。
Oracle instance共用LISTENER的狀況,通常會將LISTENER直接取名為LISTNER,可以看到如下的process。
Example:
# ps -ef | grep lsnr
oracle 21327 1 3 00:42:33 ? 4:34 /oracle/product/9.2/bin/tnslsnr LISTENER -inherit
OR
Oracle instance各自獨立使用LISTENER的狀況,通常LISTENER名稱會跟SID相關連,以方便辨識。
Example:
# ps -ef | grep lsnr
oracle 1609 1 0 Sep 12 ? 15:54 /oracle/product/9.2/bin/tnslsnr LISTENER_ADEV -inherit
oracle 27399 1 0 Oct 12 ? 8:45 /oracle/product/9.2/bin/tnslsnr LISTENER_ATEST -inherit
4.2 檢查LISTENER的設定值
Oracle instance共用LISTENER的狀況,通常會將LISTENER直接取名為LISTNER,在設定檔中會把兩個instance的設定包在一起。
Example:
# cat /oracle/product/9.2/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = ADEV))
(ADDRESS = (PROTOCOL = IPC)(KEY = ATEST))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test01)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ADEV)
(ORACLE_HOME = /oracle/product/9.2)
(SID_NAME = ADEV)
)
(SID_DESC =
(GLOBAL_DBNAME = ATEST)
(ORACLE_HOME = /oracle/product/9.2)
(SID_NAME = ATLTEST)
)
)
OR
Oracle instance各自獨立使用LISTENER的狀況,LISTENER設定檔中就會將兩個LISTENER分開,以方便辨識。
Example:
# cat /oracle/product/9.2/network/admin/listener.ora
LISTENER_ADEV =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test01)(PORT = 1521))
)
)
)
SID_LIST_LISTENER_ADEV =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ADEV)
(ORACLE_HOME = /oracle/product/9.2)
(SID_NAME = ADEV)
)
)
LISTENER_ATEST =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test01)(PORT = 1522))
)
)
)
SID_LIST_LISTENER_ATEST =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ATEST)
(ORACLE_HOME = /oracle/product/9.2)
(SID_NAME = ATEST)
)
)
5. Use tnsping
使用Oracle提供的tnsping工具,可以檢查DB的連線狀況,如果最後顯示OK,並顯示極短的時間,如OK( 0 msec ),表示應該沒問題可以連接~
Example:
# su – oracle
# tnsping ADEV
TNS Ping Utility for HPUX: Version 9.2.0.0.0 – Production on 02-NOV-2010 09:54:11
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
/oracle/product/9.2/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = ADEV))) (CONNECT_DATA = (SID = ADEV) (PRESENTATION = RO)))
OK (0 msec)