If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > how to get size of db tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-09, 12:09
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
how to get size of db tables

Hi,

Is there an easy way to get the size of an individual db2 table? I want to remove old records from tables that are taking up too much space but think a count query will simply take too long to run on certain tables.. thanks!!
Reply With Quote
  #2 (permalink)  
Old 10-15-09, 12:22
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
You can get the number of rows (card column) or number of pages (npages columns) from syscat.tables. The numbers are as of last runstats execution.
Reply With Quote
  #3 (permalink)  
Old 10-16-09, 15:49
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
- show table size:
db2 “select substr(t.tabschema,1,10)||’.’||substr(t.tabname,1, 20) as table ,char(date(t.stats_time)) as statsdate ,char(time(t.stats_time)) as statstime ,T.CARD as rows_per_tbl, decimal(float(t.npages)/(1024/(ts.pagesize/1024)),9,2) as used_mb ,decimal(float(t.fpages)/(1024/(ts.pagesize/1024)),9,2) as allocated_mb from SYSCAT.TABLES T ,SYSCAT.TABLESPACES TS where t.tbspace=ts.tbspace and T.tabname=’table name here‘ and T.TYPE=’T’”

- show all tables sizes in DB:
db2 “select substr(t.tabschema,1,10)||’.’||substr(t.tabname,1, 20) as table ,char(date(t.stats_time)) as statsdate ,char(time(t.stats_time)) as statstime ,T.CARD as rows_per_tbl, decimal(float(t.npages)/(1024/(ts.pagesize/1024)),9,2) as used_mb ,decimal(float(t.fpages)/(1024/(ts.pagesize/1024)),9,2) as allocated_mb from SYSCAT.TABLES T, SYSCAT.TABLESPACES TS where t.tbspace=ts.tbspace and T.TYPE=’T’ order by table”
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #4 (permalink)  
Old 10-16-09, 16:28
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
thank you Markham!
Reply With Quote
  #5 (permalink)  
Old 10-18-09, 08:40
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
db2top,
uppercase "T",
arrow right until you'll see the header "Table-Size"

You do not see the # rows but the size in Kb/Mb/Gb.
Reply With Quote
  #6 (permalink)  
Old 10-28-09, 15:51
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
I tried Markham's command and for some reason, I get back CARD, USED_MB and ALLOCATED_MB as -1, 0.00, 0.00 for all the tables. Any idea why this would come back as the result? Thanks!
Reply With Quote
  #7 (permalink)  
Old 10-28-09, 16:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
See post #2 in this thread.
Reply With Quote
  #8 (permalink)  
Old 10-28-09, 16:10
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Duplicate removed

Last edited by n_i; 10-28-09 at 16:18.
Reply With Quote
  #9 (permalink)  
Old 10-29-09, 12:14
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Hmm, for some reason if I try "select * from syscat.tables" I still get the -1, 0.00, 0.00 combination.. is there some setting option I can change to make this command return the correct values?
Reply With Quote
  #10 (permalink)  
Old 10-29-09, 12:35
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Do runstats. If you still get those values then it isn't a table but a view.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On