Splunk collects machine data (log files, metrics, events) into indexes and lets you search it with the Search Processing Language (SPL). For a DBA, that means one place to search alert logs, listener logs, OS logs and application errors across every server. This post covers the basics and the SPL commands I use most.
Key terms
| Term | Meaning |
|---|---|
| Index | Where data is stored, for example oracle or os. Always name the index in your search; it is much faster. |
| Sourcetype | The format of the data, such as oracle:alert or linux_secure. It decides how fields are extracted. |
| Source | The file or input the event came from, such as /u01/app/oracle/diag/.../alert_ORCL.log. |
| Host | The server that sent the event. |
| Event | One record, usually one log entry, with a timestamp. |
| Field | A named value in an event, such as host or an extracted ora_error. |
| Forwarder | The Universal Forwarder agent on each server that sends files to Splunk. |
Your first searches
Open Search & Reporting, pick a time range in the time picker (for example "Last 24 hours"), and type:
index=oracle sourcetype=oracle:alert "ORA-"
Search terms are combined with AND by default. Use OR and NOT in capitals, and quotes for exact phrases:
index=oracle ("ORA-00600" OR "ORA-07445") NOT host=testdb*
index=os sourcetype=linux_secure "Failed password"
Click a field in the left sidebar to see its top values, and click a value to add it to the search.
The pipe
Like in a Unix shell, | passes the results of one command to the next. The first part finds events; the commands after the pipes shape them:
index=oracle "ORA-" | stats count by host | sort - count
SPL commands I use most
| Command | What it does | Example |
|---|---|---|
stats | Counts, sums, averages by field | | stats count by host |
timechart | Statistics over time, for a chart | | timechart span=1h count by host |
top / rare | Most or least common values | | top limit=10 ora_error |
table | Show only chosen fields | | table _time host ora_error |
sort | Sort results (- means descending) | | sort - count |
dedup | Keep one event per value | | dedup host |
rex | Extract a field with a regular expression | | rex "(?<ora_error>ORA-\d{5})" |
eval | Calculate a new field | | eval gb=round(bytes/1024/1024/1024,2) |
where | Filter on a calculated condition | | where count > 10 |
rename | Rename fields for display | | rename count AS "Errors" |
head / tail | First or last N results | | head 20 |
lookup | Add fields from a CSV lookup table | | lookup db_owners host OUTPUT team |
transaction | Group related events into one | | transaction host maxspan=5m |
Useful searches for DBAs
ORA- errors in alert logs, by database server and error code:
index=oracle sourcetype=oracle:alert "ORA-"
| rex "(?<ora_error>ORA-\d{5})"
| stats count by host ora_error
| sort - count
Hourly trend of ORA- errors, one line per host:
index=oracle sourcetype=oracle:alert "ORA-" | timechart span=1h count by host
Databases that restarted in the last 7 days (set the time picker to "Last 7 days"):
index=oracle sourcetype=oracle:alert "Starting ORACLE instance" | table _time host | sort - _time
Failed SSH logins on database servers:
index=os sourcetype=linux_secure "Failed password" | rex "from (?<src_ip>\d+\.\d+\.\d+\.\d+)" | stats count by host src_ip | where count > 5
Listener connections per service per hour:
index=oracle sourcetype=oracle:listener "establish" | rex "SERVICE_NAME=(?<service>[^\)]+)" | timechart span=1h count by service
SPL does not use -- for comments. To add a comment inside a search, wrap it in three backticks: ```count errors per host```.
Sourcetype names depend on how your Splunk admin set up the inputs. Run index=oracle | stats count by sourcetype to see what you have.
Saving searches, alerts and dashboards
- Save As → Report keeps a search you run often.
- Save As → Alert runs the search on a schedule and emails you (or opens a ticket) when there are results. For example: "ORA-00600 in the last 15 minutes, any host".
- Save As → Dashboard Panel adds the chart to a dashboard, such as a daily database health page.
Tips for fast searches
- Always start with
index=and, if you can,sourcetype=. - Use the smallest time range that answers your question.
- Filter as early as possible, before the first pipe, and use
statsrather thantransactionwhen you can. - Use
| fields host ora_errorearly to carry only the fields you need.
To practice, Splunk offers a free trial of Splunk Enterprise and free introductory training on its website.
More DBA scripts are in my GitHub repository: github.com/sbajwa55/dba-scripts. For help with Oracle, cloud migrations or AWS, visit Bajwa Consulting Services.

No comments:
Post a Comment