Db2 简明教程
DB2 - Storagegroups
本章描述了数据库存储组。
This chapter describes the Database Storagegroups.
Introduction
存储数据库表或对象的一组存储路径是一个存储组。您可以将表空间分配给存储组。当您创建一个数据库时,所有表空间都采用默认存储组。数据库的默认存储组是“IBMSTOGROUP”。当您创建一个新的数据库时,如果在“CREATE DATABASE”命令的末尾传递了“AUTOMATIC STOGROUP NO”参数,则默认存储组为活动状态。数据库没有任何默认存储组。
A set of Storage paths to store database table or objects, is a storage group. You can assign the tablespaces to the storage group. When you create a database, all the tablespaces take default storagegorup. The default storage group for a database is ‘IBMSTOGROUP’. When you create a new database, the default storage group is active, if you pass the “AUTOMATIC STOGROUP NO” parameter at the end of “CREATE DATABASE” command. The database does not have any default storage groups.
Listing storagegroups
您可以列出数据库中的所有存储组。
You can list all the storagegroups in the database.
Syntax : [查看当前数据库中可用存储组的列表]
Syntax: [To see the list of available storagegroups in current database]
db2 select * from syscat.stogroups
Example : [查看当前数据库中可用存储组的列表]
Example: [To see the list of available storagegorups in current database]
db2 select * from syscat.stogroups
Creating a storagegroup
以下是数据库中创建存储组的语法:
Here is a syntax to create a storagegroup in the database:
Syntax : [创建一个新的 stogroup。“stogropu_name”表示新存储组的名称,“path”表示存储数据(表)的位置]
Syntax: [To create a new stogroup. The ‘stogropu_name’ indicates name of new storage group and ‘path’ indicates the location where data (tables) are stored]
db2 create stogroup on ‘path’
Example : [在路径“data1”文件夹上创建一个新的 stogroup “stg1”]
Example: [To create a new stogroup ‘stg1’ on the path ‘data1’ folder]
db2 create stogroup stg1 on ‘/data1’
Output:
Output:
DB20000I The SQL command completed succesfully
Creating tablespace with stogroup
以下是使用 storegroup 创建表空间的方法:
Here is how you can create a tablespace with storegroup:
Syntax : [使用已存在的存储组创建一个新的表空间]
Syntax: [To create a new tablespace using existed storage group]
db2 create tablespace <tablespace_name> using stogroup <stogroup_name>
Example : [使用已存在的存储组“stg1”创建一个名为“ts1”的新表空间]
Example: [To create a new tablespace named ‘ts1’ using existed storage group ‘stg1’]
db2 create tablespace ts1 using stogroup stg1
Output:
Output:
DB20000I The SQL command completed succesfully
Altering a storagegroup
您可以使用以下语法更改 storegroup 的位置:
You can alter the location of a storegroup by using following syntax:
Syntax : [将存储组从旧位置移动到新位置]
Syntax: [To shift a storage group from old location to new location]
db2 alter stogroup add ‘location’, ‘location’
Example : [针对名为“sg1”的存储组,修改位置从旧位置到新位置的路径]
Example: [To modify location path from old location to new location for storage group named ‘sg1’]
db2 alter stogroup sg1 add ‘/path/data3’, ‘/path/data4’
Dropping folder path of storagegroup
在删除存储组的文件夹路径之前,您可以使用 alter 命令为存储组添加新位置。
Before dropping folder path of storagegroup, you can add new location for the storagegroup by using alter command.
Syntax : [从存储组位置中删除旧路径]
Syntax: [To drop old path from storage group location]
db2 alter stogroup drop ‘/path’
Example : [从“stg1”中删除存储组位置]
Example: [To drop storage group location from ‘stg1’]
db2 alter stogroup stg1 drop ‘/path/data1’
Rebalancing a tablespace
当在数据库上进行事务且表空间变满时,为存储组或表空间创建新文件夹时需要重新平衡表空间。重新平衡使用新存储组更新数据库配置文件。
Rebalancing the tablespace is required when we create a new folder for storagegroup or tablespaces while the transactions are conducted on the database and the tablespace becomes full. Rebalancing updates database configuration files with new storagegroup.
Syntax : [将表空间从旧存储组路径重新平衡到新存储组]
Syntax: [To rebalance the tablespace from old storage group path to new storage group]
db2 alter tablspace <ts_name> rebalance
Example :[重新配置]
Example: [To rebalance]
db2 alter tablespace ts1 rebalance
Renaming a storagegroup
Syntax :[修改现有存储名称的名称]
Syntax: [To modify the name of existing storage name]
db2 rename stogroup <old_stg_name> to <new_stg_name>
Example :[将存储组的名称从“sg1”修改为新名称“sgroup1”]
Example: [To modify the name of storage group from ‘sg1’ to new name ‘sgroup1’]
db2 rename stogroup sg1 to sgroup1
Dropping a storage group
Step 1 :在删除任何存储组之前,您可以为表空间分配其他不同的存储组。
Step 1: Before dropping any storagegroup, you can assign some different storagegroup for tablespaces.
Syntax :[为表空间指定另一个存储组]
Syntax: [To assign another storagegroup for table space.]
db2 alter tablspace <ts_name> using stogroup <another sto_group_name>
Example :[为表空间“ts1”从一个旧的存储组更改为新的名为“sg2”的存储组]
Example: [To change from one old stogroup to new stogroup named ‘sg2’ for tablespace ‘ts1’]
db2 alter tablespace ts1 using stogroup sg2
Step 2:
Step 2:
Syntax :[删除现有存储组]
Syntax: [To drop the existing stogroup]
db2 drop stogorup <stogroup_name>
Example :[从数据库中删除存储组“stg1”]
Example: [To drop stogroup ‘stg1’ from database]
db2 drop stogroup stg1