Kamran Agayev's Oracle Blog

Kamran Agayev's Oracle Blog

Finding the folder that consumes more space in Linux OS

Posted by Kamran Agayev A. on January 23rd, 2012

Sometimes we got some folders filled with unknown files either due to any bug where Oracle creates 100 files in a second :) or due to the OS bugs. And in some cases we’re not able to find in which folder files were created. For that, you can use the simplest command in Linux to get the output for the folders with its size sorted. Here’s the command:

du -s /u01/* | sort -n -r

.......

28G     /u01/oracle/product/10.2.0/db_1/flash_recovery_area

........

 

From the output you will get the folder which consumes more space

Posted in Administration, Oracle on Linux | 2 Comments »

My presentation at Oracle OpenWorld 2011 – San Francisco

Posted by Kamran Agayev A. on January 12th, 2012

I’m getting a lot of emails from readers asking me to share my OpenWorld 2011 presentation files. So I decided to share it with you. Here, you can download the presentation with necessary video tutorials that I’ve shown at OpenWorld 2011. Download the .zip file and extract it under the folder C:\ and make sure you run the presentation from the following folder -c:\OOW 2011 – Kamran Agayev A\

Downloaded 221 times

I’ve also uploaded a part of my speech to youtube, you can watch it online:

Posted in Uncategorized | 2 Comments »

Oracle Flashback Technologies – VIDEO Tutorial

Posted by Kamran Agayev A. on January 6th, 2012

In this video tutorial I show practical demonstrations on all Flashback Technologies that are avaiable in Oracle

 

To download the .mp4 format of the video tutorial, use the following link:

http://www.kamranagayev.com/Video_Tutorials/Flashback_Technologies.mp4

Posted in Administration | 2 Comments »

Dumping an Oracle data block, reading the output and doing some math

Posted by Kamran Agayev A. on October 31st, 2011

In this post I’d like to show you how to dump a smallest logical structure of an Oracle Database – Data Block. Have you ever interested what’s actually stored in the data block and if it’s possible to get any information by “dumping” it? Sure you have. You can dump a single data block of the datafile. Let me show you how it’s done

First of all let’s create a new tablespace and a table:

SQL> create tablespace my_tbs datafile '/u01/oracle/oradata/repdb/my_tbs.dbf' size 100m;

Tablespace created.

SQL> create table my_tab tablespace my_tbs as select * from dba_objects;

Table created.

Now let’s get more information about this table from DBA_SEGMENTS view:

SQL> select header_file, header_block, bytes, blocks, extents from dba_segments where segment_name='MY_TAB';

HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS    EXTENTS
----------- ------------ ---------- ---------- ----------
          7            9    7340032        896         22 

SQL> 

From the output we can say that the header block of the table is stored in the datafile 7, block 9. The size of the table 7340032 bytes (7.3 Mb) and it contains 896 blocks and 22 extents. After getting block size of the database, let’s do some math:

SQL> show parameter db_block_size

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_block_size                        integer     8192
SQL>

BLOCKS (dba_segments) * DB_BLOCK_SIZE (parameter file) = BYTES (dba_segments)

896*8192=7340032

Now let’s query DBA_EXTENTS view to get some information on extents and data blocks of this table:

SQL> col segment_name format a10
SQL> set pagesize 100
SQL> select segment_name, extent_id, block_id,  blocks, bytes from dba_extents where segment_name='MY_TAB';

SEGMENT_NA  EXTENT_ID   BLOCK_ID     BLOCKS      BYTES
---------- ---------- ---------- ---------- ----------
MY_TAB              0          9          8      65536
MY_TAB              1         17          8      65536
MY_TAB              2         25          8      65536
MY_TAB              3         33          8      65536
MY_TAB              4         41          8      65536
MY_TAB              5         49          8      65536
MY_TAB              6         57          8      65536
MY_TAB              7         65          8      65536
MY_TAB              8         73          8      65536
MY_TAB              9         81          8      65536
MY_TAB             10         89          8      65536
MY_TAB             11         97          8      65536
MY_TAB             12        105          8      65536
MY_TAB             13        113          8      65536
MY_TAB             14        121          8      65536
MY_TAB             15        129          8      65536
MY_TAB             16        137        128    1048576
MY_TAB             17        265        128    1048576
MY_TAB             18        393        128    1048576
MY_TAB             19        521        128    1048576
MY_TAB             20        649        128    1048576
MY_TAB             21        777        128    1048576

Using DBA_EXTENTS view we can get BLOCK_ID range and number of data blocks in each extent. Look at the following output:

MY_TAB              0          9          8      65536
MY_TAB              1         17          8      65536

Here it’s seen that the first extent (0) contains 8 blocks which id range between 9 and 17
9 (block_id) + 8 (number of blocks) = 17 (block_id of the next extent)

Ok, now let’s start dumping the header block of the table. For this we need data file and header block number. It can be taken from the DBA_SEGMENTS

SQL> select header_file, header_block from dba_segments where segment_name='MY_TAB';

HEADER_FILE HEADER_BLOCK
----------- ------------
          7            9 

SQL> 

The dump file will be stored in UDUMP directory (user_dump_dest). We can use TRACEFILE_IDENTIFIER to specify part of the trace file name and find it quickly under the UDUMP directory.

SQL> alter session set tracefile_identifier = db_block_dump;

Session altered.

Now, dump the data block 9 of the datafile 7:

SQL> alter system dump datafile 7 block 9;    

System altered.

SQL> 

Ok, now open the second session (in new terminal) and open the trace file. You will see the following output:

tail -f repdb_ora_18308_DB_BLOCK_DUMP.trc

*** 2011-10-28 17:05:21.015
Start dump data blocks tsn: 7 file#: 7 minblk 9 maxblk 9
buffer tsn: 7 rdba: 0x01c00009 (7/9)
scn: 0x0000.02eeaf02 seq: 0x01 flg: 0x04 tail: 0xaf021001
frmt: 0x02 chkval: 0x1a9f type: 0x10=DATA SEGMENT HEADER - UNLIMITED
  Extent Control Header
  -----------------------------------------------------------------
  Extent Header:: spare1: 0      spare2: 0      #extents: 22     #blocks: 895
                  last map  0x00000000  #maps: 0      offset: 4128
      Highwater::  0x01c0037a  ext#: 21     blk#: 113    ext size: 128
  #blocks in seg. hdr's freelists: 0
  #blocks below: 880
  mapblk  0x00000000  offset: 21
                   Unlocked
     Map Header:: next  0x00000000  #extents: 22   obj#: 130752 flag: 0x40000000
  Extent Map

Let’s try to read the above output :

* Start dump data blocks tsn: 7 file#: 7 minblk 9 maxblk 9
This means that the following lines is the output of datafile 7, block 9. Range of blocks can be given to dump:

alter system dump datafile 1 block min 29081 block max 30539 

* rdba is the Data Block Address which is internal representation of the block address. The first 10 bits contains file number, and the rest 22 bits contains block id. So here if we convert 0x01c00009 to decimal, we would get 7/9 which is shown between brackets. Moreover, DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE and DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK can be used to get the file and block number based on RDA value. But before using these functions, rda should be converted to the decimal value.
So here, we convert the rda value (0x01c00009) to decimal and got – 29360137. Then pass this value to the above mentioned functions:

SQL> select DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(29360137) from dual;

DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(29360137)
----------------------------------------------
                                             7

SQL> select DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(29360137) from dual;

DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(29360137)
-----------------------------------------------
                                              9

SQL> 

In order to convert hexadecimal value to the decimal online, you can use the following link:
http://www.statman.info/conversions/hexadecimal.html

By using DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS function and passing file and block value, we can get RDA value:

SQL> select DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS(7,9) from dual;

DBMS_UTILITY.MAKE_DATA_BLOCK_ADDRESS(7,9)
-----------------------------------------
                                 29360137

SQL>

* scn – is the SCN value of the block which defines when it was last modified. We can compare it with each transaction SCN value inside the dump file. The SCN value of the data block is 0×0000.02eeaf02. If second part of this value (02eeaf02) is converted to the decimal, then we got – 49196802. If we query the current_scn value we got:

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
   49249322

SQL> 

* tail is used to keep track of consistency information between the beginning and end of the block against the possibility of distribution of oracle blocks over multiple OS blocks

* frmt – is the block format which tells whether it’s Oracle 7 or Oracle 8 and higher block. 0×02 represents that it’s Oracle 8 and higher block. (0×01 represents that it’s Oracle 7 block)

* chkval – which is checksum written to the blocks when it is set and used by Oracle in part to check the consistency and validity of the block

* type : Type defines which type of block it is. In this example it is “Data Segment Header”

  Extent Header:: spare1: 0      spare2: 0      #extents: 22     #blocks: 895   

Then in the Extent Control Header part we can get information about extents. So it has 22 extents and 895 blocks.

      Highwater::  0x01c0037a  ext#: 21     blk#: 113    ext size: 128
  #blocks in seg. hdr's freelists: 0
  #blocks below: 880   

Highwater mark is at extent 21, block 113. This extent has 128 blocks. And there’re 880 data block below it. Let’s do some math:

As it has 880 blocks below and the number of block is 895 (dump file didn’t count the header block), then there’re 895-880=15 data blocks free (and above the hightwater mark)
Moreover, as the highwater mark is at block 113 and the extent has 128 data blocks, then 128-113=15 data blocks are free
So this means that there’s 15*8192=122880 bytes (122Kb) free space

     Map Header:: next  0x00000000  #extents: 22   obj#: 130752 flag: 0x40000000

Next, we got object id. To find more details on that object, query sys.obj# view:

SQL> col name format a10
SQL> select obj#, owner#, name, status, ctime, type# from sys.obj$ where obj#=130752;

      OBJ#     OWNER# NAME           STATUS CTIME          TYPE#
---------- ---------- ---------- ---------- --------- ----------
    130752          0 MY_TAB              1 28-OCT-11          2

SQL> 

So the owner id is 0 (which is SYS user) and type is 2 (which means table)

SQL> select username from dba_users where user_id=0;

USERNAME
------------------------------
SYS

SQL> 

and to get information about types, use the following query:

select USERNAME,

count(decode(o.TYPE#, 2,o.OBJ#,'')) Tabs,

count(decode(o.TYPE#, 1,o.OBJ#,'')) Inds,

count(decode(o.TYPE#, 5,o.OBJ#,'')) Syns,

count(decode(o.TYPE#, 4,o.OBJ#,'')) Views,

count(decode(o.TYPE#, 6,o.OBJ#,'')) Seqs,

count(decode(o.TYPE#, 7,o.OBJ#,'')) Procs,

count(decode(o.TYPE#, 8,o.OBJ#,'')) Funcs,

count(decode(o.TYPE#, 9,o.OBJ#,'')) Pkgs,

count(decode(o.TYPE#,12,o.OBJ#,'')) Trigs,

count(decode(o.TYPE#,10,o.OBJ#,'')) Deps

from obj$ o,

dba_users u

where u.USER_ID = o.OWNER# (+)

group by USERNAME

order by USERNAME

In order to show the free space, we can use DBMS_SPACE.UNUSED_SPACE procedure. Let’s create a procedure :

SQL> create or replace
  2  procedure show_space
  3  ( p_segname in varchar2,
  4    p_owner   in varchar2 default user,
  5    p_type    in varchar2 default 'TABLE',
  6    p_partition in varchar2 default NULL )
  7  authid current_user
  8  as
  9      l_free_blks                 number;
 10      l_total_blocks              number;
 11      l_total_bytes               number;
 12      l_unused_blocks             number;
 13      l_unused_bytes              number;
 14      l_LastUsedExtFileId         number;
 15      l_LastUsedExtBlockId        number;
 16      l_LAST_USED_BLOCK           number;
 17
 18   procedure p( p_label in varchar2, p_num in number )
 19      is
 20      begin
 21          dbms_output.put_line( rpad(p_label,40,'.') ||
 22                                p_num );
 23      end;
 24
 25  begin
 26      dbms_space.unused_space
 27      ( segment_owner     => p_owner,
 28        segment_name      => p_segname,
 29        segment_type      => p_type,
 30            partition_name    => p_partition,
 31        total_blocks      => l_total_blocks,
 32        total_bytes       => l_total_bytes,
 33        unused_blocks     => l_unused_blocks,
 34        unused_bytes      => l_unused_bytes,
 35        LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
 36        LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
 37        LAST_USED_BLOCK => l_LAST_USED_BLOCK );
 38
 39      p( 'Total Blocks', l_total_blocks );
 40      p( 'Total Bytes', l_total_bytes );
 41      p( 'Total MBytes', trunc(l_total_bytes/1024/1024) );
 42      p( 'Unused Blocks', l_unused_blocks );
 43      p( 'Unused Bytes', l_unused_bytes );
 44      p( 'Last Used Ext FileId', l_LastUsedExtFileId );
 45      p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
 46      p( 'Last Used Block', l_LAST_USED_BLOCK );
 47  end;
 48
 49  /

Procedure created.

SQL> set serveroutput on
SQL> exec show_space('MY_TAB','SYS');
Total Blocks............................896
Total Bytes.............................7340032
Total MBytes............................7
Unused Blocks...........................15
Unused Bytes............................122880
Last Used Ext FileId....................7
Last Used Ext BlockId...................777
Last Used Block.........................113

PL/SQL procedure successfully completed.

SQL> 

Now I copy/paste the math I’ve done above again to compare both results.

As it has 880 blocks below and the number of block is 895 (dump file didn’t count the header block), then there’re 895-880=15 data blocks free (and above the hightwater mark)
Moreover, as the highwater mark is at block 113 and the extent has 128 data blocks, then 128-113=15 data blocks are free
So this means that there’s 15*8192=122880 bytes (122Kb) free space

As you see comparison of both values led us to the same results

So in this post you’ve learned how to dump a header block of the segment and how to read it. In the next post I’ll try to go more deep and dump a data block that contains data, make some transactional changes on the data and see what happens in the background in the block level!

Posted in Uncategorized | 4 Comments »

Step by Step Oracle installation All in One e-book

Posted by Kamran Agayev A. on October 19th, 2011

I’ve decided to create an e-book based on all “Step by Step Installation Guides” that I have in my blog. This e-book contains the following step-by-step guides:

1. Step by Step Installing Oracle Database 10gR2 on Linux

2. Step by Step Installing Oracle Database 10gR2 on Oracle Solaris 10

3. Step by Step installing Oracle 11g R2 on OEL 5.5

4. Step by Step installing Oracle 11g R2 on Oracle Solaris 10

It consists of 200 pages and contains 188 screenshots! You can download it “for free” from the following link:


Downloaded 1088 times

Posted in Uncategorized | 9 Comments »

Oracle NoSQL is now available at OTN

Posted by Kamran Agayev A. on October 19th, 2011

Oracle NoSQL is now available at OTN. Check the following link for more information, download and documentation:
http://www.oracle.com/technetwork/database/nosqldb/overview/index.html

Posted in Administration | No Comments »

My blog is redirected to the new domain – www.KamranAgayev.com

Posted by Kamran Agayev A. on October 14th, 2011

Just want to let you know that I’ve redirected my wordpress blog to www.KamranAgayev.com domain. If you have my blog in your blogroll, please change it to the new one. Actually, you shouldn’t feel any difference, because all links were redirected and should work fine. In case you find any broken link, please let me know

Posted in Uncategorized | 1 Comment »

Exclusive Interview with Rob van Wijk

Posted by Kamran Agayev A. on September 23rd, 2011

Rob has worked with Oracle databases and related products since 1995. First as a developer and analyst using Oracle Forms, Reports and Designer. Currently he works as a technical architect, QA-consultant and/or performance consultant. His main areas of expertise are the database, SQL, PL/SQL and performance. He’s an Oracle ACE

 

Could u please provide answer to the following questions as follows:

  • Brief information about yourself and your family

I live in Utrecht in the Netherlands with my wife and three sons of 5, 4 and 0 years old. I work at CIBER as a principal Oracle consultant.

  • Your education

I studied “Technische Informatica” at the Technical University of Eindhoven from 1991 to 1995.

 

  • Your experience with Oracle. When you started first? Has it been interest of your side or just a coincidence?

For the last part of my study I worked six months at Shell, building a query generator using Oracle6. When applying for jobs at the end of 1995, I noticed several HR departments had put a red circle around the word Oracle, because it was in demand. So it was coincidence.

  • What was the motive behind to prefer Oracle? Who you have been influenced by?

I had some bad experiences using other (M$) technologies at Shell and the front end tools of Oracle, especially Forms and Designer were very good at that time. I still believe you cannot top the productivity we got from using those tools. Nowadays I have only seen APEX coming close.

From 2003 to 2006 I read a few threads each day on AskTom, so Tom Kyte has had a big influence on me. From then on I started participating in forums and reading Oracle related blogs. Currently I have more than 100 blogs in my reader, who all influence me in one way or the other.

 

  • What would your preference of profession if not Oracle?

I would probably still work in IT, maybe as a web developer or for Google.

  • What motivates you in your job?

Getting better at what I do and learning new things.

 

  • Do you give lectures on Oracle?

Yes. At CIBER I have give (and attend) knowledge sessions for (by) colleagues. I have presented at several conferences like UKOUG and Oracle OpenWorld. And I just started to give a seminar for Oracle University called SQL Masterclass in their celebrity series.

  • Have you authored any book in Oracle?

No.

  • Do you manage with your time as to read books on Oracle? What is the name of the book that you read recently?

Yes, but not very much. One or two per year at most. The last one was Oracle Insights – Tales from the Oak Table.

  • What do you think on OTN forums?

It’s where I started to answer questions in 2006. Besides trying to help, I quickly found that it’s a great way to learn as well. There are lots of very knowledgeable people there that you can learn a lot from. My participation has dropped significantly the last two years because I don’t like the forum software. These days I answer more at Stack Overflow. Their forum engine is absolute fabulous compared to OTN.

  • Do you refer to the documentation? And how often does it happen?

I always do. A lot.

  • What is the biggest mistake you have ever made during your DBA career?

I’m not a DBA, but I have made a lot of mistakes of course. I once completely refactored a very important and complex batch job to run in 2 hours instead of 5-6 hours using bulk processing. This went good, but a half year later, I implemented a change, where I screwed up the relation between accounts and bill lines in the bulk collections. The result was tens of thousands of people would get charged energy bills for someone else’s products. The end users had already accepted the change in UAT and it was ready for production. Because of some dependencies, my change stayed in UAT for two months. And by coincidence, a colleague implementing another change at the same module noticed my mistake, just in time. I’m still thankful to him. Thanks Riné!

 

  • What was your greatest achivement as an Oracle DBA?

As a developer, I introduced instrumentation at a customer site. Experiencing how solving production issues was hard or even impossible and became a piece of cake, is very rewarding. The return on investment is just phenomenal.

 

  • What are your best skills which make you differ from others?

In the world it’s not unique by far, but in my job I think it’s rare to find the combination of being able to retrieve or manipulate data in any way you want combined with understanding what you’re asking the database to do for you.

 

  • What’s your major weakness?

Spending too much time behind my laptop.

 

  • How do you balance your daily life with your career?

That’s a struggle with only 24 hours in each day.

 

  • Please describe your one day summary of activities?

There is no such thing as a typical day, so this question is almost impossible to answer.

 

  • How many hours do you work and sleep in a day?

I work 8 hours a day and I try to sleep 8 hours a day.

  • Where and how do you spend your daily, weekly and annual holidays?

Different locations, but we love to go to Turkey one week each year.

  • Do you think about Oracle during vacations?

I usually bring one Oracle book with me, but a vacation is mostly offline for me.

  • Do you have time or motivation to go in for any sports? If yes, which kind of sport do you go in for?

Once a week I play tennis with friends. At amateur level, but with great enthusiasm.

 

  • What’s your favorite meal and non-alcoholic drink?

Sandwich with ragout made by my mom, and cola.

  • What foreign languages do you know?

English and a little bit of French. Dutch is my mother language.

  • What’s your average typing speed?

I don’t know exactly, but I type with 10 fingers and quite fast, so probably around 200 strokes per minute. Unfortunately I write code much slower :-)

  • Have you ever get involved in politics?

No.

  • What are your hobbies?

Oracle of course. And listening to music, working on my APEX application for Tour de France poules, playing Civilization and playing tennis.

 

  • How do you spend your free time?

With my family and exercising the above mentioned hobbies.

  • What’s your biggest ambition?

To raise my children well.

  • What would be your advice to the beginners in Oracle?

Read and try to understand the Concepts Manual and participate in a forum.

  • Would you like your children to follow in your footsteps or take a different path in life?

I hope they will do what they like best, whatever that may be.

  • Do you have any followers of you?

According to Google Reader, 247 readers have currently subscribed to the RSS feed of my blog. I seriously doubt they all consider them “followers of me”, though.

  • What is your vision on the future of Oracle?

I don’t have a vision on Oracle’s future. They’ll probably do fine and expand some more. And their database will remain the best one.

 

  • Could you please take a photo in your office near to your desktop?

Posted in Expert Interviews | No Comments »

Subscribe to the newsletter right now!

Posted by Kamran Agayev A. on September 22nd, 2011

Dear visitors. I’ve just added a subscription widget to my blog. So you can enter your email address and receive notifications of new posts by email!

Posted in Uncategorized | 4 Comments »

CREATE INDEX statement performs Index fast full scan over another index – Hemant's post

Posted by Kamran Agayev A. on September 22nd, 2011

Yesterday, Hemant K. Chitale, who’s co-author of my book “Oracle Backup & Recovery: Expert secrets for using RMAN and Data Pump” posted an interesting article where shows how CREATE INDEX statement performs INDEX FAST FULL SCAN over another index to speed up the process. You can read the article from the following link:

http://hemantoracledba.blogspot.com/2011/09/index-that-is-subset-of-pre-existing.html

Posted in Administration | No Comments »