本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
資料表空間的常見任務
您可以為 RDS for Db2 資料庫建立、更改、重新命名或捨棄資料表空間。建立、更改、重新命名或捨棄資料表空間需要更高層級的 SYSADM 授權,這些授權不適用於主要使用者。請改用 Amazon RDS 預存程序。
建立資料表空間
若要為您的 RDS for Db2 資料庫建立資料表空間,請呼叫 rdsadmin.create_tablespace 預存程序。如需詳細資訊,請參閱 IBM Db2 文件中的 CREATE TABLESPACE 陳述式
重要
若要建立資料表空間,您必須具有相同頁面大小的緩衝集區,才能與資料表空間建立關聯。如需更多詳細資訊,請參閱 緩衝集區的常見任務。
建立資料表空間
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.create_tablespace來建立資料表空間。如需更多詳細資訊,請參閱 rdsadmin.create_tablespace。db2 "call rdsadmin.create_tablespace( 'database_name', 'tablespace_name', 'buffer_pool_name',tablespace_initial_size,tablespace_increase_size, 'tablespace_type')"
更改資料表空間
若要更改 RDS for Db2 資料庫的資料表空間,請呼叫 rdsadmin.alter_tablespace 預存程序。您可以使用此預存程序來變更資料表空間的緩衝集區、降低高浮水印,或讓資料表空間上線。如需詳細資訊,請參閱 IBM Db2 文件中的 ALTER TABLESPACE 陳述式
更改資料表空間
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.alter_tablespace來更改資料表空間。如需更多詳細資訊,請參閱 rdsadmin.alter_tablespace。db2 "call rdsadmin.alter_tablespace( 'database_name', 'tablespace_name', 'buffer_pool_name',buffer_pool_size,tablespace_increase_size, 'max_size', 'reduce_max', 'reduce_stop', 'reduce_value', 'lower_high_water', 'lower_high_water_stop', 'switch_online')"
將資料表空間重新命名
若要變更 RDS for Db2 資料庫的資料表空間之名稱,請呼叫 rdsadmin.rename_tablespace 預存程序。如需詳細資訊,請參閱 IBM Db2 文件中的 RENAME TABLESPACE 陳述式
將資料表空間重新命名
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.rename_tablespace將資料表空間重新命名。如需詳細資訊,包括您可命名資料表空間的限制,請參閱 rdsadmin.rename_tablespace。db2 "call rdsadmin.rename_tablespace( 'database_name', 'source_tablespace_name', 'target_tablespace_name')"
捨棄資料表空間
若要捨棄 RDS for Db2 資料庫的資料表空間,請呼叫 rdsadmin.drop_tablespace 預存程序。在捨棄資料表空間之前,請先捨棄資料表空間中的任何物件,例如資料表、索引或大型物件 LOB)。如需詳細資訊,請參閱 IBM Db2 文件中的捨棄資料表空間
捨棄資料表空間
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.drop_tablespace以捨棄資料表空間。如需更多詳細資訊,請參閱 rdsadmin.drop_tablespace。db2 "call rdsadmin.drop_tablespace( 'database_name', 'tablespace_name')"
檢查資料表空間的狀態
您可以使用 cast 函數來檢查資料表空間的狀態。
檢查資料表空間的狀態
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至 Db2 資料庫。在下列範例中,將
rds_database_alias、master_username和master_password取代為您自己的資訊。db2 connect tords_database_aliasusermaster_usernameusingmaster_password -
傳回摘要輸出。
針對摘要輸出:
db2 "select cast(tbsp_id as smallint) as tbsp_id, cast(tbsp_name as varchar(35)) as tbsp_name, cast(tbsp_type as varchar(3)) as tbsp_type, cast(tbsp_state as varchar(10)) as state, cast(tbsp_content_type as varchar(8)) as contents from table(mon_get_tablespace(null,-1)) order by tbsp_id"
傳回資料表空間的詳細資訊
您可以使用 cast 函數傳回一個成員或所有成員的資料表空間相關資訊。
傳回資料表空間的詳細資訊
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至 Db2 資料庫。在下列範例中,將
rds_database_alias、master_username和master_password取代為您自己的資訊。db2 connect tords_database_aliasusermaster_usernameusingmaster_password -
針對一個成員或所有成員,傳回資料庫中所有資料表空間的詳細資訊。
針對一個成員:
db2 "select cast(member as smallint) as member, cast(tbsp_id as smallint) as tbsp_id, cast(tbsp_name as varchar(35)) as tbsp_name, cast(tbsp_type as varchar(3)) as tbsp_type, cast(tbsp_state as varchar(10)) as state, cast(tbsp_content_type as varchar(8)) as contents, cast(tbsp_total_pages as integer) as total_pages, cast(tbsp_used_pages as integer) as used_pages, cast(tbsp_free_pages as integer) as free_pages, cast(tbsp_page_top as integer) as page_hwm, cast(tbsp_page_size as integer) as page_sz, cast(tbsp_extent_size as smallint) as extent_sz, cast(tbsp_prefetch_size as smallint) as prefetch_sz, cast(tbsp_initial_size as integer) as initial_size, cast(tbsp_increase_size_percent as smallint) as increase_pct, cast(storage_group_name as varchar(12)) as stogroup from table(mon_get_tablespace(null,-1)) order by member, tbsp_id "針對所有成員:
db2 "select cast(member as smallint) as member cast(tbsp_id as smallint) as tbsp_id, cast(tbsp_name as varchar(35)) as tbsp_name, cast(tbsp_type as varchar(3)) as tbsp_type, cast(tbsp_state as varchar(10)) as state, cast(tbsp_content_type as varchar(8)) as contents, cast(tbsp_total_pages as integer) as total_pages, cast(tbsp_used_pages as integer) as used_pages, cast(tbsp_free_pages as integer) as free_pages, cast(tbsp_page_top as integer) as page_hwm, cast(tbsp_page_size as integer) as page_sz, cast(tbsp_extent_size as smallint) as extent_sz, cast(tbsp_prefetch_size as smallint) as prefetch_sz, cast(tbsp_initial_size as integer) as initial_size, cast(tbsp_increase_size_percent as smallint) as increase_pct, cast(storage_group_name as varchar(12)) as stogroup from table(mon_get_tablespace(null,-2)) order by member, tbsp_id "
列出資料表空間的狀態和儲存群組
您可以執行 SQL 陳述式,列出資料表空間的狀態和儲存群組。
若要列出資料表空間的狀態和儲存群組,請執行下列 SQL 陳述式:
db2 "SELECT varchar(tbsp_name, 30) as tbsp_name, varchar(TBSP_STATE, 30) state, tbsp_type, varchar(storage_group_name,30) storage_group FROM TABLE(MON_GET_TABLESPACE('',-2)) AS t"
列出資料表的資料表空間
您可以執行 SQL 陳述式來列出資料表的資料表空間。
若要列出資料表的資料表空間,請執行下列 SQL 陳述式。在下列範例中,將 SCHEMA_NAME 和 TABLE_NAME 取代為結構描述和資料表的名稱:
db2 "SELECT VARCHAR(SD.TBSPACE,30) AS DATA_SPACE, VARCHAR(SL.TBSPACE,30) AS LONG_SPACE, VARCHAR(SI.TBSPACE,30) AS INDEX_SPACE FROM SYSCAT.DATAPARTITIONS P JOIN SYSCAT.TABLESPACES SD ON SD.TBSPACEID = P.TBSPACEID LEFT JOIN SYSCAT.TABLESPACES SL ON SL.TBSPACEID = P.LONG_TBSPACEID LEFT JOIN SYSCAT.TABLESPACES SI ON SI.TBSPACEID = P.INDEX_TBSPACEID WHERE TABSCHEMA = 'SCHEMA_NAME' AND TABNAME = 'TABLE_NAME'"
列出資料表空間容器
您可以使用 cast 命令來列出所有資料表空間容器或特定資料表空間容器。
列出資料表空間的資料表空間容器
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至 Db2 資料庫。在下列範例中,將
rds_database_alias、master_username和master_password取代為您自己的資訊:db2 connect tords_database_aliasusermaster_usernameusingmaster_password -
傳回資料庫中所有資料表空間容器或特定資料表空間容器的清單。
針對所有資料表空間容器:
db2 "select cast(member as smallint) as member, cast(tbsp_name as varchar(35)) as tbsp_name, cast(container_id as smallint) as id, cast(container_name as varchar(60)) as container_path, container_type as type from table(mon_get_container(null,-2)) order by member,tbsp_id,container_id"針對特定資料表空間容器:
db2 "select cast(member as smallint) as member, cast(tbsp_name as varchar(35)) as tbsp_name, cast(container_id as smallint) as id, cast(container_name as varchar(60)) as container_path, container_type as type from table(mon_get_container('TBSP_1',-2)) order by member, tbsp_id,container_id"