How To
Summary
This page guides you on how to list table physical size in a database.
Objective
A table in a database involves several objects like data, index, lob and extent map for each objects. Each objects need at least one extent (page size * extent size) even if no data is stored in the objects.
For example, an empty table becomes 32*32KB*4=4MB in size if it's created in a tablespace defined pagesize is 32K, extent size is 32 page, and the table has index. See the follwoing page for details.
So we need to add up all the extents to measure table size.
Steps
Users can use ADMINTABINFO administrative view or ADMIN_GET_TAB_INFO table function to list object size.
- List all tables with its size in a database (decending order)
- Login to the database server as instance owner
- Create an SQL text named tsize.sql as below:
SELECT TABSCHEMA, TABNAME, SUM(DATA_OBJECT_P_SIZE) + SUM(COL_OBJECT_P_SIZE) + SUM(INDEX_OBJECT_P_SIZE) + SUM(LONG_OBJECT_P_SIZE) + SUM(LOB_OBJECT_P_SIZE) + SUM(XML_OBJECT_P_SIZE) AS SIZE_IN_KB FROM SYSIBMADM.ADMINTABINFO GROUP BY TABSCHEMA, TABNAME ORDER BY 3 DESC ;
- Connect to the database, and run the SQL
The unit of the size is Kiro-bytedb2 connect to <db_name> db2 -tvf tsize.sql
- List all tables in the specific tablespace. Tablespace ID = 0 in this example
- Login to the database server as instance owner
- Create an SQL text named tsize_tbs0.sql as below:
You can change 0 (TBS=0) to any tablespace ID in the database.with TBSSIZE as (select d.TABNAME,d.TABSCHEMA,d.DATAPARTITIONID,d.TBSPACEID as tbs,DATA_OBJECT_P_SIZE + COL_OBJECT_P_SIZE as size from SYSCAT.DATAPARTITIONS d join SYSIBMADM.ADMINTABINFO t on d.TABNAME=t.TABNAME and d.TABSCHEMA=t.TABSCHEMA and d.DATAPARTITIONID=t.DATA_PARTITION_ID union select d.TABNAME,d.TABSCHEMA,d.DATAPARTITIONID,d.INDEX_TBSPACEID as tbs,INDEX_OBJECT_P_SIZE as size from SYSCAT.DATAPARTITIONS d join SYSIBMADM.ADMINTABINFO t on d.TABNAME=t.TABNAME and d.TABSCHEMA=t.TABSCHEMA and d.DATAPARTITIONID=t.DATA_PARTITION_ID union select d.TABNAME,d.TABSCHEMA,d.DATAPARTITIONID,d.LONG_TBSPACEID as tbs,LONG_OBJECT_P_SIZE + LOB_OBJECT_P_SIZE + XML_OBJECT_P_SIZE as size from SYSCAT.DATAPARTITIONS d join SYSIBMADM.ADMINTABINFO t on d.TABNAME=t.TABNAME and d.TABSCHEMA=t.TABSCHEMA and d.DATAPARTITIONID=t.DATA_PARTITION_ID ) select char(TABSCHEMA,20),char(TABNAME,50),TBS,SUM(size) from TBSSIZE group by TABSCHEMA,TABNAME,TBS having TBS=0 order by SUM(size) desc ;
- Connect to the database, and tun the SQL
db2 connect to <db_name> db2 -tvf tsize_tbs0.sql
See the ADMINTABINFO for details
Document Location
Worldwide
[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"ARM Category":[{"code":"a8m500000008PlYAAU","label":"Database Objects-\u003ETables"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]
Was this topic helpful?
Document Information
Modified date:
23 February 2024
UID
ibm17123107