The ADMIN_MOVE_TABLE stored procedure moves the data in an active table into a new table object with the same name, while the data remains online and available for access.
This stored procedure creates a protocol table composed of rows that contain status information and configuration options related to the table to be moved. The return set from this procedure is the set of rows from the protocol table related to the table to be moved.
You must have SQLADM or DBADM authority to invoke the ADMIN_MOVE_TABLE stored procedure. You must also have the appropriate object creation authorities, including authorities to issue the SELECT statement on the source table, and to issue the INSERT statement on the target table.
In a non-restrictive database, EXECUTE privilege is granted to PUBLIC when the procedure is automatically created.
Method 1:
>>-ADMIN_MOVE_TABLE--(--tabschema--,--tabname--,----------------> >--data_tbsp--,--index_tbsp--,--lob_tbsp--,---------------------> >--organize_by_clause--,--partkey_cols--,--data_part--,---------> .---------. V | >--coldef--,----options-+--,--operation--)---------------------><
Method 2:
>>-ADMIN_MOVE_TABLE--(--tabschema--,--tabname--,----------------> .---------. V | >--target_tabname--,----options-+--,--operation--)-------------><
The schema for both methods is SYSPROC.
Example 1: 'C1, C4, (C3,C1), C2'
Example 2: ORGANIZE BY INSERT TIME
Example: 'C1, C3'
Example: '(C1) (STARTING FROM (1) EXCLUSIVE ENDING AT (1000) EVERY (100))'
This also provides the ability to add new columns and drop existing columns. When adding a column, it must be defined as either nullable or have a default value set. Also, a column can only be dropped if there is a unique or primary index on the table and the column to be dropped is not a part of that unique or primary index. This parameter has a data type of VARCHAR(32672). This parameter can be NULL or the empty string.
Example: 'C1 INT, C2 INT DEFAULT 0'
If this parameter is set to NULL or the empty string, the stored procedure uses the same definition as the source table. This parameter is case sensitive and has a data type of VARCHAR(128).
Syntax for 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-'
If you specify any load options for COPY_USE_LOAD, ADMIN_MOVE_TABLE uses an ADMIN_CMD load to copy the data from the source table to the target table. If you do not specify any options for COPY_USE_LOAD, then the NONRECOVERABLE option the db2Load API is used to copy the data from the source table to the target table. In releases earlier than DB2® Version 9.7 Fix Pack 2, the FORCE option must be specified if COPY_USE_LOAD is used.
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.
This option is available starting in DB2 Version 10.5 Fix Pack 3.
This option is available starting in DB2 Version 10.5 Fix Pack 3.
Column name | Data type | Description |
---|---|---|
TABSCHEMA | VARCHAR(128) | table_schema - Table schema name monitor element |
TABNAME | VARCHAR(128) | table_name - Table name monitor element |
KEY | VARCHAR(32) | Name of the attribute. |
VALUE | CLOB(10M) | Value of the attribute. |
The key and value pairs that are returned in the result set can be found in Table 2. To modify the user configurable keys in the result set, use the ADMIN_MOVE_TABLE_UTIL stored procedure.
Key | Return Value | User Configurable |
---|---|---|
AUTHID | Displays the authorization ID of the user who called the stored procedure. | No |
CLEANUP_END | Displays the CLEANUP phase end time. | No |
CLEANUP_START | Displays the CLEANUP phase start time. | No |
COMMIT_AFTER_N_ROWS | During the COPY phase, a commit is executed after this many rows are copied. 0 means no commits during COPY. Default value is 10000. | Yes |
COPY_ARRAY_SIZE | Specifies the ARRAY size for COPY_ARRAY_INSERT. A value less than or equal to 0 means do not use COPY_ARRAY_INSERT. Default value is 100. | Yes |
COPY_END | Displays the COPY phase end time. | No |
COPY_INDEXNAME | The name of the index used to cluster the data on the target table during the COPY phase. This value must be set before the COPY phase. The default name is the name of a cluster index on the source table, if it exists; otherwise the name of the unique or primary index on the source table. | Yes |
COPY_INDEXSCHEMA | The schema of the index used to cluster the data on the target table during the COPY phase. This value must be set before the COPY phase. The default schema is the schema name of a cluster index on the source table, if it exists; otherwise the schema name of the unique or primary index on the source table. | Yes |
COPY_OPTS | The copy options used during the COPY phase. | No |
COPY_START | Displays the COPY phase start time. | No |
COPY_TOTAL_ROWS | Displays the total number of rows copied during the COPY phase. | No |
DEEPCOMPRESSION_SAMPLE | If the source table has compression enabled, this field specifies how much data (in KB) is sampled when creating a dictionary for compression. 0 means no sampling is done. Default value is 20MB (20480 KB). | Yes |
INDEX_CREATION_TOTAL_TIME | Displays the total time required for creating secondary indexes. | No |
INDEXNAME | Displays the name of the index or the empty string if the table does not have an index. | No |
INDEXSCHEMA | Displays the schema of the index or the empty string if the table does not have an index. | No |
INIT_END | Displays the INIT phase end time. | No |
INIT_START | Displays the INIT phase start time. | No |
LOCK | Displays the LOCK start time if another online table move stored procedure call is active, otherwise it is empty. | No |
ORIGINAL | Displays the name of original table after the swap. | No |
REORG_USE_TEMPSPACE | If you call the REORG option, you can also specify a temporary table space for the USE clause of the REORG command. If a value is not specified here, the REORG command uses the same table space as the table being reorganized. | Yes |
REPLAY_END | Displays the REPLAY phase end time. | No |
REPLAY_MAX_ERR_RETRIES | Specifies the maximum retry count for errors (lock timeouts or deadlocks) that may occur during the REPLAY phase. Default value is 100. | Yes |
REPLAY_START | Displays the REPLAY phase start time. | No |
REPLAY_THRESHOLD | For a single iteration of the REPLAY phase, if the number of rows applied to the staging table is less than this value, then REPLAY stops, even if new entries are made in the meantime. Default value is 100. | Yes |
REPLAY_TOTAL_ROWS | Displays the accumulated number of replayed rows. | No |
REPLAY_TOTAL_TIME | Displays the accumulated time in seconds used for replaying rows. | No |
STAGING | Displays the name of the staging table. | No |
STATUS | Displays the current status of the online table
move:
|
No |
SWAP_END | Displays the SWAP phase end time. | No |
SWAP_MAX_RETRIES | Specifies the maximum number of retries allowed during the SWAP phase (if lock timeouts or deadlocks occur). Default value is 10. | Yes |
SWAP_RETRIES | Displays the number of retries performed during SWAP phase. | No |
SWAP_START | Displays the SWAP phase start time. | No |
TARGET | Displays the name of the target table. | No |
UTILITY_INVOCATION_ID | Displays the unique identifier for the table move operation. | No |
VERIFY_END | Displays the verification end time. | No |
VERIFY_START | Displays the verification start time. | No |
VERSION | Displays the version of the stored procedure. | No |
WARNINGS | Displays warnings to pass on to the user. These
warnings include:
|
No |
Sample:
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 system 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.
If you use the COPY_USE_LOAD option and the source table has a statistics profile, the load operation collects statistics on the target table.
By default, when you are moving a table where statistics are collected, the RUNSTATS command is issued on the table during the SWAP phase. The ADMIN_MOVE_TABLE procedure attempts to create statistics only if the target table does not yet have any statistics. If the target table does not yet have statistics and you want to minimize the duration of the SWAP phase, issue the RUNSTATS command before the SWAP phase. If a statistics profile is found, the RUNSTATS command is called by using the statistics profile. Otherwise, the RUNSTATS command is called with the WITH DISTRIBUTION ON COLUMNS (...) and AND SAMPLE DETAILED INDEXES ALL clauses.
If the COPY_STATS option has been set, the statistics from the source table are copied to the target table before performing the swap. Copying statistics may cause inaccurate physical statistics especially if changing page size. However, it will save on computing time as RUNSTATS does not have to be called to compute new statistics. Also, the optimizer may choose the same access plans, because the statistics are the same (plan stability). The statistics that are copied are in the SYSSTAT.TABLES, SYSSTAT.COLUMNS, SYSSTAT.COLDIST, SYSSTAT.INDEXES, and SYSSTAT.COLGROUPS catalog views.
If the NO_STATS option has been set, the RUNSTATS command is not issued, and statistics are not copied on the target table. If you use AUTO_RUNSTATS or AUTO_STMT_STATS, DB2 will automatically create new statistics
If you are using the COPY_USE_LOAD option, and if you do not specify a sub-option or you choose NONRECOVERABLE, then it is necessary to perform a backup of the target table space or table spaces before the SWAP phase in order to ensure recoverability. A backup can be created by issuing a statement such as the following:
BACKUP DB dbname TABLESPACE targetDataTablespace,
targetIndexTablespace, targetLongTablespace
ONLINE TO <destination>
If the destination for a recoverable LOAD in an HADR environment cannot be found from the standby, the table space will be inaccessible. The primary is not informed about this situation, so you might assume that the standby is up to date, but if there is a failover to the standby the table will not accessible.
In releases earlier than DB2 Version 9.7 Fix Pack 2, the FORCE option must be specified if the COPY_USE_LOAD is used. Else, the SWAP phase will not execute and you will receive an error.
The Table Move stored procedure treats any generated columns in the source table specially. The following paragraphs describe how the different types of generated columns are handled.
A row change timestamp column is a column that holds a timestamp representing the time when a row was last changed.
If a row change timestamp column is found in the source table, the values of this column after the table move operation is complete will not be the same as they where before the table move operation. The values of the column after the table move will represent the time at which the rows where inserted/updated in the new table object. This is done because the actual rows are being changed and the row change timestamp column values should therefore reflect these changes.
If a new table definition is supplied, and a column is defined as a row change timestamp column in the source table but not in the new table definition, then the column will not be a row change timestamp column.
An identity column is a column that automatically generates a value for the column when a row is inserted into the table.
If an identity column is found in the source table, the values of this column after the Table Move operation is complete will be identical to the values that were present before the table move operation. However, there is no way to determine the "last/next" value for the identity column in the source table. Therefore, when creating the identity column on the target table the value generation will be set to begin from the next "uncached" value. This is the same behavior that happens when the database restarts (stop/start). This behavior is documented in ALTER TABLE statement, under the "SET NO CACHE or CACHE integer-constant" heading of the "identity-alteration" section.
The column will initially be created as a regular column in the target table, and then be altered to be an identity column during the brief offline period of the SWAP phase. This is done because the column may have been created as GENERATED ALWAYS, and that would block the stored procedure from being able to insert the exact values from the source table into the column in the target table.
If a new table definition is specified, and a column is specified to be an identity column in the new table definition, then the stored procedure will check to see if the definition of the identity column matches the definition of the column in the source table. If they are a match, the stored procedure will continue as previously described. If they are not a match, the stored procedure will use the new identity column definition. Please note that this will restart the identity column counter with whatever the start value is specified as, however the current values of the rows in the column will remain the same.
If a new table definition is specified, and a column that is specified as an identity column in the source table is not specified as an identity column in the new table definition, then the stored procedure will still create the column as an identity column in the target table using the same specification found in the source table. This is done so that users do not need to look up the definition of the existing identity column and re-enter it into the new table definition. If the user does not want to keep the column as an Identity column, then they can alter the target table after the call to the stored procedure to remove the identity specification from the column.
An expression column is a column that automatically generates a value for the column based on an expression when a row is inserted into the table.
If an expression column is found in the source table, the values of this column after the Table move operation is complete will be identical to the values that were present before the table move operation.
The column will originally be created as a regular column in the target table, and then be altered to be an expression column during the brief offline period of the SWAP phase. This is done because expression columns are created as GENERATED ALWAYS, and do not allow inserts into that column. However, In order to alter the column in the target table to be an expression column, set integrity will briefly be turned off on the target table. The ALTER statement is performed, and then integrity is set back on with the GENERATED COLUMN IMMEDIATE UNCHECKED option.
The stored procedure will not support column expressions that include the table name (such as table 'T1' with expression (T1.C *5)) in either the source table or the target table. To remedy this, the user can alter the column to change the expression to not include the table name.
If a new table definition is specified, and a column is specified to be an expression column in the new table definition, then the stored procedure will check to see if the definition of the expression column matches the definition of the column in the source table by performing a basic string to string comparison. If they are a match, the stored procedure will continue as previously described. If they are not a match, the stored procedure will use the new expression column definition. Please note that the current values of the rows in the column will remain the same.
If a new table definition is specified, and a column that is specified as an expression column in the source table is not specified as an expression column in the new table definition, then the stored procedure will still create the column as an expression column in the target table using the same specification found in the source table. This is done so that users do not need to look up the definition of the existing expression column and re-enter it into the new table definition. If the user does not want to keep the column as an Expression column, then they can alter the target table after the call to the stored procedure to remove the Expression Specification from the column.
The stored procedure will preserve the following objects when a Table Move is performed:
To keep the database recoverable and compatible with HADR setups, ADMIN_MOVE_TABLE does not copy the NOT LOGGED INITIALLY information from the source to the target table.
If auto_revalidation is enabled on the database, and the USE_AUTO_REVAL option is not set (which is the default if auto_revalidation is enabled), then the views are not be dropped as outlined previously. Instead, the views remain and are revalidated with auto_revalidation. Triggers are dropped and re-created by the stored procedure because there is currently a limitation with renaming a table with a trigger defined as the subject. There might also be invalid views after the stored procedure completes if the auto_reval configuration parameter is set to DEFERRED. Objects are revalidated automatically on the next access, or you can call the ADMIN_REVALIDATE_DB_OBJECTS to revalidate all objects in the database.
It is possible to cluster the target table by an index. If a cluster index is present on the source table, it will be clustered by that index by default. The default can be changed after the INIT phase (This implies phase wise execution of Online Table Move). Calling Online Table Move in one MOVE phase with no cluster index present will result in the stored procedure clustering the target table with the unique/primary index. If a cluster index exists, the stored procedure will cluster the target table using the cluster index.
If there is a cluster index on the source table, it is possible to not cluster the target table on the cluster index by performing a multi-step move and deleting the key entries COPY_INDEXSCHEMA and COPY_INDEXNAME from the protocol table after the INIT phase.
It is possible to cluster the target table by any secondary index by performing a multi-step move and inserting/updating the key entries COPY_INDEXSCHEMA and COPY_INDEXNAME in the protocol table with the required index to cluster the target table.
If a user wants to modify the attributes of any existing attributes (such as index clustering, index compression, change global to local indexes and vice versa) they can manually make these changes during a multi-step move operation.
This can be done by performing the INIT and COPY phases of the move via a multi-step move. Then manually make any changes to the indexes on the target table. The name of the target table can be found in the protocol table. After the modifications have finished, resume with the REPLAY and SWAP phases.
If you convert a row-organized table into a column-organized table, applicable column-organized table restrictions on queries (that is, limited isolation levels) take effect at the end of processing, after the new table becomes visible to queries.
The ADMIN_MOVE_TABLE procedure requires triggers on the source table to capture changes. Because triggers are not supported on column-organized tables, the source table cannot be a column-organized table.
Indexes on column-organized tables are not supported. The ADMIN_MOVE_TABLE procedure silently converts primary key and unique indexes into primary key or unique constraints and ignores all non-unique indexes.
You cannot use the ADMIN_MOVE_TABLE procedure to convert a row-organized table into a column-organized table if the table contains unique indexes that are defined on nullable columns. Create any unique constraints on the target table before you call the ADMIN_MOVE_TABLE stored procedure.
The DISTRIBUTE BY HASH clause is not supported for column-organized tables. To ignore the DISTRIBUTE BY HASH clause, specify the minus sign (-) for the partkey_cols parameter.
The PARTITION BY RANGE clause is not supported for column-organized tables. To ignore the PARTITION BY RANGE clause, specify the minus sign (-) for the data_part parameter.
MDC or ITC tables are converted into column-organized tables when you specify the ORGANIZE BY COLUMN clause for the organize_by_clause parameter.
If you use the load utility to populate a column-organized target table, the ADMIN_MOVE_TABLE procedure inherits column-organized table restrictions that apply to the load utility.
The REORG option is not supported.
A long offline SWAP phase occurs when the table has foreign key (referential integrity) constraints that are defined on it, because the foreign key relationship must be checked.
CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',
'T1',
'ACCOUNTING',
'ACCOUNT_IDX',
'ACCOUNT_LONG',
'',
'',
'',
'CUSTOMER VARCHAR(80), REGION CHAR(5), YEAR INTEGER, CONTENTS CLOB',
'',
'MOVE')
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
This example calls the stored procedure using the second method , where the target table is created outside the procedure and is then named within the target_tabname parameter, to move the same table as in the previous example.
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'
Then call the stored procedure and
pass in the name of the target table:CALL SYSPROC.ADMIN_MOVE_TABLE(
'SVALENTI',
'T1',
'T1_TARGET',
'',
'MOVE')
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
CALL SYSPROC.ADMIN_MOVE_TABLE(
'OTM01COL',
'STAFF',
'STAFF2',
'COPY_USE_LOAD',
'MOVE'
)
CALL SYSPROC.ADMIN_MOVE_TABLE(
'OTM01COL',
'STAFF',
'',
'',
'',
'ORGANIZE BY COLUMN',
'',
'',
'',
'COPY_USE_LOAD',
'MOVE'
)
ALTER TABLE "TANJINXU"."ACT"
ADD CONSTRAINT "RPAA" FOREIGN KEY ("ACTNO")
REFERENCES "TANJINXU"."ACT" ("ACTNO")
ON DELETE RESTRICT
ON UPDATE NO ACTION
ENFORCED
ENABLE QUERY OPTIMIZATION
Because enforced foreign
key (referential integrity) constraints are not supported on column-organized tables, the NOT_ENFORCED option must
be specified so that the target table can be created as a column-organized table.CALL ADMIN_MOVE_TABLE(
'TANJINXU',
'ACT',
'',
'',
'',
'ORGANIZE BY COLUMN',
'',
'',
'',
'COPY_USE_LOAD,NOT_ENFORCED',
'MOVE,TRACE'
)