Database mode check
Standard Operating Procedure (SOP) for Database Read-Only Mode Validation Automation
---
1. Purpose
This SOP outlines the automated process for validating the OPEN_MODE of multiple Oracle databases using a predefined list. The script identifies databases that are not in READ ONLY mode and sends an email notification for further review.
---
2. Scope
Applies to Oracle databases running across multiple hosts.
Uses a common tnsnames.ora file for connectivity.
Executes SQL queries to check the database mode and uptime in that mode.
Notifies the DBA team if any database is not in READ ONLY mode.
---
3. Prerequisites
Ensure the Oracle environment variables are set correctly:
export TNS_ADMIN=/auto/your/tns/location
export ORACLE_HOME=/auto/your/oracle/home
export PATH=$ORACLE_HOME/bin:$PATH
A valid tnsnames.ora file containing the TNS entries for all databases.
A list of target databases stored in a file (db_list.txt).
A static username and password for database authentication.
---
4. Script Execution Workflow
Step 1: Read Database List
The script reads each database name from db_list.txt.
Step 2: Connect to Each Database
It establishes a SQL*Plus session using the format:
sqlplus -s "username/password@DB_NAME"
Retrieves the OPEN_MODE and calculates the number of days in the current mode.
Step 3: Validate Database Mode
The script checks if the database is in READ ONLY mode.
If not, it logs the entry and prepares an email notification.
Step 4: Generate Reports
Saves results in /tmp/database_mode.log.
Stores databases not in READ ONLY mode in /tmp/email_body.txt.
Step 5: Send Email Notification
If any database is not in READ ONLY mode, an email alert is sent to the DBA team.
---
5. Key Features
✅ Automation
Fully automated execution with no manual intervention.
✅ Multi-Database Validation
Works across multiple hosts using TNS-based connectivity.
✅ Error Handling
Captures SQL errors and skips databases that fail to connect.
Logs failures for troubleshooting.
✅ Logging & Reporting
Detailed logs are stored for audit and review.
Generates a formatted report with database mode details.
✅ Email Alerts
Sends a summary email listing databases that are not in READ ONLY mode.
---
6. Example Output
Log File (/tmp/database_mode.log)
Processing database: testdb1
testdb1 READ WRITE 45 days
Processing database: testdb2
testdb2 READ ONLY 30 days
Processing database: testdb3
testdb3 MOUNTED 2 days
Email Notification (/tmp/email_body.txt)
Database: testdb1 is in mode: READ WRITE (Not READ ONLY)
Database: testdb3 is in mode: MOUNTED (Not READ ONLY)
---
7. Troubleshooting
---
8. Execution Steps
1. Ensure Oracle environment variables are set:
export TNS_ADMIN=/auto/your/tns/location
export ORACLE_HOME=/auto/your/oracle/home
export PATH=$ORACLE_HOME/bin:$PATH
2. Create or update db_list.txt with target databases.
3. Run the script:
./database_mode_check.sh
4. Check logs for results:
cat /tmp/database_mode.log
5. If email is expected, verify mail command execution:
mail -s "Databases Not in READ ONLY Mode" your_email@example.com < /tmp/email_body.txt
---
9. Conclusion
This automated script efficiently monitors Oracle databases for READ ONLY mode compliance, logs the results, and notifies DBAs for immediate action if any database is in an unexpected state.
Would you like any add
itional enhancements, such as integration with monitoring tools or scheduled execution using cron jobs?
Comments
Post a Comment