oracle集群巡检脚本
时间: 2023-07-12 20:21:41 浏览: 136
Oracle巡检脚本.pdf
以下是一个 Oracle RAC 集群巡检脚本的示例,您可以根据自己的需要进行修改和调整:
```bash
#!/bin/bash
# Author: Your Name
# Date: 2021-06-01
# Description: A script to perform Oracle RAC cluster health check
# Define variables
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
GRID_HOME=/u01/app/11.2.0/grid
LOG_FILE=/var/log/oracle/check.log
DATE=$(date '+%Y-%m-%d %H:%M:%S')
# Define functions
function check_asm_diskgroup {
$GRID_HOME/bin/asmcmd lsdg | grep --quiet '+DATA'
if [ $? -ne 0 ]; then
echo "$DATE ERROR: +DATA diskgroup not found" >> $LOG_FILE
return 1
fi
return 0
}
function check_asm_listener {
$GRID_HOME/bin/lsnrctl status LISTENER_ASM | grep --quiet 'Instance "ASM", status READY'
if [ $? -ne 0 ]; then
echo "$DATE ERROR: ASM listener not running" >> $LOG_FILE
return 1
fi
return 0
}
function check_database_listener {
$ORACLE_HOME/bin/lsnrctl status LISTENER | grep --quiet 'Instance ".*", status READY'
if [ $? -ne 0 ]; then
echo "$DATE ERROR: Database listener not running" >> $LOG_FILE
return 1
fi
return 0
}
function check_database_status {
$ORACLE_HOME/bin/sqlplus -S / as sysdba << EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT STATUS FROM V\\$INSTANCE;
EXIT;
EOF
if [ $? -ne 0 ]; then
echo "$DATE ERROR: Failed to connect to database" >> $LOG_FILE
return 1
fi
return 0
}
# Main script
echo "$DATE Starting Oracle RAC cluster health check" >> $LOG_FILE
check_asm_diskgroup && echo "$DATE +DATA diskgroup found" >> $LOG_FILE
check_asm_listener && echo "$DATE ASM listener running" >> $LOG_FILE
check_database_listener && echo "$DATE Database listener running" >> $LOG_FILE
check_database_status && echo "$DATE Database status is OK" >> $LOG_FILE
echo "$DATE Oracle RAC cluster health check completed" >> $LOG_FILE
```
此脚本使用了多个 Oracle 命令来检查各个组件的运行状态,包括 ASM 磁盘组、ASM 监听器、数据库监听器和数据库本身。脚本输出会写入日志文件中,您可以根据需要将其添加到定时任务中进行定期检查。
阅读全文