关于序列设置cache之后跳号问题的原因:cache会把sequence缓存在lb cache中,在lb cache中对对象的age out是基于lru算法的,如果cache 20,
会把这个序列每次取的时候取出来20个,然后再在lb cache中一个一个用,但是如果在用完这20个之前,这个序列被aged out了,那么没用的那些数就丢掉了,而下次再去从dd取出sequence的时候就会去取上次那20个+1的号为开始,再来20个。这就是产生断号的原因。
一、产生问题原因
SQL> select JMS_PSNINFO_SEQUENCE.Nextval from dual;
NEXTVAL
----------
721
SQL> select JMS_PSNINFO_SEQUENCE.Nextval from dual;
NEXTVAL
----------
722
SQL> alter system flush shared_pool;
SQL> select JMS_PSNINFO_SEQUENCE.Nextval from dual;
NEXTVAL
----------
741
二、解决办法:
DBMS_SHARED_POOL.KEEP 存储过程
该过程用于将对象固定到共享池
PROCEDURE DBMS_SHARED_POOL.KEEP (name IN VARCHAR2 ,flag IN CHAR DEFAULT 'P');
Flag标志 Description
---------- --------------
C cursor
JC Java class
JD java shared data
JR Java resource
js java source
P Package, procedure, or function name
Q sequence
R trigger
T type
Any other character Cursor specified by address and hash value
e.g.
exec sys.dbms_shared_pool.keep('SYS.STANDARD');
exec sys.dbms_shared_pool.keep('scott.tri_test','T')
keep到缓存中
SQL> exec sys.dbms_shared_pool.keep('bos0301.JMS_PSNINFO_SEQUENCE','Q')PL/SQL procedure successfully completed
查看当前已经常驻内存的对象
select * from v$db_object_cache where kept='YES'
SQL> select * from v$db_object_cache where kept='YES' AND OWNER='BOS0301';
OWNER NAME DB_LINK NAMESPACE TYPE SHARABLE_MEM LOADS EXECUTIONS LOCKS PINS KEPT CHILD_LATCH INVALIDATIONS HASH_VALUE LOCK_MODE PIN_MODE STATUS TIMESTAMP PREVIOUS_TIMESTAMP LOCKED_TOTAL PINNED_TOTAL
---------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ------------ ---------- ---------- ---------- ---------- ---- ----------- ------------- ---------- --------- --------- ------------------- -------------------------------------- -------------------------------------- ------------ ------------
BOS0301 JMS_PSNINFO_SEQUENCE TABLE/PROCEDURE SEQUENCE 4712 4 0 1 0 YES 107864 0 1104258392 NULL NONE VALID 2013-12-17/14:12:28 89 133
从keep中删除对象
exec sys.dbms_shared_pool.unkeep('bos0301.JMS_PSNINFO_SEQUENCE','Q')