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.注:
When neither CLUSTER or NON_CLUSTER options are specified, ADMIN_MOVE_TABLE will read the data from the source table with an ORDER BY clause only when a clustering index exists on 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.如果聯機移動失敗,那麼重新運行該移動:
a. 解決導致表移動失敗的問題。
b. 通過查詢 SYSTOOLS.ADMIN_MOVE_TABLE 協議表以了解狀態來確定表移動失敗時正在進行的階段。
c. 再次調用存儲過程,並指定適用選項:
- 如果過程的狀態為 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鎖的影響
最後更新:2017-06-29 09:02:26