單純 ping 或 ps -ef | grep oracle 無法確認資料庫真正可用。完整檢測需包含:
#!/bin/ksh
. /u01/home/oracle/.profile
/u01/app/oracle/admin/monitororcl \
'cat /u01/app/oracle/admin/Get_Oracle_Instance_List'
exit
# 格式: instance_name tnsname sys_password
instance_name1 tnsname1 sys_password_for_this_instance
instance_name2 tnsname2 sys_password_for_this_instance
instance_name3 tnsname3 sys_password_for_this_instance
腳本對每個實例執行:
tnsping <tnsname> 驗證 Listener;sqlplus -s sys/<pwd>@<tnsname> AS SYSDBA 執行:
SELECT 1 FROM DUAL; 驗證登入與基本查詢;SELECT tablespace_name, SUM(bytes)/1024/1024 AS total_mb, SUM(maxbytes)/1024/1024 AS max_mb, (SUM(maxbytes)-SUM(bytes))/1024/1024 AS free_mb FROM dba_data_files GROUP BY tablespace_name; 檢查表空間容量;v$instance 狀態、v$recovery_file_dest 歸檔區使用率。UTL_SMTP 或外部 mailx)。建立「Listener → 登入驗證 → 核心查詢 → 表空間/歸檔空間」四層檢測體系,配合排程自動執行與異常通知,才能真正掌握 Oracle 可用性與容量健康度,避免業務中斷。