當前位置:成語大全網 - 新華字典 - db2怎麽查看表空間使用率

db2怎麽查看表空間使用率

db2 查看表空間使用率

1. 統計所有節點表空間使用率

select substr(TABLESPACE_NAME,1,20) as TBSPC_NAME,bigint(TOTAL_PAGES * PAGE_SIZE)/1024/1024 as "TOTAL(MB)",

used_pages*PAGE_SIZE/1024/1024 as "USED(MB)", free_pages*PAGE_SIZE/1024/1024 as "FREE(MB)"

from table(snapshot_tbs_cfg('DB_NAME', -2)) as snapshot_tbs_cfg

2、查看表空間使用率

select substr(tbsp_name,1,20) as TABLESPACE_NAME,substr(tbsp_content_type,1,10) as TABLESPACE_TYPE,sum(tbsp_total_size_kb)/1024 as TOTAL_MB,

sum(tbsp_used_size_kb)/1024 as USED_MB,sum(tbsp_free_size_kb)/1024 as FREE_MB,tbsp_page_size AS PAGE_SIZE

from SYSIBMADM.TBSP_UTILIZATION group by tbsp_name,tbsp_content_type,tbsp_page_size

order by 1

3、通過存儲過程查看數據庫大小和容量

db2 call GET_DBSIZE_INFO (?,?,?,0)

輸出參數的值

--------------------------

參數名: SNAPSHOTTIMESTAMP

參數值: 2008-05-26-10.53.06.421000

參數名: DATABASESIZE

參數值: 1203863552

參數名: DATABASECAPACITY

參數值: 4281493504

unit=byte, byte/1024/1024=m

db2 call GET_DBSIZE_INFO (?,?,?,0)

註意:

a、從V8以上版本支持,此存儲過程看數據庫大小和容量;如果要看各表空間使用情況上面的sql方便,

b、還有DPF環境下,db2 call GET_DBSIZE_INFO (?,?,?,0)只能看dbsize大小,無法看db的容量

SYSIBM.SYSTABLESPACES

SYSIBM.SYSTBSPACEAUTH

2.db2查看表空間和增加表空間容量

Db2 connect to xxx

Db2 “LIST TABLESPACES SHOW DETAIL”

Tablespace ID = 7

Name = TSASNAA

Type = Database managed space

Contents = All permanent data. Large table space.

State = 0x0000

Detailed explanation:

Normal

Total pages = 14800

Useable pages = 14752

Used pages = 12864

Free pages = 1888

High water mark (pages) = 12864

Page size (bytes) = 8192

Extent size (pages) = 32

Prefetch size (pages) = 32

Number of containers = 1

增加表空間大小

DB2數據庫使用時,如果表空間滿了,該如何擴容呢?下文將教給您DB2數據庫表空間擴容的方法,供您參考,希望對您有所幫助。

1)直接添加壹個容器的例子:

db2 " ALTER TABLESPACE PAYROLL ADD (DEVICE '/dev/rhdisk9' 10000) "

加容器之後DB2會有壹個自動balance的過程,可能會持續幾個小時!!! 壹定要註意該選項,修改前確認該選項是否能滿足業務需求!

2)改變現有容器的大小(該方法不會觸發balance,但如果表空間建立在裸設備上,則要擴沖裸設備空間):

db2 " ALTER TABLESPACE TS1 RESIZE (FILE '/conts/cont0' 2000, DEVICE '/dev/rcont1' 2000, FILE 'cont2' 2000) "

註意這種方式就是將原有的相應容器都改成大小是2000頁

db2 "ALTER TABLESPACE TS1 RESIZE (ALL 2000)"

這種方式就是把表空間中所有的容器大小都改成2000頁

db2 " ALTER TABLESPACE TS1 EXTEND (FILE '/conts/cont0' 1000, DEVICE '/dev/rcont1' 1000, FILE 'cont2' 1000) "

這種方式就是將相應的容器都擴大1000頁,也就是增加1000頁。

db2 " ALTER TABLESPACE DATA_TS EXTEND (ALL 1000)"

這種方式就是將所有的容器都增加1000頁。

3.db2數據字典

select name from sysibm.systables where type='T' and creator='USERID' and tbspace='TS4R_DNJC' order by name;

select name from sysibm.systables where type='V' and creator='USERID' order by name;

type:數據庫表用T表示;數據庫視圖用V表示

creator:數據庫對象的創建者

select * from sysibm.syscolumns

select tabname from syscat.tables where tabschema=current schema ;

獲取當前模式下面的所有用戶表

describe table XXXX

SELECT NAME

,COLNO

,COLTYPE || '('

|| CAST(LENGTH AS CHAR(5)) || ','

|| CAST(SCALE AS CHAR(5)) || ')'

,CASE WHEN NULLS = 'N'

THEN 'NOT NULL' ELSE ' ' END

,TBNAME

WHERE TBCREATOR = 'TEST' -- < OR 'TEST'

-- AND (NAME = 'YOUR_COL_NAME' -- < COLUMN NAME \ ONLY USE ONE

AND (TBNAME = 'T_QUICK_MENU' -- < TABLE NAME /

)

ORDER BY TBNAME, COLNO

SELECT NAME FROM SYSIBM.SYSCOLUMNS