MainframeSupports
tip week 21/2011:

Does it irritate you that DB2 does not keep track of the actual number of rows in a table. Would you like to know when your table was lasst updated. These questions and a lot of other questions can be answered by using information from the table SYSIBM.TABLESPACESTATS, which is renamed to SYSIBM.SYSTABLESPACESTATS in DB2 version 9. There is a similar table for indexes called SYSIBM.INDEXSPACESTATS and renamed to SYSIBM.SYSINDEXSPACESTATS in DB2 version 9. These tables are referred to as Real time statistics tables.

Each time a tablespace is updated the corresponding information in the TABLESPACESTATS table is updated. The same happens for indexes in the INDEXSPACESTATS table, but this table is not quite as interesting. In other words you do not need to run RUNSTATS to obtain current statistics information. The information in the two tables are not 100% up to date, because DB2 caches the information, but they are very close. It is only a matter of seconds to a few minutes that prevents them from being 100% correct.

As the name TABLESPACESTATS suggests the information is on tablespace level. If you have more tables in the same tablespace the information may not be of much use. Fortunately most installations has a rule that ensures a 1:1 correspondance between tables and tablespaces. Unfortunately some popular products like SAP and Peoplesoft breaks this rule (I have heard). Real time statistics was introduced in DB2 version 7 and required a separate installation. This practise was continued in DB2 version 8, but in DB2 version 9 Real time statistics became an integated part of DB2. This is the reason for the name change. Please be aware that SYSTABLESPACESTATS and SYSINDEXSPACESTATS becomes active when switching from Compability mode to New function mode. Until the switch is carried out it is TABLESPACESTATS and INDEXSPACESTATS that is updated.

The table TABLESPACESTATS contains a lot of interesting information about each tablespace. Partitioned tables consist of many tablespaces so of course there is a row for each partition. For these tables the total amount of rows must be calculated by summing rows in TABLESPACESTATS. You can read all about the contens of each indivudual column here. The link is for DB2 version 9. The columns are the same in DB2 version 8 and a few more are added. Some columns has changed format (among these the important one containing the number of rows called TOTALROWS) from FLOAT to BIGINT (8 bytes integer).

Previous tip in english        Sidste danske tip        Tip list