Subscribe to Posts by Email

Subscriber Count

    701

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

Performance Troubleshooting Series : Identifying or Estimating How much PGA needed by Session/Query

Have got a question from one of fellow DBA that how much PGA the session will use or needed.

Well to answer this, first we need to know what PGA looks like and what it used for?

The follow shows the components of a PGA, the little space used for Stack, Env Variables and Private SQL area.

Image Courtesy: Oracle Architecture Diagram

Where the most of the utilisation will be SORT AREA, HASH AREA 

SORT AREA : is used when the session performing a sorting of data and use approximately 

HASH AREA: is used when execution plan contains hash join and stores the hashed data and once data is matched or processed the final data put into buffer cache (db file scattered read) but stores with in PGA for Direct Path Reads.

Bit Map Merge area:- When using bitmap keys and merging of data uses.

To further dig into , the PGA setting is not hard limit, it can grow and utilize all free memory at OS if needed by oracle sessions. Until 12c you cannot limit the pga memory size.

For example if you have given PGA_AGGREGATE_TARGET =5g  , pga can still grow more than 5gb accumulating of all sessions not by single session.

In dedicated architecture where each session will have its own PGA space and put the private data like variables , sorting, hashed data etc. However, although the PGA can grow much more than your setting each individual session can have only 200MB of PGA due to hidden parameter _pga_max_size which default to 200MB or 5% of pga_aggregate_target parameter. So that means if a session needs more than 200MB it has to spill to disk to do sorting.

How to find how much each of this area used by your query ,

select inst_id,sid,sql_id,operation_type,sum(actual_mem_used)/1024/1024,sum(work_area_size)/1024/1024, sum(tempseg_size)/1024/1024 from gv$sql_workarea_active  group by inst_id,sid,sql_id,operation_type;

So far we seen the PGA dynamics and allocations of memory, but how to know and estimating how much sorting/hash need of PGA Memory. As of my understanding, this is two fold,

Sort : Once the sort area is full with in pga it will spill to temp space , so ideally with gather plan statistics hint we can find out the temporary space need

Hash: Basically a full table scans, ideally used for hash joins of two tables, find the two tables that join with hash you are looking for find the avg_row_len * num of rows should give you approximate hash utilization.

For example consider a simple query below, which does a full table scan of each table O,T,I.

The plan shows three tables having full tables doing hash join to finalize the data after equal predicates.

Lets look at the calculation tables (here I done some estimations to prove avg_row_len can be used but cases may vary, and its not hard fact rule it will be matched)

Estimation Calculation, to do estimation I have taken the exact row length and rows from dba_tables and the number of rows returned from query. I have added few columns manually to do calculation, the query may not return below. 

Lets look at v$sql_workarea_active to see how much expected and actual pga / workarea used for this query.

As you see above, the Expected_MB column shows the expected pga utilization for this query which matches to our Estimation table above.

Happy Reading

Geek DBA

Comments are closed.