对序列进行迁移时产生间断的原因

简介:
我们知道创建序列时,会有默认的或者指定的 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 在内存中的值 )。这就是为什么会出现间断了。
相关文章
|
3月前
leetcode-2016:增量元素之间的最大差值
leetcode-2016:增量元素之间的最大差值
32 0
|
6月前
|
机器人
【Leetcode -657.机器人能否返回原点 -674.最长连续递增序列】
【Leetcode -657.机器人能否返回原点 -674.最长连续递增序列】
20 0
|
4月前
|
算法 测试技术 C#
C++单调向量算法:得到山形数组的最少删除次数
C++单调向量算法:得到山形数组的最少删除次数
|
8月前
|
算法 索引
算法训练Day36|435. 无重叠区间 ● 763.划分字母区间 ● 56. 合并区间
算法训练Day36|435. 无重叠区间 ● 763.划分字母区间 ● 56. 合并区间
|
8月前
|
监控 算法
算法训练Day37|738.单调递增的数字 ● 968.监控二叉树
算法训练Day37|738.单调递增的数字 ● 968.监控二叉树
|
9月前
|
传感器
通过求解数学模型来选择编码节点的最佳数量和位置(Matlab代码实现)
通过求解数学模型来选择编码节点的最佳数量和位置(Matlab代码实现)
通过求解数学模型来选择编码节点的最佳数量和位置(Matlab代码实现)
|
10月前
m 序列(最长线性反馈移位寄存器序列)详解
m 序列(最长线性反馈移位寄存器序列)详解
248 0
|
11月前
求给定精度的简单交错序列部分和
求给定精度的简单交错序列部分和
65 0
|
Python
LeetCode 5881. 增量元素之间的最大差值
给你一个下标从 0 开始的整数数组 nums ,该数组的大小为 n ,请你计算 nums[j] - nums[i] 能求得的 最大差值 ,其中 0 <= i < j < n 且 nums[i] < nums[j] 。
77 0

热门文章

最新文章