Friday, 20 June 2014

PX Deq Credit: send blkd causing Parallel queries to hang in Oracle


The main blocker in parallel queries in the Query coordinator, Suppose you want to sum on 500 million rows, Then even if you run in parallel , Each query coordinator will do the sum 
and then give result to query coordinator to further sum it. 

Now consider you have grouping on 2 columns, Then it has to sort the data (group) so the 
query coordinator has lot of work to do in case of 500 million. You will see in parallel plans
p->s which means parallel to sequential 

What this Send blocked error means is Query coordinator already has lot of work so it cant accept any more data from Slave processes and Slaves are waiting for Query coordinator to become free 

Solution - Try to write PL/SQL code using Table functions and DBMS_PARALLEL approach it allows you to linearly scale up

If you really want to make use of parallel , then best to go for procedure and parallelise
procedure using dbms_parallel . This is truly parallel in database

( Assumption -In most of cases you will never be slowed by read speed, 1 billion rows is not a
issue, if you are doing in TB then have to think)

Table Functions  (Very important for datawarehouse implementation and Next is dbms_parallel) 

http://docs.oracle.com/cd/B28359_01/appdev.111/b28425/pipe_paral_tbl.htm

How to make pl/sql go in parallel 

http://www.oracle.com/au/products/database/o30plsql-086044.html



We were facing issue with one of our Fact table population queries getting hanged in Datawarehouse. After long day of analysis below is the summary

1) Checked temp space , it was not increasing. Usually almost all parallel queries bypass buffer cache and they use temp space for most of the sorting , grouping , hash join,. PGA size is small though your PGA can be in GBs but a single process can use max 5% of it. So content gets spilled to temp space. So when temp space is not changing means nothing much is happening in query. It was stucked

2) The sorting , Hashing operation were not taking much part of temp space whatever their size was it was constant for more than 30 minutes

3) The v$session and V$session_wait both tables shows waits on below particular parallel events



Query coordinator ( QC)

Session are waiting on 3 parallel events  ( V$session, V$session_wait)

PX Deq: Execution Msg – Means slave process has finished execution waiting for message from QC to die
PX Deq: Table Q Normal – Means Consumers slaves waiting for producer slaves for data
PX Deq Credit: send blkd – Means slaves are not able to send data to QC they are blocked because QC has not finished processing earlier data. Reason being its parallel buffer pool is full

Root cause of issue – Too many parallel processing sending message to QC and QC not having enough buffer pool to accept those messages

Solution – Increasing buffer pool size for parallel (parallel_automatic_tuning) or reducing degree of parallelism. Can be done by removing default parallelism on tables and setting it manually





Select * From V$tempseg_Usage--------- Temp usage for query is low

select ----------------------------------------  none of the sorts are using high temp space
   a.username,
   sum(srt.blocks * 8 / 1024) "Used Space in MB",
   sum(srt.blocks * 8 / 1024)/1024 "Used Space in GB"
from
   v$session    a,
   v$sort_usage srt
where
   a.saddr = srt.session_addr
   and sid in ( select  sid FROM v$SESSION WHERE OSUSER= )
   Group By A.Username

SELECT p1 file#, p2 block#, p3 class#,EVENT-------------------- Session is waiting for 3 parallel events only
 FROM v$session_wait where sid in (
 Select  Sid From V$session
Where Osuser=''
AND USERNAME =
and blocking_session is null)


The parallel_automatic_tuning parameter sets the pool of buffer messaging. If the parameter is enabled, the buffer will be in the large pool or will be on shared pool whether the parameter is disabled. So if it is expected that your database run many parallel queries, consider fit correctly the pool size.
 


Friday, 13 June 2014

Understanding Explain plan for Parallel Queries in Oracle



Hi Guys

Basic

In the previous article we discussed the general rule for applying parallel hint Parallel Hint.  Parallel explain plan are more complex to read compared to serial plans. When we use hint paralle(2) . 4 Processes are created 2 consumers and 2 producers. The general assumption is if some work can be done by 1 process in 1 minute then it can be done by 2 processors in 1/2 minute or with 4 processes in 0.25 .But this is not true due to various things.  Recently I had faced issue with paralle queries. I found the articles by Randolf Geist and Jonathan lewis. Below are the link . This articles is my take away from their articles and what I found in my queries . 

When you create many parallel processes each process is assigned a PGA memory. Consider you have 128 processes than a lot of PGA memory will be used and this memory when full they will start to use  the Temp Space  thus slowing down the sql 


Article by Randolf Geist. ( Very Very good)


Degree of Parallelism

http://www.oracle.com/technetwork/issue-archive/2010/o40parallel-092275.html

Click on the Image or Save the Image if you are not able to read the Text writen on image 











The change involved moving the table join to a subquery. So basically the idea is make sure processes are working as expected. Read the below article about details on how parallel queries internally work

If degree of parallelism is set to 4 it means 8 parallel processes will be used. 4 as producers and 4 as consumers.When we see PX BLOCK ITERATOR Data is accessed not at partition level but at data block level. Since data is accesed at block level it requires distribution of data

In Order for Parallel queries to work efficiently

Efficient parallel execution plan

Good Link on Bloom filters




Some Notes after reading

Due to this Consumer / Producer model Oracle has to deal with the situation that both Parallel Slave Sets are busy (one producing, the other consuming data) but the data according to the execution plan has to be consumed by the next related parent operation. If this next operation is supposed to be executed by a separate Parallel Slave Set (you can tell this from the TQ column of the DBMS_XPLAN output) then there is effectively no slave set / process left that could consume the data, hence Oracle sometimes needs to revert to sync points (or blocking operations that otherwise wouldn't be blocking) where the data produced needs to be "parked" until one of the slave sets is available for picking up the data.

In recent releases of Oracle you can spot these blocking operations quite easily in the execution plan. Either these are separate operations (BUFFER SORT – not to be confused with regular BUFFER SORT operations that are also there in the serial version of the execution plan) or one of the existing operations is turned into a BUFFERED operation, like a HASH JOIN BUFFERED.

Whenever we say something is buffered it is writen to temp and read back.If the amount of data to buffer is large, it cannot be held in memory and therefore has to be written to temporary disk space, only to be re-read by / to be sent to the Parallel Slave set that is supposed to consume / pick up the data. And even if it can be held in memory, the additional PGA memory required holding the data can be significant.


What does this mean --- simply because Oracle cannot have more than two Parallel Slave sets active per Data Flow Operation ????

SQL work areas -- How has join tables are made ????

What is a Data flow operation


DFO means "Data Flow Operator". Actually, “queries” don’t run in parallel, it’s "data flow operations" (DFOs) that run in parallel, and a single query can be made up of several data flow operations. DFO tree is composite with DFOs, usually one query have one DFO tree. such as

The result from v$pq_tqstat:
 
You can just go through the Screenshot below. Follow the comments that all is needed to understand those plans











 
There are Three ways in which parallel join operations can be performed

First

One slave sets the reads the table as shown in example and one slave set joins the data as shown in the figure. Q1,00 reads the data and Q1,04 joins the data this requires buffering

Second
Look at the broadcast being done , it is received by Q1,06 which also does the full scan of the sec acss grp person. This method does not require buffering for hash joining as entire data has being broadcasted

Note -- If any time you see multiple DFO being used then you will see Q1, Q2 in the TQ column .

For Other two read the original article by oracle ACE Randolf Geist which I found helpful

Note

Window Sorts are Analytical functions

Sunday, 11 May 2014

NMON for Linux performance analysis

Hi All,

Nmon is very important utility for checking linux server perfomance. It is useful for both Reporting and ETL server performance monitoring

sudo apt-get install nmom -- (precede any command by sudo it gets installed by super user
On ubuntu that all that is required . just type nmon

To store the output of nmon to a file
nmon -ft -s 30 -c 120

To search for the file created by nmon . Search for files ending with nmon extension  *.nmon
-f : Start data collect mode and output in spreadsheet format.
-s 2 : Wait between 2 seconds refreshing the screen.
-c30 : Total number of refreshes (30).
-t : Spreadsheet includes top processes.
-d disks : to increase the number of disks [default 256]
-x : Capacity planning (15 min for 1 day = -fdt -s 900 -c 96)
find -iname *.nmon


Friday, 9 May 2014

Working with Cursors



Select into can be used when we are fetching a single row from the select statement

DBMS_OUTPUT.put_line (
     l_last_name);

Select into can be used to select 2 column values into two variables, but the number of rows outputed should not be more then one other wise it gives too many rows exception

Select into is a inplicit cursor that is oracle opens a curson implicitly


  l_department_name  
     departments.department_name%TYPE --- used for defining of the type of the column name

l_employee   employees%ROWTYPE -- used for defining of the rowtype

l_employee_id   employee_id_cur%ROWTYPE--- also can be defined of the type cursor


Using for loops with Cursor

If you declare a for loop using cursor then no need to explicitly open and close the cursor oracle does this for you

Best thing about using for loop with cursor is oracle automatically optimizes the code to use bulk collect so it will collect all the rows before firing the sql

V$lock Table in Oracle

Hi All,

Below link gives good info about V$lock table. Most of us will face issue relating to locking some or other time 





If a session holds a lock that's blocking another session, BLOCK=1

How to get the rowid of the row that is blocked

select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#
  2* from v$session where sid=479



select do.object_name,
  row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
  dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
   from v$session s, dba_objects do
   where sid in ( select  sid FROM v$SESSION
WHERE SQL_ID = '0t15js2r1s67u' )
and s.ROW_WAIT_OBJ# = do.OBJECT_ID


select * from tstlock where rowid='AAAVnHAAQAAAp0tAAA'

NUMA-Non uniform memory access


Most servers with multiple sockest like 32 sockets run on NUMA . Need to understand how this works

Apart from this HBA adapters cards

Blade server v/s clustor .. In clustor different machines are connected by heartbeat but in blade servers all the 4 cpu cells are housed up In one RAC one big machine like cupboard

Sockets are physical slots to hold processors. You cannot place dual core serves in multiple sockets. Processors like xeon are capable of multi socket