ADMIN_MOVE_TABLE procedure
You can move tables both online and offline using
ADMIN_MOVE_TABLE. In fact, this procedure
can be used to move the data in a table to a new table object of the
same name (but with possibly different storage characteristics, such
as different tablespace) while the data remains online and available
for access. You can also generate a new optimal compression dictionary
when a table is moved.
The ADMIN_MOVE_TABLE stored procedure
creates a protocol table composed of rows containing status
information and configuration options related to the table to be
moved. The return set from this procedure is the rows from that
protocol table related to the table to be moved.
You can invoke the ADMIN_MOVE_TABLE by two methods.
Method 1
— Modify only certain parts of the table definition for the
target table (if you just want to modify the tablespaces for the table
objects, for exmaple). All you need to do is to fill out the
data_tbsp, index_tbsp, and
lob_tbsp parameters while calling the
procedure, leaving the other optional parameters blank.
Example
This example calls the stored procedure using the first method, where the target table is defined within the procedure, to move a table named T1, which is located in the schema titled SCHEMA1. Additionally, the column definitions of the target table are passed to the procedure.
Listing 35. Example for stored procedure using the first method
CALL SYSPROC.ADMIN_MOVE_TABLE(
'SCHEMA1',
'T1',
'ACCOUNTING',
'ACCOUNT_IDX',
'ACCOUNT_LONG',
'',
'',
'',
'CUSTOMER VARCHAR(80), REGION CHAR(5), YEAR INTEGER, CONTENTS CLOB',
'',
'MOVE')
|
the above example moves the table SCHEMA1.T1 to a new table with the same name that has the columns definitions: CUSTOMER VARCHAR(80), REGION CHAR(5), YEAR INTEGER, CONTENTS CLOB and resides in tablespace ACCOUNTING with its indices tablespace ACCOUNT_IDX and its LOBs tablespace ACCOUNT_LONG.
Method 2 — Create the target table and provide its name to the procedure. This provides you with more control and flexibility by allowing you to create the target table beforehand, rather than having the stored procedure create it.
Example
This example is equivalent to the previous one, but it 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.
Listing 36. Example for stored procedure using the second method
CREATE TABLE SCHEMA1.T1_TGT (
CUSTOMER VARCHAR(80),
REGION CHAR(5),
YEAR INTEGER,
CONTENTS CLOB)
IN ACCOUNTING
INDEX IN ACCOUNT_IDX
LONG IN ACCOUNT_LONG'
|
CALL SYSPROC.ADMIN_MOVE_TABLE(
'SCHEMA',
'T1',
'T1_TGT',
'',
'MOVE')
|
For online data movement:
- The procedure creates a shadow table to which the data are copied.
- Any changes to the source table during the copy phase are captured using triggers and placed in a staging table.
- After the copy phase is completed, the changes captured in the staging table are replayed to the shadow copy.
- Following that, the stored procedure briefly takes the source table offline and assigns the source table name and index names to the shadow copy and its indices.
- The shadow table is then brought online, replacing the source
table. By default, the source table is dropped, but you can use
the
KEEPoption to retain it under a different name.
Obviously, the online operation costs more server resources (disk space and processing power), so make sure you only use it if you value availability more than cost, space, move performance, and transaction overhead. Additionally, avoid performing online moves for tables without indices, particularly unique indices as it might result in deadlocks and complex or expensive replay.
If the online move fails, rerun it:
- Fix the problem that caused the table move to fail.
- Determine the stage that was in progress when the table move failed by querying the SYSTOOLS.ADMIN_MOVE_TABLE protocol table for the status.
- Call the stored procedure again, specifying the applicable option:
- If the status of the procedure is INIT, use the
INIToption. - If the status of the procedure is COPY, use
COPY. - If the status of the procedure is REPLAY, use
REPLAYorSWAP. - If the status of the procedure is CLEANUP, use
CLEANUP.
- If the status of the procedure is INIT, use the
If the status of an online table move is not COMPLETED or CLEANUP, you
can cancel the move by specifying CANCEL
for the stored procedure.
ADMIN_MOVE_TABLE procedure and temporal
tables
There are some limitations when using the
ADMIN_MOVE_TABLE stored procedure to move
data in an active system-period temporal table into a new table with
the same name. The following actions are blocked:
- Alter table operations that change the definition of the system-period temporal table or the associated history table are blocked during online move operations.
- The
KEEPoption ofADMIN_MOVE_TABLEis unavailable for system-period temporal tables.
Additionally, the online-table-move operation is not supported for history tables.




