Watch Oracle DB Session Activity With The Real-Time Session Sampler
Watching Oracle Database session activity is a great way to diagnose and learn about Oracle Database tuning. There are many approaches to this. I wanted something simple, useful, modifiable, no Oracle licensing issues and that I could give away. The result is what I call the Oracle Real-Time Session Sampler (OSM: rss.sql).
The tool is simple to use. Based on a number filtering command line inputs, it repeatedly samples active Oracle sessions and writes the output to a file in /tmp. You can do a "tail -f" on the file to watch session activity in real time!
The rss.sql tool is included in the OraPub System Monitor (OSM) toolkit (v13j), which can be downloaded HERE.
If you simply want to watch a video demo...
Over the past two months I have been creating my next OraPub Online Institute seminar about how to tune Oracle with an AWR/Statspack report using a quantitative time based approach. Yeah... I know the title is long. Technically I could have used Oracle's Active Session History view (v$active_session_history) but I didn't want anyone to worry about ASH licensing issues. And ASH is not available with Oracle Standard Edition.
The Real-Time Session Sampler is used in a few places in the online seminar where I teach about Oracle session CPU consumption and wait time. I needed something visual that would obviously convey the point I wanted to make. The Real-Time Session Sampler worked perfectly for this.
What It Does
Based on a number of command line inputs, rss.sql repeatedly samples active Oracle sessions and writes the output to file in /tmp. The script contains no dml statements. You can do a "tail -f" on the output file to see session activity in real time. You can look at all sessions, a single session, sessions that are consuming CPU or waiting or both, etc. You can even change the sample rate. For example, once every 5.0 seconds or once every 0.25 seconds! It's very flexible and it's fascinating to watch.
Here is an example of some real output.
How To Use RSS.SQL
The tool is run within SQL*Plus and the output is written to the file /tmp/rss_sql.txt. You need two windows: one to sample the sessions and other other to look at the output file. Here are the script parameter options:
rss.sql low_sid high_sid low_serial high_serial session_state wait_event_partial|% sample_delay
low_sid is the low Oracle session id.
high_sid is the high Oracle session id.
low_serial is the low Oracle session's serial number.
high_serial is the high Oracle session's serial number.
session_state is the current state of the session at the moment of sampling: "cpu", "wait" or for both "%".
wait_event_partial is when the session is waiting, select the session only with this wait event. Always set this to "%" unless you want to tighten the filtering.
sample_delay is the delay between samples, in seconds.
Examples You May Want To Try
By looking at the below examples, you'll quickly grasp that this tool can be used in a variety of situations.
Situation: I want to sample a single session (sid:10 serial:50) once every five seconds.
SQL>@rss.sql 10 10 50 50 % % 5.0
Situation: I want to essentially stream a single session's (sid:10 serial:50) activity.
SQL>@rss.sql 10 10 50 50 % % 0.125
Situation: I want to see what sessions are waiting for an row level lock while sampling once every second.
SQL>@rss.sql 0 99999 0 99999 wait enq%tx%row% 1.0
Situation: I want to see which sessions are consuming CPU, while sampling once every half second.
SQL>@rss.sql 0 99999 0 99999 cpu % 0.50
Be Responsible... It's Not OraPub's Fault!
Have fun and explore...but watch out! Any time you are sample repeatedly, you run the risk of impacting the system under observation. You can reduce this risk by sampling less often (perhaps once every 5 seconds), by limiting the sessions you want to sample (not 0 to 99999) and by only select sessions in either a "cpu" or "wait" state.
A smart lower impact strategy would be to initially keep a broader selection criteria but sample less often; perhaps once every 15 seconds. Once you know what you want to look for, tighten the selection criteria and sample more frequently. If you have identified a specific session of interest, then you stream the activity (if appropriate) every half second or perhaps every quarter second.
All the best in your Oracle Database tuning work,
If you have any questions or comments, feel free to email me directly at craig at orapub.com.
|Operating System Focus: Log File Switch Checkpoint Incomplete||How To See Unseen Activity Using ASH And SQL*Net Message From Client||Integrating Stori Into Your Oracle Database Performance Management System|