對序列進行遷移時產生間斷的原因

楊奇龍發表於2011-04-01
我們知道建立序列時,會有預設的或者指定的 n個值會cache到記憶體中,當資料庫所在的伺服器down 機或者遷移序列時,會發生序列丟失的問題。現在就第二種進行實驗。這裡並沒有什麼方法可以解決序列 間隔的問題,如果有,也請大家給以事例。
yang@rac1>create sequence yang_seq ;
Sequence created.
yang@rac1>select yang_seq.nextval from dual;
   NEXTVAL
----------
         1
yang@rac1>/
   NEXTVAL
----------
         2
yang@rac1>/
   NEXTVAL
----------
         3
yang@rac1>/
   NEXTVAL
----------
         4
yang@rac1>/
   NEXTVAL
----------
         5
yang@rac1>/
   NEXTVAL
----------
         6
yang@rac1>/
   NEXTVAL
----------
         7
匯出序列:
oracle@rac1:rac1 /tmp>expdp yang/yang  directory=dumpdir dumpfile=sequence.dmp  include=sequence  
Export: Release 11.2.0.1.0 - Production on Fri Apr 1 22:59:31 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Starting "YANG"."SYS_EXPORT_SCHEMA_01":  yang/******** directory=dumpdir dumpfile=sequence.dmp include=sequence
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Master table "YANG"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for YANG.SYS_EXPORT_SCHEMA_01 is:
  /tmp/dump/sequence.dmp
Job "YANG"."SYS_EXPORT_SCHEMA_01" successfully completed at 23:01:06
刪除序列
yang@rac1>drop sequence yang_seq;
Sequence dropped.
匯入序列:
oracle@rac1:rac1 /tmp>impdp yang/yang  directory=dumpdir dumpfile=sequence.dmp  table_exists_action=skip include=sequence  
Import: Release 11.2.0.1.0 - Production on Fri Apr 1 23:06:21 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "YANG"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "YANG"."SYS_IMPORT_FULL_01":  yang/******** directory=dumpdir dumpfile=sequence.dmp table_exists_action=skip include=sequence
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Job "YANG"."SYS_IMPORT_FULL_01" successfully completed at 23:07:21
再次驗證
yang@rac1>select yang_seq.nextval from dual;

   NEXTVAL
----------
        21
從7 間斷了13個 (注意:預設的是20個)
從下面的實驗中可以看出 我們匯入sequence時 資料庫都做了什麼:
oracle@rac1:rac1 /tmp>impdp yang/yang  directory=dumpdir dumpfile=sequence.dmp   SQLFILE=seq.sql                                               
Import: Release 11.2.0.1.0 - Production on Fri Apr 1 23:15:16 2011
Data Mining and Real Application Testing options
Master table "YANG"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "YANG"."SYS_SQL_FILE_FULL_01":  yang/******** directory=dumpdir dumpfile=sequence.dmp SQLFILE=seq.sql
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Job "YANG"."SYS_SQL_FILE_FULL_01" successfully completed at 23:16:13

oracle@rac1:rac1 /tmp>cd dump
oracle@rac1:rac1 /tmp/dump>ls
export.log  import.log  seq.sql  sequence.dmp  t.dmp
oracle@rac1:rac1 /tmp/dump>cat seq.sql
-- CONNECT YANG
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/SEQUENCE/SEQUENCE
 CREATE SEQUENCE  "YANG"."YANG_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER  NOCYCLE ;
每次匯入佇列時,會從cache 的 N+1 開始(N 為建立序列時cache 在記憶體中的值 )。這就是為什麼會出現間斷了。
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-691503/,如需轉載,請註明出處,否則將追究法律責任。

相關文章