View and Filter the Oracle Alert Log with ADRCI SHOW ALERT
View and Filter the Oracle Alert Log with ADRCI SHOW ALERT
Purpose
A text editor opens the whole alert log at once. tail -f on the log file shows new lines but can't filter them by meaning. A SQL query on V$DIAG_INFO tells you where the log lives, but not what it says. ADRCI, the ADR Command Interpreter, does all of this from one prompt: it lists the diagnostic homes on the server, points at one of them, and then shows the alert log in full, as a live tail, or filtered by a SQL-like condition such as "messages that contain ORA-".
The commands below are for a DBA who has only a terminal on the database server. They need no SQL session, no editor and no graphical tool. They work the same way for a database instance, an ASM instance or a listener, because each of these keeps its own alert log inside the Automatic Diagnostic Repository (ADR).
Use this sequence when you need to answer one question fast: what has the instance logged recently, and did any of it contain an error? If you need the path of the alert log itself, the companion post on locating the alert log and trace files with V$DIAG_INFO covers that. To search trace files with operating system tools, see finding and grepping Oracle trace files.
Code
1adrci
2show homes
3set homepath diag/rdbms/orcl/orcl
4show alert -tail
5show alert -tail 50
6show alert -tail -f
7show alert -p "message_text like '%ORA-%'"
Code Breakdown
adrci
Starts ADRCI in interactive mode at the operating system prompt. Before you run it, the ORACLE_HOME and PATH environment variables must be set, and PATH must include Oracle_home/bin. On Microsoft Windows the installer sets these in the registry. On other platforms you set and check them yourself.
show homes
Lists the ADR homes in the current ADRCI session. SHOW HOME and SHOW HOMEPATH are the same command. On a typical server the output lists several homes, for example:
1ADR Homes:
2diag/tnslsnr/dbhost1/listener
3diag/asm/+asm/+ASM
4diag/rdbms/orcl/orcl
5diag/clients/user_oracle/host_9999999999_11
The command doesn't need an ADR home to be set first, so it is always safe to run.
set homepath diag/rdbms/orcl/orcl
Makes one ADR home current. The path is relative to the current ADR base, and the leading diag directory can be left out, so set homepath rdbms/orcl/orcl does the same thing. When ADRCI starts, the homepath is null, which means every ADR home under the ADR base is current. Most SHOW ALERT variations work with only one current home. If more than one is current, ADRCI asks you to choose one from a numbered list before it shows anything.
show alert -tail
Shows the most recent entries in the alert log in the terminal. With no number, it shows the last 10 entries.
show alert -tail 50
Shows the last 50 entries. Change the number to match how far back you need to look.
show alert -tail -f
Shows the last 10 entries, then keeps the command running and adds each new alert log entry to the screen as it arrives. This is live monitoring of the alert log. To stop it, press CTRL+C. You can combine the two forms: show alert -tail 20 -f shows the last 20 entries and then follows the log.
show alert -p "message_text like '%ORA-%'"
Shows only the alert log entries for which the predicate is true. The predicate is SQL-like and must be enclosed in double quotation marks. MESSAGE_TEXT is the field that holds the message itself. This example keeps every entry that contains the string ORA-, which brings the errors to the top of a long log. A worked ADR walkthrough runs this same filter, and shows a message_text like '%incident%' filter returning an ORA-07445 entry with its incident number.
Key Points
SHOW ALERTwithout flags opens an editor. The alert log is displayed, with XML tags omitted, in your default editor. Use-tailor-termto keep output in the terminal.- The default editor is
vi. If no editor is set, ADRCI uses the editor in the operating systemEDITORvariable, and if that isn't set either, it usesvi.SET EDITORchanges it for the session. - Only one home at a time, except with
-term.-termdirects output to the terminal and outputs the alert logs of all current ADR homes, one after another. -filereads an alert log outside the ADR. It needs a full path, and it can't be combined with-tail.- The ADR base comes from
DIAGNOSTIC_DEST. That initialization parameter sets the root directory that holds every ADR home. If it is omitted or null, the database sets it to a default value.
Insights and Best Practices
Fields you can filter on
MESSAGE_TEXT is the field most DBAs need, but the -p predicate accepts other alert fields too. The Oracle 19c Utilities guide lists them, including ORIGINATING_TIMESTAMP, MESSAGE_TYPE, MESSAGE_LEVEL, HOST_ID, PROCESS_ID, MODULE_ID and PROBLEM_KEY. Oracle's own example filters on a specific internal error: SHOW ALERT -P "MESSAGE_TEXT LIKE '%ORA-600%'" shows only the messages that contain ORA-600. A narrow string like this is useful when you already know which error you are chasing.
Saving what you find
SPOOL sends ADRCI output to a file. If you give a file name without a path, the file is created in the current ADRCI working directory. If you give no extension, ADRCI uses .ado. Oracle shows this pattern for saving the alert log without XML tags:
1SPOOL /home/steve/MYALERT.LOG
2SHOW ALERT -TERM
3SPOOL OFF
SPOOL filename APPEND adds to an existing file instead of overwriting it, which is useful when you collect output from several homes into one file.
Running the same checks from a script
ADRCI also runs in batch mode, without the interactive prompt. ADRCI EXEC="SHOW HOMES" runs one command from the operating system prompt, and several commands can be chained with semicolons: ADRCI EXEC="SHOW HOMES; SHOW INCIDENT". For longer sequences, ADRCI SCRIPT=adrci_script.txt runs a file of commands separated by semicolons or line breaks. Oracle's example script is SET HOMEPATH diag/rdbms/orcl/orcl; SHOW ALERT -term. Batch mode suits a scheduled job that saves the latest alert entries each morning, because there's no editor to close.
The -p predicate can combine fields. One published alert-log monitoring script runs set home and then show alert -p "message_text like '%ORA-%' and originating_timestamp > systimestamp-1/96" -term inside an adrci exec call. The time condition keeps only entries from the last 1/96 of a day, which is 15 minutes, so each run reports just the new errors.
Pick the right home first
On a server running a database, ASM and a listener, the first show homes usually lists several homes. Setting the homepath before anything else avoids the "choose a home" prompt and makes sure you are reading the right log. The database home sits under diag/rdbms/<db_name>/<instance_name>. The listener and ASM homes sit under diag/tnslsnr and diag/asm.
When to Run This
- Straight after an instance fails to start, to read the last entries before the failure.
- During a change window, with
-tail -frunning in a second terminal to watch for new errors as they appear. - When an application team reports an
ORA-error and you need to see whether the instance logged it too. - As part of a morning check, in batch mode, saving the last entries to a file with
SPOOL. - On a server with a database, ASM and a listener, to read each component's alert log in turn.
Troubleshooting Common Issues
"No ADR base is set." ADRCI may have started with a null or invalid ORACLE_HOME. Exit ADRCI, set ORACLE_HOME, and start it again.
DIA-48400: ADRCI initialization failed. The ADR base directory doesn't exist. Check the value of the DIAGNOSTIC_DEST initialization parameter and make sure it points to an ADR base that contains at least one ADR home. If DIAGNOSTIC_DEST is missing or null, look for an ADR base directory hierarchy in ORACLE_HOME/log.
DIA-48431: Must specify at least one ADR home path. The command needs a current ADR home. Run set homepath with one of the paths from show homes.
DIA-48447: The input path does not contain any ADR homes. The path you gave isn't inside the current ADR base. Set the right base with SET BASE, run show homes to see what is under it, then set the homepath again.
References
- ADRCI: ADR Command Interpreter (Oracle Database 19c Utilities) - Oracle's reference for starting ADRCI, setting the homepath, every SHOW ALERT flag and alert field, SPOOL, batch mode and the ADRCI error messages
- Automatic Diagnostic Repository (ADR) in Oracle Database 11g Release 1 (oracle-base.com) - Tim Hall's walkthrough of ADRCI help, setting a home and filtering the alert log with show alert -p for ORA- messages
- Diagnosing and Resolving Problems (Oracle Database 19c Administrator's Guide) - how the alert log, trace files and incidents fit into Oracle's fault diagnosability infrastructure
- DIAGNOSTIC_DEST (Oracle Database 19c Reference) - the initialization parameter that sets the ADR base ADRCI reads from
- Shell script for monitoring the alert log (dbaclass.com) - a batch ADRCI script that filters the alert log on message_text and originating_timestamp for recent ORA- errors
- V$DIAG_INFO (Oracle Database 19c Reference) - the view that reports ADR locations from inside the database
Posts in this series
- Determining Oracle Database Startup Time using v$instance
- Oracle Schema Space Usage with dba_segments and dba_objects
- Check if Java is Installed in Oracle Database
- Oracle Top 10 Largest Segments Query with dba_segments
- Oracle Feature Usage with dba_feature_usage_statistics
- Assessing Database Storage Utilization in Oracle Database
- Unveiling Language and Locale Settings in Oracle Database
- Locate the Alert Log and Trace Files with V$DIAG_INFO
- List Database Peak Usage with DBA_HIGH_WATER_MARK_STATISTICS
- View and Filter the Oracle Alert Log with ADRCI SHOW ALERT