← All field notes

Oracle Database Block Visualizer

Recently I wanted to demonstrate to some people on my training, how Oracle database maintains blocks in a datafile – what happens after truncate, truncate with drop storage clause, delete, regular insert, direct path insert and so on…

I didn’t find any tool for that so I’ve written my own. It’s core code is based on my previous database block research – project RICO https://blog.ora-600.pl/2015/09/03/rico/

Tool is very small and simple and right now it supports only regular blocks with data and no compression.

And this is how it works – let’s create a tablespace and 3 new tables in HR schema:

ora600@lab ~ / text#01
SQL> conn / as sysdba
Connected.
SQL> create tablespace emps_tbs
  2  datafile '/u01/app/oracle/oradata/orcl/emps_tbs01.dbf'
  3  size 64m
  4  autoextend on next 32m
  5  maxsize 1g;

Tablespace created.

SQL> conn hr/hr
Connected.
SQL> create table employees1 tablespace emps_tbs as select * from employees;

Table created.

SQL> create table employees2 tablespace emps_tbs as select * from employees;

Table created.

SQL> create table employees3 tablespace emps_tbs as select * from employees;

Table created.

SQL>
26 LINESTEXT / UTF-8

Now let’s fill those tables:

ora600@lab ~ / text#02
SQL> ed
Wrote file afiedt.buf

  1  begin
  2    for i in 1..50 loop
  3	 for j in 1..10 loop
  4	   insert into employees1 select * from employees;
  5	   insert into employees2 select * from employees;
  6	   insert into employees3 select * from employees;
  7	   commit;
  8	end loop;
  9    end loop;
 10* end;
SQL> /

PL/SQL procedure successfully completed.
17 LINESTEXT / UTF-8

Now let’s play with tables a little bit 🙂

ora600@lab ~ / text#03


To check the physical layout of blocks in a datafile we have get data_object_id of all tables:
[code]
SQL> ;
  1  select object_id, data_object_id, object_name
  2  from user_objects
  3* where object_name like 'EMPLOYEES_'
SQL> /

 OBJECT_ID DATA_OBJECT_ID OBJECT_NAME
---------- -------------- ------------------------------
     94033	    94033 EMPLOYEES3
     94032	    94032 EMPLOYEES2
     94031	    94031 EMPLOYEES1
16 LINESTEXT / UTF-8

Now we can prepare parameter file for my tool:

ora600@lab ~ / text#04
94031:X|RED
94032:Y|BLUE
94033:Z|MAGENTA
4 LINESTEXT / UTF-8

And this is how we use it (I use print screens to show you colors :))
odbv

And below visualization you can find legend:

odbv2

Well, that’s it. If you want to play with it, you can find this tool, compiled for Linux x86_64 here: http://ora-600.pl/oinstall/odbv.x86_64

I will use it in the future to explain some stuff 🙂 Enjoy!

END OF FIELD NOTE / 2016-11-03

Keep asking why. Keep looking deeper.

← Back to the blog