Image Image Image Image Image Image Image Image Image




March 30, 2014

Note: Oracle Related posts are moving

March 30, 2014 | By | No Comments

The Oracle Related posts will probably be moving from to (or a similar URL). This blog will be used for some of my other interests. I’ve been planning on a site for what I refer to as DBA “Kata” for a while, and I think the Oracle content will fit better there.



June 13, 2013

A little SQL trick

June 13, 2013 | By | No Comments

I’ve been toying with the idea of a wrapper script for generating output in html format with the key goal being to quickly plot the output of a SQL statement as a time-series chart. To this end I wanted to figure out a way where I can execute a query, with some flexibility to control the output format. It was at that point that I figured out a little trick. This may be common knowledge, but to me it was new, so humour me.

In this example I’m using the method to geneare a csv file, not very imaginative and there are easier and more flexible ways of doing this, but it’s a simple place to start.

Here we go. First you have a file called “load_query.sql” which looks like the one below:

with q as

Pretty simple stuff. Next we have a file called “csv.sql”, which starts by defining some of the sqlplus output display properties.

-- Parameters
-- 1. Script to execute
-- 2. Output File

-- Settings
alter session set NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';
set heading on
set underline off
set pagesize 50000
set linesize 144
set feedback off
set echo off
set trimout on
set verify off

spool &2

-- Load query and execute
@load_query.sql &1
select q.time || ',' || q.value from q;

spool off

Line 20 & 21 above is where the “trick” comes into play.
In line 20 we execute the load_query.sql script, passing the name of the script that we want to generate csv output for. Note that this script has the following properties:

  • It returns two columns. As the end-goal will be time-series data, we only need time and value columns
  • The query doesn’t end with a semi-colon, that is key, because line 21 is a continuation of the same SQL statement

As an example of a SQL script that can be passed as a parameter when executing csv.sql we can use the query below which shows the number of log switches per hour:

select trunc(first_time, 'hh24') as time ,count(*) as value
from v$log_history
group by trunc(first_time, 'hh24')
order by trunc(first_time,'hh24')

So basically, the csv.sql and load_query.sql files work together to turn the query into the following output:

with q as
select trunc(first_time, 'hh24') as time ,count(*) as value
from v$log_history
group by trunc(first_time, 'hh24')
order by trunc(first_time,'hh24')
select q.time || ',' || q.value from q;

This forms the basis of a system for working with your script-set in a more dynamic way, giving you control of the form that the output takes. In the next post I’ll show how to use the same principal to create a dygraph plot from query output.



October 18, 2011

Introducing jiTree

October 18, 2011 | By | No Comments

I originally started work on jiTree as a way to improve my understanding of Oracle Indexes. Being a visual person, I often find that more complicated concepts are easier to master when I can see them visualised. So at it’s heart this is intended as an educational tool, to make understanding Oracle indexes more accessible.

A long term goal of the project is to improve the speed and accuracy of the visualisation to a degree where it can be used as a general purpose tool for investigating indexes, but whether this is practical (or can be accomplished in a browser) is not clear yet.
The key to jiTree
Using jiTree is simple. All you have to do is paste an Oracle Index Treedump into the box provided and hit the “Draw Index” button. Once drawn you can view and save an image of the visualisation by clicking the “View as Image” button at the bottom of the page.

Use jiTree



October 4, 2011

Oracle Index Tree Dump Visualisation

October 4, 2011 | By | No Comments

 Update: JiTree is an online tool for visualising your indexes.

I’ve been working on a Processing project to visualise Oracle Index Tree Dumps. This is a quick example of the progress. It’s still very much a work in progress, so there are problems to address.

For the test table I’m just copying the dba_objects view into a table.

SQL> select count(*) from dba_objects;


SQL> create table test_o as select * from dba_objects;

Table created.

SQL> create index test_o_idx on test_o(object_id);

Index created.

Next I get the treedump as follows:

SQL> select object_id
2 from dba_objects
3 where object_name = 'TEST_O_IDX';


SQL> alter session set events 'immediate trace name treedump level 71227';

Session altered.

Plugging the treedump into my visualisation tool (as I said, it’s a work in progress) gives this view. A very simple tree consisting of only a root node (red) and leaf nodes (clustered around the yellow core).

Now I delete 20000 rows from the test_o table:

SQL> delete from test_o where object_id between 40000 and 60000;

19565 rows deleted.

SQL> alter session set events 'immediate trace name treedump level 71227';

Loading the new treedump shows us where leaf nodes have been deleted.



May 6, 2010

Oracle and Python

May 6, 2010 | By | No Comments

Some time ago I created a few blog posts about using Oracle and Python. Looking back on it I realise that this is truly an attractive combination for both static and real time data visualisation. I may explore the topic further in future, but for now the links are below:

First Things First
Building on the Basics
cx_Oracle and matplotlib
Pie Charts and ratio_to_report