DB2 - 儲存組



本章介紹資料庫儲存組。

Storage

介紹

儲存資料庫表或物件的一組儲存路徑稱為儲存組。您可以將表空間分配給儲存組。建立資料庫時,所有表空間都採用預設儲存組。資料庫的預設儲存組為“IBMSTOGROUP”。建立新資料庫時,如果在“CREATE DATABASE”命令末尾傳遞“AUTOMATIC STOGROUP NO”引數,則預設儲存組處於活動狀態。否則,資料庫沒有任何預設儲存組。

列出儲存組

您可以列出資料庫中的所有儲存組。

語法:[檢視當前資料庫中可用儲存組的列表]

db2 select * from syscat.stogroups

示例:[檢視當前資料庫中可用儲存組的列表]

db2 select * from syscat.stogroups

建立儲存組

以下是在資料庫中建立儲存組的語法。

語法:[建立新的儲存組。“stogropu_name”表示新儲存組的名稱,“path”表示儲存資料(表)的位置]

db2 create stogroup  on ‘path’

示例:[在“data1”資料夾路徑上建立新的儲存組“stg1”]

db2 create stogroup stg1 on ‘/data1’

輸出

DB20000I The SQL command completed succesfully 

使用儲存組建立表空間

以下是如何使用儲存組建立表空間。

語法:[使用現有儲存組建立新表空間]

db2 create tablespace <tablespace_name>  using stogroup <stogroup_name> 

示例:[使用現有儲存組“stg1”建立名為“ts1”的新表空間]

db2 create tablespace ts1 using stogroup stg1 

輸出

DB20000I The SQL command completed succesfully 

更改儲存組

您可以使用以下語法更改儲存組的位置。

語法:[將儲存組從舊位置移動到新位置]

db2 alter stogroup  add ‘location’, ‘location’ 

示例:[將名為“sg1”的儲存組的路徑從舊位置修改為新位置]

db2 alter stogroup sg1 add ‘/path/data3’, ‘/path/data4’ 

刪除儲存組的資料夾路徑

在刪除儲存組的資料夾路徑之前,您可以使用更改命令為儲存組新增新位置。

語法:[從儲存組位置刪除舊路徑]

db2 alter stogroup  drop ‘/path’ 

示例:[從“stg1”刪除儲存組位置]

db2 alter stogroup stg1 drop ‘/path/data1’  

重新平衡表空間

當我們為儲存組或表空間建立新資料夾時,需要重新平衡表空間,同時在資料庫上進行事務處理並且表空間已滿。重新平衡會使用新的儲存組更新資料庫配置檔案。

語法:[將表空間從舊儲存組路徑重新平衡到新的儲存組]

db2 alter tablspace <ts_name> rebalance   

示例:[重新平衡]

db2 alter tablespace ts1 rebalance   

重新命名儲存組

語法:[修改現有儲存組名稱]

db2 rename stogroup <old_stg_name> to <new_stg_name>   

示例:[將儲存組名稱從“sg1”修改為新名稱“sgroup1”]

db2 rename stogroup sg1 to sgroup1   

刪除儲存組

步驟 1:在刪除任何儲存組之前,您可以為表空間分配一些不同的儲存組。

語法:[為表空間分配另一個儲存組。]

db2 alter tablspace <ts_name> using stogroup <another sto_group_name>    

示例:[將表空間“ts1”從一箇舊儲存組更改為名為“sg2”的新儲存組]

db2 alter tablespace ts1 using stogroup sg2   

步驟 2

語法:[刪除現有的儲存組]

db2 drop stogorup <stogroup_name>   

示例:[從資料庫中刪除儲存組“stg1”]

db2 drop stogroup stg1  
廣告

© . All rights reserved.