Tuesday, March 31, 2009

Pickler Fetch

SQL> create user rdba identified by rdba;

User created.

SQL> grant dba to rdba;

Grant succeeded.

SQL>

SQL> connect rdba/rdba
Connected.
SQL>

1 create table big_all_objects
2 as
3 select * from all_objects
4 union all
5 select * from all_objects
6 union all
7 select * from all_objects
8 union all
9 select * from all_objects
10 union all
11 select * from all_objects
12 union all
13* select * from all_objects
SQL> /

Table created.

Elapsed: 00:01:04.67
SQL> select count(1) from big_all_objects;

COUNT(1)
----------
141828

Elapsed: 00:00:00.50
SQL>

1* select /* Without Pickler fetch */ object_id from big_all_objects where object_id in (3,30,50,100,150,200)

OBJECT_ID
----------
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150

30 rows selected.

Elapsed: 00:00:00.88

Let's prepare for pickler fetch:
SQL> create or replace type inListTable as table of number
2 /

Type created.

SQL> create or replace function str2tbl( p_str in varchar2 ) return inListTable
2 as
3 l_str long default p_str || ',';
4 l_n number;
5 l_data inListTable := inListTable();
6 begin
7 loop
8 l_n := instr( l_str, ',' );
9 exit when (nvl(l_n,0) = 0);
10 l_data.extend;
11 l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
12 l_str := substr( l_str, l_n+1 );
13 end loop;
14 return l_data;
15 end;
16 /


Function created.

SQL> SQL>

1 select /* with pickler fetch */ object_id
2 from big_all_objects
3 WHERE object_id IN (select *
4* from table ( cast ( str2tbl('3,30,50,100,150,200') as inListTable)))
SQL> /

OBJECT_ID
----------
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150
3
50
30
100
150

30 rows selected.

Elapsed: 00:00:00.81
SQL>


Both of these take about the same time in running in the 2nd, 3rd iteration onwards.

Let's see what v$sqlarea has to say about these two.

First time after running query with pickler fetch..


EXECUTIONS HASH_VALUE SQL_TEXT SORTS CPU_TIME BUFFER_GETS DISK_READS PARSE_CALLS LOADS
---------- ---------- ------------------------------ ---------- ---------- ----------- ---------- ----------- ----------
1 3492981496 with pickler fetch 0 1370000 11953 9852 1 4


First time after running query after pickler fetch.

EXECUTIONS HASH_VALUE SQL_TEXT SORTS CPU_TIME BUFFER_GETS DISK_READS PARSE_CALLS LOADS
---------- ---------- ------------------------------ ---------- ---------- ----------- ---------- ----------- ----------
1 3532977385 without pickler fetch 0 530000 9174 9562 1 2



Here are the results after running the above queries 10 times each.


EXECUTIONS HASH_VALUE SQL_TEXT SORTS CPU_TIME BUFFER_GETS DISK_READS PARSE_CALLS LOADS
---------- ---------- ------------------------------ ---------- -------- ----------- ---------- ----------- ----------
10 1169982563 without pf 0 4970000 90745 90610 10 1

10 582411935 with pickler fetch 0 5270000 93657 90610 10 4



From the above analysis we can conclude that after the procedure stays in shared pool and/or pinned, the execution time and resources used to run the SQL is the same. The big benefit we get is to have a non-fragmented shared pool. This is applicable when the number of arguments in an in list is random.

Thursday, January 29, 2009

sql date formats

A little FYI...

FORMAT MEANING
D Day of the week
DD Day of the month
DDD Day of the year
DAY Full day for ex. ‘Monday’, ’Tuesday’, ’Wednesday’
DY Day in three letters for ex. ‘MON’, ‘TUE’,’FRI’
W Week of the month
WW Week of the year
MM Month in two digits (1-Jan, 2-Feb,…12-Dec)
MON Month in three characters like “Jan”, ”Feb”, ”Apr”
MONTH Full Month like “January”, ”February”, ”April”
RM Month in Roman Characters (I-XII, I-Jan, II-Feb,…XII-Dec)
Q Quarter of the Month
YY Last two digits of the year.
YYYY Full year
YEAR Year in words like “Nineteen Ninety Nine”
HH Hours in 12 hour format
HH12 Hours in 12 hour format
HH24 Hours in 24 hour format
MI Minutes
SS Seconds
FF Fractional Seconds
SSSSS Milliseconds
J Julian Day i.e Days since 1st-Jan-4712BC to till-date
RR If the year is less than 50 Assumes the year as 21ST Century.
If the year is greater than 50 then assumes the year in 20th Century.

Wednesday, June 25, 2008

Sga Auto sizing ! Good or Bad ?

Have you bumped accross SIMULATOR LRU LATCH or SIMULATOR HASH LATCH ?
I have. I'm sure you have too.
What is it ? Why does it happen ?

Let's start from the basics.

What is ASMM ? Auto Shared Memory Management ?
Sure, it manages Oracle SGA memory dynamically. All you have to do is specify an upper limit using

alter system set sga_target = scope=spfile;

(and reboot !)

and Alas ! Oracle automagically sizes the buffer cache, shared pool, streams pool and the java pool. No need to measure any sizes of what buffer cache or shared pool should be.

Right ?

Wrong !

Let's dig more....


SQL> select
2 component,
3 parameter,
4 initial_size,
5 target_size,
6 final_size,
7 status,
8 to_char(start_time,'dd-mon hh24:mi:ss') start_time,
9 to_char(end_time,'dd-mon hh24:mi:ss') end_time
10 from
v$sga_resize_ops
10 where
start_time > sysdate -1/12
11* order by
start_time



COMPONENT PARAMETER INITIAL_SIZE TARGET_SIZE FINAL_SIZE STATUS START_TIME END_TIME
--------- -------------- ------------ ----------- ---------- ------ --------------- -----------
DEFAULT buffer cache db_cache_size 1.5469E+10 1.5452E+10 1.5452E+10 COMPLETE 04-jun 17:54:40 04-jun 17:54:40

shared pool shared_pool_size 3506438144 3523215360 3523215360 COMPLETE 04-jun 17:54:40 04-jun 17:54:40
SQL>


What is this ?
This means that ASMM is asking to increase the shared pool area and taking away space from buffer cache and that could be a reason why you will see simulator lru latch and simulator hash latch waits.

All good ?

Here's what I found. Although shared pool has enough free space available, SGA resizing still takes place.


SQL> select *
2 from v$sgastat
3 where pool like 'shared pool'
4 and name like 'free%';



POOL NAME BYTES
------------ -------------------------- ----------
shared pool free memory 805474392



What is this ?
The means there is 800 Megs of free space in the shared pool and ASMM is still asking for more space.

Why is that ?

I have asked Oracle. They had a wierd answer. Library object hits could be benfitial with having a larger shared pool.

Really ?
EVEN WITH FREE SPACE AVAILABLE ???

Here's the latest !
"It is cheaper for Oracle to move granules from buffer cache to Shared Pool than to use the free memory already avaiable in Shared Pool" - Doesn't make sense, does it ?

Well, this above is TRUE. ASMM works on hit ratios and when it thinks Shared Pool could do better by re-sizing it, it so does it !

Moral: Don't rely too much on the AUTOMATIC bells and whistles that Oracle provides.

Study them first !

Tuesday, June 24, 2008

Different Yardsticks in Oracle

1) Shared Pool has a 4k Chunk Size.

2) Granule is 16Mb (these days) for an SGA over 128Mb.

3) Shared Pool Library Cache Threshold >2048K (> 2MB)

Monday, June 16, 2008

Linux - One by One the Penguins steal my sanity.

List of some commands I like and you will too !

screen
- Running a script and got disconnected ?
- Running a script in background and forgot to pipe the output ?

These are some and numerous other reasons why you should use screen command rather than doing the above.

screen and hit enter
ctl -a d - to detach from the screen.

screen -ls (to view all disconnected screens like follows)

There are screens on:
6295.ttyp1 (Detached)
22270.ttyp3.server (Detached)
24315.ttyp5.server (Detached)
3 Sockets in /tmp/screens/S-username

screen -r 22270
lets you can get into session 22270

Having fun ?

What happens when i wnat screen's inside screens ?

well. You do the following.

ctl - a - n
gets you in the next screen.

ctl - a - p
gets you in the previous screen.




watch
Great utility ! Ever tried doing iostat -x 3. Well it gives io statictics update every 3 seconds.
Now try this,
watch -n 3 -d iostat
It also refreshes iostat every 3 seconds. But check out the difference.
watch enables the same display over and over again and the deviation portion highlighted.
Probably one of the little great utilites i have every used.

Friday, June 6, 2008

Redo copy latch, allocation latches & log file sync

What is redo copy latch ?
Generation of redo requires a redo copy latch to be acquired by a process. This is done so that the LGWR knows the data is being copied and so it doesn't flushes that data in the REDO LOG.


What is redo allocation latch ?
Redo allocation latch is obtained to allocated space in the log buffer. This is done to know which log buffer blocks are used and which are free.
If you see this event, it could be due to a number of things.
1) You don't have enough space in your log buffer and processes are waiting for space allocatioin, or lgwr is slow due to slower disks.
2) dbwr gets a latch to see whether these blocks are written to the disk so it can write these blocks to the data files.
3) The sessions that are waiting on log file sync cycle thru and acquire redo allocation latch to check on the log buffer blocks are written to the redo logs or not.

These are the basic reasons why you will see redo allocation latch. Ask me if you need to know how to fix these issues.


What is log file sync ?
Sessions waiting on the return on the commit from the log buffer to guarantee recovery.
DBWR waiting on LGWR to write redo blocks to the redo buffer so dbwr could write the corresponding blocks in the datafiles.
Slower disks
Smaller log buffer.