Sie sind auf Seite 1von 2

SEQUENCES' CACHE_SIZE

Author JP Vijaykumar
Written May 11th 2018
Modified May 30th 2018

I started noticing considerable waits on event "enq: SQ - contention" during heavy


data loading operations.
I had extracted the following sql, from the referenced urls, and made slight
modification.
This sql suits most of the environments.

Here I am generating the proposed sequences' cache_size equal to avg of sequences'


generation per minute.
you can change this proposed cache_size setting to a higher value or lower values,
like
"avg of sequences' generation per every 5 mts" or "avg of sequences' generation per
every 30 seconds" and the like.

--IDENTIFY SEQUENCES WITH HEAVY INSERTS


--BASED ON AVG SEQUENCE GENERATED FROM CREATION DATE TILL NOW
column sequence_owner format a15
set linesize 140 pagesize 100
select 'alter sequence '||sequence_owner||'.'||sequence_name||' cache '||
proposed_cache_size||';' from (
select a.*,(trunc(a.avg_executions_per_mt/100) + 1)*100 proposed_cache_size
from
(
select sequence_owner,sequence_name,last_number,o.created ,
round(last_number/(sysdate - o.created )/1440) avg_executions_per_mt,cache_size
from dba_sequences s,dba_objects o
where s.sequence_owner = o.owner and s.sequence_name=o.object_name
and round(last_number/(sysdate - o.created )/1440) > 0
) a order by sequence_owner,sequence_name
) where cache_size <> proposed_cache_size;

If the proposed_cache_size > cache_size, then no action taken


and when proposed_cache_size < cache_size, then you may increase that sequence's
cache_size.

Alternatively, if the difference between cache_size and proposed_cache_size is too


high,
then you may take action, else, no action required.

REFERENCES:
https://asktom.oracle.com/pls/asktom/f?
p=100:11:451611870226342::::P11_QUESTION_ID:2985886242221
https://stackoverflow.com/questions/24298868/sequence-cache-and-performance
https://stackoverflow.com/questions/2381681/oracle-sequence-caching
https://www.toadworld.com/platforms/oracle/w/wiki/1332.increasing-the-sequence-
cache-size
http://momendba.blogspot.co.uk/2007/08/to-cache-or-not-to-cache-oracle.html
http://grokbase.com/t/freelists.org/oracle-l/143fd6j1j6/index-contention-sequence-
caching
http://www.arikaplan.com/oracle/ari82599.html --cache option can skip numbers
https://technology.amis.nl/2006/09/22/how-does-the-sequence-cache-affect-
performance/
https://srivenukadiyala.wordpress.com/2010/12/09/determining-appropriate-sequence-
cache-value/
http://www-01.ibm.com/support/docview.wss?uid=swg21570128
http://oraclexpert.com/sequences/
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:530735152441

In our environment, some of the application modules are dormant.


Which were inherited by the application, during past business mergers/acquisitions.
As such, I decided to find only those sequences, which are active in the last 90
days(I had bumped
the snapshot retention to 90 days in our db, and the snapshot interval to 30 mts)
and take appropriate action:

--SEQUENCES WITH HEAVY INSERTS AND SMALL CACHE_SIZE


set linesize 120 pagesize 100
column objejct_owner format a15
with a as (
select a.*,(trunc(a.avg_executions_per_mt/100) + 1)*100 proposed_cache_size from (
select object_owner,object_name,cache_size,round(avg(executions_delta)/30)
avg_executions_per_mt
from dba_hist_sql_plan sp,dba_hist_sqlstat st, dba_sequences sq
where sp.object_type='SEQUENCE'
and sp.sql_id = st.sql_id
and sp.object_owner = sq.sequence_owner
and sp.object_name = sq.sequence_name
group by object_owner,object_name,cache_size having round(avg(executions_delta)/30)
> 0 order by 4
) a)
select '--alter sequence '||object_owner||'.'||object_name||' cache '||
proposed_cache_size||';'||chr(10)||'##'||cache_size from a
where cache_size < proposed_cache_size;

I had increased the active sequences'(sequences that are active in the past 90
days) cache_size.
The recurrance of waits on "enq: SQ - contention" wait event almost stopped, in our
environment.

Readers are advised to make necessary changes to these scripts as may be required
to suit your requirements,
test these scripts throughly in lower environments, before porting to production.

There might be better ways to fix the sequences' cache_size as may be necessary,
the readers are advised to use their ingenuity in investigating further for a
better solution.

These scipts will not work as expected, in the event, if your application more
often selects sequence_name.currval,
You need to search for sql queries that are generating only sequence_name.nextval
and calculate
the average sequence generation per minute. You need to join dba_hist_sqltext and
look for sql_text with NEXTVAL strings.

Happy scripting.

Das könnte Ihnen auch gefallen