DB2联机移动表——admin_move_table

简介:

来自文档:admin_move_table过程

1.ADMIN_MOVE_TABLE 过程-在线移动表

ADMIN_MOVE_TABLE存储过程将数据从一个活动表 移动到一个相同名称的新表对象中,而被移动的这个表在这个过程中是联机且可以被访问的。这个存储过程创建一个协议表(protocol table),这个协议表由包含 与将被移动的表相关的 状态信息和配置选项 构成。这个过程的返回集是 行集合,该行集合 来自 与将要被移动的表相关的 协议表 。

这个存储过程使用下列的术语(terminology):

  • 源表Source table

    传入到存储过程参数中的原始表名称。是将被移动的表的名称。
    
  • 目标表Target table

    存储过程使用存储过程内部传入的表定义创建的表。源表中的所有数据都被拷贝到这个目标表中,然后这个目标表被命名成与源表相同的名称。
    
  • 阶段表Staging table

    一个由存储过程创建的表。这个staging table存储所有的更新——在移动表的过程中发生在源表上的update、delete和insert操作,在移动完成之后这个表被删除。
    

语法

有两种等效的方式来启动ADMIN_MOVE_TABLE存储过程:

  • 使用第一种方法来修改 目标表的表定义的一些确定的内容。例如,如果你有一个表,表定义很大(几KB大小),但是你想做的仅仅是修改表的表空间,你可以这样做:不一定要决定需要去重建源表的整个CREATE TABLE 语句,你只需要找出data_tbsp(数据表空间)、索引表空间和大对象表空间参数,让其他的可选参数为空。
  • 第二种方法让你有更多控制性和灵活性。你可以预先创建目标表,而不是让存储过程创建目标表。通过预先创建目标表,你可以创建一个使用第一种方法不能创建的表。

第一种方法的语法:

>>-ADMIN_MOVE_TABLE--(--tabschema--,--tabname--,---------------->

>--data_tbsp--,--index_tbsp--,--lob_tbsp--,--------------------->

>--organize_by_clause--,--partkey_cols--,--data_part--,--------->

              .---------.                    
              V         |                    
>--coldef--,----options-+--,--operation--)---------------------><

第二种方法的语法:

>>-ADMIN_MOVE_TABLE--(--tabschema--,--tabname--,---------------->

                      .---------.                    
                      V         |                    
>--target_tabname--,----options-+--,--operation--)-------------><

方法的模式名为: SYSPROC.

过程参数

tabschema

大小写敏感。This input parameter specifies the name of the schema which contains the table to be moved. This parameter is case sensitive and has a data type of VARCHAR(128).

tabname

This input parameter specifies the name of the table to be moved. This parameter is case sensitive and has a data type of VARCHAR(128)

data_tbsp

这个参数指明了目标表的新的数据表 空间( the new data table space for the target table)。如果提供了值,index_tbsp 和 lob_tbsp也需要提供。如果没有提供了值,将使用源表的数据表空间。This parameter is case sensitive and has a data type of VARCHAR(128). This parameter can be NULL or the empty string.
  • index_tbsp
  • lob_tbsp
  • organize_by_clause
  • partkey_cols
  • data_part
  • coldef

     这个参数指明了 目标表的新的列定义,允许你改变列的类型以及兼容性,但是列名必须保持一致
    
    这也提供了添加新列还删除已经存在的列的功能,当添加新列时,必须定义为允许空或者有默认值。同样,只有在表上有唯一索引或主键索引的情况下才能删除列,并且被删除的列不是唯一索引或逐渐索引的组成部分。这个参数数据类型为VARCHAR(32672),可以为NULL或空字符串。
    
    Example: 'C1 INT, C2 INT DEFAULT 0'

目标表名称

这个参数提供一个移动过程中被用来作为目标表的已经存在的表名称。可以对传入的目标表做下面的改变:

  • 数据、索引和大对象表空间可以被改变
  • 多维列 specification 可以被添加或改变(multi dimensional column (MDC) )
  • 分区键列 specification 可以被添加或删除
  • 数据分区specification 可以被添加或删除
  • 数据压缩可以被添加或删除
  • 可以指定一个新的列定义;但是 当指定一个列定义参数 有 相同的限制(however the same restrictions as when specifying the coldef parameter apply here).

下面的限制适用于命名的表:

  • 表与源表必须存在于同一模式下
  • 空必须是空表
  • 类型表(typed tables), 物化查询表, staging tables, 远程表或集群表是不允许的
  • 表不能有参考约束(reference constraints)

如果这个参数被设置为NULL或空字符串,存储过程使用与源表相同的表定义。大小写敏感,varchar(128).

options

这个输入参数是 由逗号分隔开的字符串,这个字符串定义了存储过程用到的选项。选项的列表大小写不敏感,varchar(32672)。可以为NULL或空字符串。下面的值是有效的:

KEEP

这个选项以一个不同的表名称来保留原始表的备份,如果源表的名称是T1,那么在数据移动完成之后表会被自动重命名为类似 T1AAAAVxo的名称.在返回的协议表中你可以得到这个准确的名称, under the ORIGINAL key。 You may set this option at any point up to and including the SWAP phase.

COPY_USE_LOAD "<load option>"

COPY_USE_LOAD的语法
.-NONRECOVERABLE--------------------------------------------------.   
>>-+--------------------+--+-----------------------------------------------------------------+-><
   '-MESSAGES ON SERVER-'  '-COPY----YES--+-USE TSM--+--------------------------+--------+---'   
                                          |          '-OPEN--num-sess--SESSIONS-'        |       
                                          |     .-,----------------.                     |       
                                          |     V                  |                     |       
                                          +-TO----device/directory-+---------------------+       
                                          '-LOAD--lib-name--+--------------------------+-'       
                                                            '-OPEN--num-sess--SESSIONS-'         

如果你为COPY_USE_LOAD指定任何的load选项,ADMIN_MOVE_TABLE 使用一个ADMIN_CMD load来将数据从源表拷贝到目标表中,如果你不指定任何选项,那么 NONRECOVERABLE 选项 db2load API被用来 将数据从源表拷贝到目标表中。 在早于DB2 9.7的版本中, 如果使用了COPY_USE_LOAD那么就一定要指定 FORCE选项。

  • MESSAGES ON SERVER
  • COPY YES
    声明loaded 数据的一份拷贝是否要保存。如果前滚恢复被禁用那么这个选项无效
USE TSM: 使用 Tivoli® Storage Manager (TSM)来存储备份
OPEN *num-sess* SESSIONS:I/O会话的数量,默认是1
TO device or directory:拷贝被创建到那个设备或路径
LOAD *lib-name*:
  • NONRECOVERABLE

COPY_WITH_INDEXES

这个选项在拷贝源表之前先创建索引,相对来说,默认是拷贝表完成之后创建索引的。这个选项的好处就是拷贝之后建索引时每个索引都需要进行一次全表扫描,而索引创建是一个事务需要活动日志空间。 如果 logindexbuild数据库配置参数是打开的,建立索引 将导致在短时间内需要大量的日志空间。这个选项的一个缺点就是拷贝性能会被降低因为需要同时维护目标表上的索引。同时,得到的索引 包含很多已经标记删除了的键,索引不像 拷贝之后建的索引 那样保持平衡。你可以 在任何时候包括SWAP阶段 设置COPY_WITH_INDEXES 选项 .

FORCE

如果设置了Force option,SWAP 段将不会检查 源表的表定义是否发生改变。 在DB29.7版本之前,如果使用了COPY_USE_LOAD,FORCE选项必须被指定。你可以 在任何时候包括SWAP阶段 设置这个选项.

NO_STATS

这个选项不启用目标表的RUNSTATS或其他统计拷贝。如果你使用了AUTO_RUNSTATS数据库配置参数,DB2随后将自动创建新的统计信息。针对回退能力(For backwards compatibility),STATS_NO 也接受。你可以 在任何时候包括SWAP阶段 设置这个NO_STATS选项.

COPY_STATS

这个选项在执行交换之前 从源表拷贝统计信息 到目标表 。 这可能引起不准确的物理统计,尤其是在页大小改变的情况下。但是,设置这个选项可以节约计算时间 因为将不会调用RUNSTATS来计算新的统计信息。当然,优化器可能会选择相同的访问计划,因为统计信息时相同的。倒过来书写的顺序 STATS_COPY 也可以识别。你可以 在任何时候包括SWAP阶段 设置 STATS_COPY 选项.

NO_AUTO_REVAL

这个选项阻止表的自动重新生效,取而代之的是,重建所有触发器和视图。只可以在INIT阶段 设置 NO_AUTO_REVAL选项。

  • REORG
    这个选项在执行交换之前 在目标表上 创建了一个额外的离线REORG。如果你使用这个选项来改善你的 压缩字典, 建议使用默认 样板 方法 是一个更好的创建 最佳压缩字典的方法(If you use this option to improve your compression dictionary, be advised that using the default sampling approach is a better method to create an optimal compression dictionary.)。但是,如果你需要一个最佳的XML压缩字典,REORG是唯一的方法。你可以 在任何时候包括SWAP阶段 设置REORG选项 在任何时候包括SWAP阶段。
  • NO_TARGET_LOCKSIZE_TABLE
    这个选项 在COPY和SWAP阶段 不保留 目标表上的 LOCKSIZE表选项。 默认在目标表上 使用LOCKSIZE表选项 来组织锁overhead, 当没有在目标上指定唯一索引时。

CLUSTER

This option reads the data from the source table with an ORDER BY clause when a copy index has been specified using ADMIN_MOVE_TABLE_UTIL, a clustering index exists on the source table or a unique index or primary key is defined in the source table.

注:

A copy index will override a clustering index; a clustering index will be used in preference to a primary key; a primary key will be used in preference to a unique index.

  • NON_CLUSTER

        This option reads the data from the source table without an ORDER BY clause regardless of whether a copy index has been specified, a clustering index exists on the source table, or a unique index or primary key has been defined in the source table.

注:

  • LOAD_MSGPATH
    This option can be used to define the load message file path.
    LOAD_MSGPATH can be used together with COPY_USE_LOAD in the following situations:

    • COPY_USE_LOAD is specified without further options (in other words, the default COPY_USE_LOAD NONRECOVERABLE is assumed)
    • COPY_USE_LOAD NONRECOVERABLE is specified explicitly

    LOAD_MSGPATH cannot be used together with COPY_USE_LOAD when optional keywords are also specified with COPY_USE_LOAD.

    If the LOAD_MSGPATH option is not specified, then the default path is determined by the DB2_UTIL_MSGPATH registry variable.

  • LOAD_TEMPPATH
    Use this option to define the load temporary file path.

    This option is available starting in DB2 Version 10.1 Fix Pack 4.

  • ALLOW_RLBAC
    Use this option to move a table that has row-level label-based access control (LBAC) security label specified. Before you use this option, ensure that you have adequate privilege; if you lack the privilege to access all the table row entries, data loss can occur.

    This option is available starting in DB2 Version 10.1 Fix Pack 4.

操作

This input parameter specifies which operation the stored procedure is to execute. There are two ways of calling the stored procedure: using the MOVE command to execute all the operations at one time; or by using the individual commands to execute the table move one step at a time. The main advantage of this second method is that you control when the SWAP phase actually occurs, thereby determining when the table is briefly taken offline. This allows you to make the move during a period of low system activity. If you use the individual commands, they must be called in the following order: INIT, COPY, REPLAY, VERIFY (optional), and SWAP.

  • MOVE: Performs the entire table move (INIT, COPY, REPLAY, and SWAP operations) in one step.
  • INIT: 验证能够进行表移动,然后 初始化所有 在表移动过程中 需要的数据 (目标表、staging表、源表上的触发器)
  • COPY: 将内容从源表拷贝到目标表中去。在这个拷贝的阶段中发生的对源表的更改(update、delete、insert) 存储到staging table中,在拷贝阶段结束时创建新索引,除非指定了COPY_WITH_INDEXES选项。当然,如果需要的话,会在源表和目标表上创建辅助索引来改善RELAY阶段的性能。只能够在INIT阶段完成后使用COPY操作。
  • REDIRECT: Forwards changes directly to the target table instead of capturing the changes in the staging table.

Note

    For tables with XML columns, the REDIRECT command does not work on multi-partitioned systems on tables that do not have a unique index.
  • REVERT: Reverts to the original behavior wherein the staging table captures the changes.
  • REPLAY: Copies into the target table any rows that have changed in the source table since the COPY phase began. REPLAY can be used only after the COPY phase has completed.
  • VERIFY: 可选择的,检查源表的内容和目标表内容是否一致。这个过程会获得源表和目标表上的S锁, 重放发生在源表上的更改,然后进行比较。如果表有一个唯一索引,这个命令比较两个表中都有的列的所有值。否则,这个命令比较 两个表中形同的列的值(除了LONG、LOB和XML列)。这个操作的代价比较大,注意应该小心的决定这个比较对于你的移动来说是否是必要的。VERIFY只能在COPY和RELAY阶段之后调用。
  • SWAP: Executes the REPLAY phase until the number of changes applied during the last scan of the staging table is less than the REPLAY_THRESHOLD value stored in the protocol table. The source table is then taken offline briefly to finish the final REPLAY, and then this command swaps the source table with target table and brings the table back online. SWAP can be used after the COPY phase has completed, but ideally after the REPLAY phase has been called.
  • CLEANUP: Drops the staging table, any non-unique indexes or triggers created on the source table by the stored procedure, and the source table if the KEEP option has not been set. CLEANUP can be called if the command failed during the SWAP phase.
  • CANCEL: Cancels a multi-step table move while between phases, or cancels a failed table move operation. Executing this command requires that the operation status is not in COMPLETED or CLEANUP state. CANCEL clears up all intermediate data (the indexes, the staging table, the target table, and the triggers on the source table).

    This parameter is not case sensitive and has a data type of VARCHAR(128).
    

Authorization

你必须有SQLADM或DBADM权限来引用ADMIN_MOVE_TABLE存储过程。你必须有合适的对象创建权限,包括在源表上执行SELECT语句、在目标表上执行insert语句的权限。

默认PUBLIC

在一个非严格的数据库中,当存储过程被自行创建时,EXECUTE特权被赋权为PUBLIC。

Examples

这个实例使用第一种放调用存储过程, 这种方式 目标表在存储过程中定义,移动一个位于模式SVALENT1下的名为T1的表。

CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',       --tabschema
'T1',             --tabname
'ACCOUNTING',      --data_tbsp
'ACCOUNT_IDX',     --index_tbsp
'ACCOUNT_LONG',    --lob_tbsp
'',                --organize_by_clause--
'',                --partkey_cols-
'',                --data_part--
'CUSTOMER VARCHAR(80), REGION CHAR(5), YEAR INTEGER, CONTENTS CLOB',    ----coldef
'',               --V.options
'MOVE'             --operation
)

下面是这个过程的一个输出的示例:

Result set 1
------------

KEY                          VALUE
------------------------     -------------------------------------
AUTHID                       SVALENTI
CLEANUP_END                  2009-02-13-11.34.07.609575
CLEANUP_START                2009-02-13-11.34.07.369331
COPY_END                     2009-02-13-11.34.05.148018
COPY_OPTS                    BY_KEY,OVER_INDEX
COPY_START                   2009-02-13-11.34.04.841292
COPY_TOTAL_ROWS              100
INDEXNAME                    T1_INDEX
INDEXSCHEMA                  SVALENTI
INDEX_CREATION_TOTAL_TIME    0
INIT_END                     2009-02-13-11.34.04.552875
INIT_START                   2009-02-13-11.34.03.013563
PAR_COLDEF                   CUSTOMER VARCHAR(80), REGION CHAR(5), 
                                 YEAR INTEGER, CONTENTS CLOB
REPLAY_END                   2009-02-13-11.34.06.198369
REPLAY_START                 2009-02-13-11.34.05.164582
REPLAY_TOTAL_ROWS            100
REPLAY_TOTAL_TIME            5
STATUS                       COMPLETE
SWAP_END                     2009-02-12-11.34.07.214447
SWAP_RETRIES                 0
SWAP_START                   2009-02-13-11.34.06.244506
VERSION                      09.07.0000

22 record(s) selected.

Return Status = 0

下面这个例子使用第二种方式调用了存储过程,这种方式里面目标表是外部创建的,然后 传入target_tabname参数,用来移动同名表,和第一个例子中一样:
(1).第一步:首先手工创建表:

CREATE TABLE SVALENTI.T1_TARGET (
   CUSTOMER VARCHAR(80), 
   REGION CHAR(5), 
   YEAR INTEGER, 
   CONTENTS CLOB) 
IN ACCOUNTING 
INDEX IN ACCOUNT_IDX 
LONG IN ACCOUNT_LONG'

(2).然后调用存储过程传入目标表的名称:

CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',       --tabschema
'T1',             --tabname
'T1_TARGET',      --target_tabname
'',               --V.options
'MOVE',          --operation
)

下面是这个过程的一个输出的示例:

Result set 1
------------

KEY                          VALUE
------------------------     -------------------------------------------
AUTHID                       SVALENTI
CLEANUP_END                  2009-02-13-11.37.49.283090
CLEANUP_START                2009-02-13-11.37.49.125786
COPY_END                     2009-02-13-11.37.47.806060
COPY_OPTS                    BY_KEY,OVER_INDEX
COPY_START                   2009-02-13-11.37.47.446616
COPY_TOTAL_ROWS              0
INDEXNAME                    T1_INDEX
INDEXSCHEMA                  SVALENTI
INDEX_CREATION_TOTAL_TIME    1
INIT_END                     2009-02-13-11.37.47.287703
INIT_START                   2009-02-13-11.37.46.052952
PAR_COLDEF                   using a supplied target table so COLDEF 
                                 could be different
REPLAY_END                   2009-02-13-11.37.48.785503
REPLAY_START                 2009-02-13-11.37.47.822109
REPLAY_TOTAL_ROWS            0
REPLAY_TOTAL_TIME            0
STATUS                       COMPLETE
SWAP_END                     2009-02-13-11.37.48.977745
SWAP_RETRIES                 0
SWAP_START                   2009-02-13-11.37.48.825228
VERSION                      09.07.0000
22 record(s) selected.

Return Status = 0

Usage notes 使用的注意事项

1. 使用该过程的建议for best results

  • 避免同时移动到相同的表空间,这样可以避免目标表上的空间碎片。
  • 在表上的低活期运行该过程。避免使数据负载聚集或删除,从而并行读访问不会造成问题(Avoid mass data loads or deletes so that parallel read access is not a problem) .
  • 使用多步骤移动操作。INIT和COPY阶段可以在任何时候调用。多次执行RELAY阶段来保持staging table的表在较小的水平,然后在表业务的低峰期执行swap操作。
  • 检查确认是否对你的表移动需求来说离线移动是一个更好的办法,尤其是 要顾虑 没有唯一索引的表和没有索引的表。

2. 在源表上受限的操作

  • 存储过程依赖触发器来捕获源表上的更改。但是有一些对表的更改操作不会触发触发器。这将导致源表和目标表之间的不一致,而且不容易被存储过程探测到,这些操作包含:

    • TRUNCATE TABLE (without restrict when delete triggers)
    • IMPORT ... REPLACE INTO ...
    • LOAD TABLE
    • ALTER TABLE
    • REORG (both online and offline)

这些在源表上的操作是受限的,并且使用一个新的表级别的状态标签。这个标签被 在INIT阶段 设置 ,在cleanup或cancel阶段被清空。受限操作会失败,返回码:SQL0668N reason code 10 (sqlstate 57016).

3.会影响表移动的操作

在移动正在进行的时候,有一些操作会引起存储过程的失败。这些操作包括:

  • 删除 SYSTOOLSPACE (系统工具)表空间
  • 删除或重命名
  • 删除或重命名任何由OTM在INIT阶段创建的临时对象(目标表,阶段表,源表上的触发器,协议表)
  • 修改协议表中非用户可配置的值

4.临时对象的命名惯例

为避免创建临时对象时的命名冲突,使用下面的命名惯例:

  • Postfix后缀

    • "t" 目标
    • "s" for staging
    • "o" 原始的,初始的
    • "g" for generated
    • "i" for insert trigger
    • "d" for delete trigger
    • "u" for before update trigger
    • "v" for after update trigger
  • Names are built consisting of <characters from name of object><base64 encoded hash key over name of object><postfix>.
  • If length of name would exceed object length (128 bytes) <characters from name of object> gets shorter.
  • Hash value gets calculated from the object name and is encoded similar to base64 encoding.

示例

Name of object: T1 
Staging object: T1AAAAVxs
Target object: T1AAAAVxt 
Original object: T1AAAAVxo 
Generated index: T1AAAAVxg (if table has no index) 
Insert trigger: T1AAAAVxi 
Delete trigger: T1AAAAVxd 
Before update trigger: T1AAAAVxu 
After update trigger: T1AAAAVxv

压缩和字典创建的方式 在线表移动

There are several methods to create a data compression dictionary using Online Table Move. Compression must either be enabled on the source table or specified to be active in the new table definition if provided.

Create dictionary with sampling is the default method of Dictionary creation through Online Table Move. If compression is turned on for the table, then before performing the COPY operation, a Bernoulli sampling of the data from the source table is inserted into the target table, where the amount of data sampled is specified in the DEEPCOMPRESSION_SAMPLE field in the protocol table. The compression dictionary is then created based off of this random sample, and therefore results in an optimal compression dictionary.

Please note, that an XML compression dictionary will not be created through the sampling method. This is due to the fact that db2Inspect is used to create the compression dictionary, and db2Inspect currently does not have the ability to create an XML compression dictionary. The XML compression dictionary will be created through automatic dictionary creation (ADC).

Create dictionary with automatic dictionary creation (ADC) is the standard method of Dictionary creation with tables in DB2. By simply turning on compression for the table, DB2 will automatically create the dictionary as data is inserted into the table. This will result in a non-optimal compression dictionary. Please note that the DEEPCOMPRESSION_SAMPLE field in the protocol table will have to be set to 0 to avoid having the stored procedure attempt to create a better compression dictionary.

The create dictionary with REORG method of Dictionary creation results in a dictionary being created that reflects any activity on the source table that occurred while the COPY phase was in process. This is done by performing a REORG before the SWAP phase with the RESETDICTIONARY option set. An optimal dictionary will be created, however depending on the size of the table the REORG could take a long time. Also, if an optimal XML dictionary is required, REORG is the only method that will produce one. It is advised to use the sampling method of dictionary creation.

来自文档:通过使用 ADMIN_MOVE_TABLE 过程来以联机方式移动表

2.通过使用 ADMIN_MOVE_TABLE 过程来以联机方式移动表

  可通过使用 ADMIN_MOVE_TABLE 过程来以联机脱机方式移动表。如果相对于成本、空间、移动性能和事务开销,您更重视可用性,请使用表的联机移动而不是表的脱机移动。

开始之前

  请确保有足够的磁盘空间来容纳表和索引的副本、登台表以及附加日志条目(accommodate the copies of the table and index, the staging table, and the additional log entries.)。

关于此任务

  可通过调用存储过程一次或多次来以联机方式移动表,该过程执行的每个操作都对应一次调用。使用多个调用允许您有其他选择,例如,取消移动或控制何时使目标表脱机以进行更新。

  当调用 SYSPROC.ADMIN_MOVE_TABLE 过程时,会:

  1. 创建源表的影子副本(shadow table) 在哪里?
  2. 在复制阶段期间,会使用触发器来捕获对源表的更改(更新、插入或删除)并将其放置到staging table中
  3. 当复制阶段完成后,会对影子副本重放登台表(staging table)中捕获的更改。
  4. 存储过程会迅速使源表脱机并将源表名称和索引名称指定给影子副本及其索引。这一步中的锁定情况,以及索引的重组情况?
  5. 然后,使影子表联机,从而替换源表。缺省情况下,会删除源表,但可以使用 KEEP 选项来以另一个名称保留该源表。

注意:对于不带索引(特别是唯一索引)的表,请不要执行联机移动。对不带唯一索引的表执行联机移动可能导致死锁和复杂或费用很高的重放。
就是说,如果要执行联机索引,那么最好是唯一索引,没有唯一索引的表执行联机移动可能导致死锁和复杂或费用很高的重放,为什么?

  用于存放对源表的冲突锁定的应用程序可能会失败,且返回原因码 SQL0911N 68,因为 ADMIN_MOVE_TABLE 更有可能会在锁定超时冲突中成功。要在 SWAP 操作期间防止死锁,可使用 FORCE_ALL 选项。请参见 FORCE_ALL 以获取更多详细信息。

过程

要以联机方式移动表,请执行下列步骤:

1.采用下列其中一种方式调用 ADMIN_MOVE_TABLE 过程:

    • 调用 ADMIN_MOVE_TABLE 过程一次,并至少指定源表的模式名称、源表名称以及操作类型 MOVE。例如,使用以下语法将数据移到同一表空间内的现有表中:
        CALL SYSPROC.ADMIN_MOVE_TABLE (
        'schema name',         --源表的模式名称
        'source table',         --源表名称
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        'MOVE'              --操作类型MOVE
        )
    • 调用 ADMIN_MOVE_TABLE 过程多次(每个操作都对应一次调用),并至少指定源表的模式名称、源表名称以及操作名称。例如,使用以下语法将数据移到同一表空间内的新表中:
        CALL SYSPROC.ADMIN_MOVE_TABLE (
        'schema name',
        'source table',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        'operation name')

  其中 operation name 为下列值之一:INIT、COPY、REPLAY、VERIFY 和 SWAP。必须按照此操作顺序调用该过程,例如,在第一次调用中必须指定 INIT 作为操作名称。

  注:
    VERIFY 操作的费用很高;仅当需要时才针对表移动执行此操作。

2.如果联机移动失败,那么重新运行该移动:

  1. 解决导致表移动失败的问题。
  2. 通过查询 SYSTOOLS.ADMIN_MOVE_TABLE 协议表以了解状态来确定表移动失败时正在进行的阶段。
  3. 再次调用存储过程,并指定适用选项:
  • 如果过程的状态为 INIT,那么使用 INIT 选项。
  • 如果过程的状态为 COPY,那么使用 COPY 选项。
  • 如果过程的状态为 REPLAY,那么使用 REPLAY 或 SWAP 选项。
  • 如果过程的状态为 CLEANUP,那么使用 CLEANUP 选项。
  • 如果表的联机移动状态不是 COMPLETED 或 CLEANUP,那么可以通过对存储过程指定 CANCEL 选项来取消该移动。

示例

示例 1:在不使 T1 脱机的情况下,将 T1 表从模式 SVALENTI 移到 ACCOUNTING 表空间中。指定 DATA、INDEX 和 LONG 表空间以将表移动到新的表空间。

CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',
'T1',
'ACCOUNTING',   --data_tbsp
'ACCOUNTING',    --index_tbsp
'ACCOUNTING',    --lob_tbsp
'', 
'', 
'', 
'',
'',
'MOVE')   

示例 2:在不使 T1 脱机的情况下,将 T1 表从模式 EBABANI 移到 ACCOUNTING 表空间中,并且在移动后保留原始表的副本。使用 COPY_USE_LOAD 和 LOAD_MSGPATH 选项来设置装入消息文件路径。指定 DATA、INDEX 和 LONG 表空间以将表移动到新的表空间。原始表将保持类似于 'EBABANI'.'T1AAAAVxo' 的名称。

CALL SYSPROC.ADMIN_MOVE_TABLE(
'EBABANI', 
'T1',
'ACCOUNTING',
'ACCOUNTING',
'ACCOUNTING',
'', 
'', 
'', 
'',
'KEEP, COPY_USE_LOAD,LOAD_MSGPATH "/home/ebabani"',
'MOVE')

示例 3:在同一表空间中移动 T1 表。将 T1 中的 C1 列(使用不推荐的数据类型 LONG VARCHAR)更改为使用兼容的数据类型。

CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',
'T1',
'',
'',
'',
'',
'',
'',
'C1 VARCHAR(1000), C2 INT(5), C3 CHAR(5), C4 CLOB',
'',
'MOVE')

示例 4:您通过以下语句创建 T1 表:

CREATE TABLE T1(C1 BIGINT,C2 BIGINT,C3 CHAR(20),C4 DEC(10,2),C5 TIMESTAMP,C6 BIGINT 
        GENERATED ALWAYS AS (C1+c2),C7 GRAPHIC(10),C8 VARGRAPHIC(20),C9 XML

在同一表空间内移动该表,并删除列 C5 和 C6:

CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',
'T1',
'',
'',
'',
'', 
'', 
'', 
'c1 BIGINT,c2 BIGINT ,c3 CHAR(20),c4 DEC(10,2),c7 GRAPHIC(10),
c8 VARGRAPHIC(20),c9 XML',
'', 
'MOVE')   

示例 5:您的范围分区表具有表空间 TS1 和 TS2 中定义的两个范围。将该表移至表空间 TS3,但保留 TS1 中的第一个范围。

CREATE TABLE "EBABANI "."T1"  (
        "I1" INTEGER , 
        "I2" INTEGER )   
         DISTRIBUTE BY HASH("I1")   
        PARTITION BY RANGE("I1") 
        (PART "PART0" STARTING(0) ENDING(100) IN "TS1", 
        PART "PART1" STARTING(101) ENDING(MAXVALUE) IN "TS2"); 

将 T1 表从模式 EBABANI 移至 TS3 表空间。指定分区定义。

DB2 "CALL SYSPROC.ADMIN_MOVE_TABLE 
('EBABANI',
'T1',
'TS3',
'TS3',
'TS3',
'',
'',
'(I1) (STARTING 0 ENDING 100 IN TS1 INDEX IN TS1 LONG IN TS1, STARTING 101
ENDING MAXVALUE IN TS3 INDEX IN TS3 LONG IN TS3)',
'',
'',
'MOVE')"

ONLINE REORG TABLE

进行到哪一步就不能回滚了?

Z锁以及操作Z锁的影响

相关文章
|
9月前
|
SQL Oracle 关系型数据库
Oracle 使用DB link update table & TNS:linstener was not given the servicename in connect_data处理方式
业务需求:需要在Oracle1 的A表增加一个字段,这个字段来自于Oracle2 的B表的一个字段。
68 0
|
关系型数据库 MySQL 数据库
mysql中的update(更新)与alter(更改)以及 change和modify的区别
mysql中的update(更新)与alter(更改)以及 change和modify的区别
1162 0
|
SQL XML Oracle
Oracle Database 19c 中的自动索引 (DBMS_AUTO_INDEX)
Oracle 数据库 19c 引入了自动索引功能,它可以让您将一些有关索引管理的决策交给数据库。
|
Oracle 关系型数据库 测试技术

相关实验场景

更多