Python graphing scripts for Oracle database tuning
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


# PythonDBAGraphs

This is a Python program that displays graphs that
are helpful for Oracle database performance tuning.

PythonDBAGraphs includes these graphs: - Shows cpu usage within an Oracle database
            by various parts of the application. - Shows the average time for an Oracle wait
             event and the number of events per period.
  - Show average elapsed versus executions
                   for one SQL statement. - Show average elapsed versus executions
            for all SQL statements.
 - Show average elapsed versus executions
               for SQL statements whose force matching
               signature is in a specified group of
  - Show total elapsed, CPU, and IO time
               for SQL statements whose force matching
               signature is in a specified group of
               signatures. - Show total elapsed for SQL statements 
                   whose force matching signature is in a 
                   specified group of signatures. Show 
                   percent CPU used on same graph. - Four metrics for SQL statements 
             whose force matching signature is in a 
             specified group of signatures. These are
             number of executions, average elapsed time,
             CPU percent used, and average single block
             read time.
  - For a time range show the number of active
              sessions on CPU and total number active. - Show execution time of a single 
                      SQL statement by plan.
              - Plot the number of connected sessions. - Segment usage statistics for one segment - Show the number of sessions active on one particular wait. - Plots total elapsed, cpu, and io seconds for a single sql_id. - Shows overall I/O information for one database. - Shows host level CPU information for one instance
Command line help:

usage: [-h] {file,screen} [database] {Y,N} {Y,N}

Database CPU by Application Area

positional arguments:
  {file,screen}  Where to send the graph
  database       Name of the database
  {Y,N}          Show SQL that was executed (Y or N)
  {Y,N}          Show data returned by query (Y or N)

optional arguments:
  -h, --help     show this help message and exit

See README for more detailed help.


python screen ORCL N N

This creates the graph on the ORCL database and sends the output to 
the screen. It does not display the SQL used and it does not output the
data returned by the query.

Two other included scripts: - shows a range of colors. I used this to pick the colors
for the graphs.


python r .5

Sets red at 0.5 and shows range of colors varying blue and green between 0.0 and 1.0. - Displays a graph based on data saved from an earlier run.
                Prompts for the name of the file that was previously saved.


Enter name of data file to be restored: D:\temp\All SQL statements on DBATEST2 database.txt


The author primarily uses this application in the following environment:

Windows 7

32 bit Python 3.6.1

These packages:

cx-Oracle (6.2.1)
cycler (0.10.0)
matplotlib (2.0.2)
numpy (1.12.1)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.0)
pytz (2017.2)
setuptools (28.8.0)
six (1.10.0)
wxPython (4.0.0a2)

I had to do the following steps to configure Matplotlib to use wxPython:

Download from this URL:

Run this command:

python --verbose-helpful 

Output includes a line like this:

loaded rc file C:\Users\myuser\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\mpl-data\matplotlibrc

I edited the matplotlibrc to use wx by setting backend to WXAgg. Here is the diff from the original matplotlibrc:

diff matplotlibrc.original matplotlibrc
< backend      : TkAgg
> backend      : WXAgg


The program uses certain directories. The paths to these directories
are stored in the file directories.txt which is kept in the same 
location as the script. The directories are the configuration, 
password, and output directories.

The configuration directory contains the file userandfilenames.txt
which has the Oracle user name and the name of the password file.

The password directory contains the password file. It has lines in this 

Database name:user name:password

The output directory is where image files are written if you choose
"file" as the destination for the graph.

You can test these scripts interactively through IDLE by setting the arguments
at the top of the script. So, if you want to test put these lines
at the top of the file:

import sys
sys.argv = ['x','screen','YOURDB','N','N']

Once you are done testing remove these lines and run the script from the command line.

Related blog posts: