473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Table size and index size

I am trying to write a sql script to estimate size and count of rows of
all tables and indexes within a schema.

Here's what I have so far but need a little help.

#$1 is database name and $2 is schema name
db2 connect to $1
db2 select tabname,t1.fpages * t2.pagesize as bytes from syscat.tables
t1, syscat.tablespaces t2 where t1.tabschema='$2' and
t1.tbspace=t2.tbspace
How can I add the index_size for each index under a table?
#syscat.indexes lists nleafs but it doesn't compute.
How can I list the number of rows for each table as I progress through
the query.

Nov 12 '05 #1
3 24126
Since you select t1.fpages, it seems to me you rely on your statistics to be
current.
Given that, t1.card will give you the number of rows in the table.

However, t1.fpages will always include the count of empty pages, so
fpages*pagesize as bytes may never reflect reality.
The same applies to indexes. nleafs indicate the number of pages in the
last level. They are pages holding keys and rids. Some may be full, some
may be empty. It does not count the space that other nodes occupy.
HTH, Pierre.

--
Pierre Saint-Jacques
SES Consultants Inc.
514-737-4515
"dunleav1" <jm*@dunleavyenterprises.com> a écrit dans le message de
news:11**********************@g14g2000cwa.googlegr oups.com...
I am trying to write a sql script to estimate size and count of rows of
all tables and indexes within a schema.

Here's what I have so far but need a little help.

#$1 is database name and $2 is schema name
db2 connect to $1
db2 select tabname,t1.fpages * t2.pagesize as bytes from syscat.tables
t1, syscat.tablespaces t2 where t1.tabschema='$2' and
t1.tbspace=t2.tbspace
How can I add the index_size for each index under a table?
#syscat.indexes lists nleafs but it doesn't compute.
How can I list the number of rows for each table as I progress through
the query.


Nov 12 '05 #2
Yes, I am relying on my statistics to be current.
Thanks for card definition to equal the number of rows.
Since fpages may by 0, what is the best way to calculate the size for
the table and index?

Nov 12 '05 #3
If you look at your docs., you'll find that table stats. include
FPAGES: Total number of pages to hold the table
NPAGES: Number of page holding at least one row.
The ratio of npages over fpages is an indication of the amount of "fluff" in
your table.
If FPAGES is 0 then CARD should be 0 also.

You can use Google to find stuff like that. I did a google search on: db2
size estimate.
HTH, Pierre.
Here's what Craig Tobias from IBM suggests;
estimate size
Posted by: Craig Tobias, 2004 March 29 02:21 PM

Jean-Marc,

In v8.1, we created some stored procedures to capture and save storage
snapshots. Snapshots can be captured for Databases, Table spaces,
Tables,
Indexes, and Database Partition Groups. To capture storage data
(including
estimated size) for all objects (including tables) in a database, you
should
capture a database snapshot.

Before capturing a snapshot, you must create the storage management
tables
(where all snapshot data is stored). Run the following command to
create the
storage tables, and specify a table space for the tables.

db2 connect to
db2 call create_storagemgmt_tables('')

Now, capture a snapshot at the database level... this can take a while
for
large databases. You may also want to update your table statistics
using
the Runstats utility before running the storage snapshot. To capture a
snapshot, run the following command:

db2 call capture_storagemgmt_info(0, ' ', '')

The table related data is stored in the SYSTOOLS.STMG_TABLE table. You
also
need to do a name lookup in the SYSTOOLS.STMG_OBJECT table. To query
the
storage management tables for estimated table size, run the following
command...

SELECT
MAX(tables.STMG_TIMESTAMP) as SNAPSHOT_TIMESTAMP,
tables.OBJ_ID,
object.OBJ_NAME,
object.obj_schema,
tables.ESTIMATED_SIZE
FROM
SYSTOOLS.STMG_TABLE tables
INNER JOIN
SYSTOOLS.STMG_OBJECT object
ON tables.obj_id = object.obj_id AND tables.stmg_timestamp =
object.stmg_timestamp
GROUP BY tables.STMG_TIMESTAMP, tables.ESTIMATED_SIZE, tables.obj_id,
object.obj_name, object.obj_schema
The number of bytes used by the table is displayed in the
ESTIMATED_SIZE
column.

You can also delete historical snapshots by deleting entries from the
SYSTOOLS.STMG_ROOT_OBJECT table. To delete all historical data, run
the
following query:

DELETE FROM SYSTOOLS.STMG_ROOT_OBJECT

There is also a stored procedure which will drop all of the storage
management tables.

db2 call drop_storagemgmt_tables(0)
All of the snapshot data can easily be viewed using the storage
management
tool which is launched from the DB2 Control Center, Database > Manage
Storage...

The storage management tool provides detailed historical analysis of
the
captured snapshot data for all storage related objects in the
database, as
well as a way to schedule regular snapshots, and delete historical
snapshots.

Craig Tobias
DB2 Admin. Tools Development
IBM Toronto Lab

--
Pierre Saint-Jacques
SES Consultants Inc.
514-737-4515
"dunleav1" <jm*@dunleavyenterprises.com> a écrit dans le message de
news:11********************@f14g2000cwb.googlegrou ps.com...
Yes, I am relying on my statistics to be current.
Thanks for card definition to equal the number of rows.
Since fpages may by 0, what is the best way to calculate the size for
the table and index?


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jgb_dba | last post by:
Hello, I not exactly sure how to determine the table when given the following information: -- Could not find the index for RID '999999' in index page ('1:99999999'), index id ), database...
11
by: SarahMarsden | last post by:
I'm new to Dreamweaver (using MX 2004). I have a 2 row 3 column table. I have set each column to 200 pixels. The second row I have merged into one cell. When I enter text (or anything else) into...
2
by: Stanley Sinclair | last post by:
About to create a table which will "include" a BLOB. Am not sure how large to make the container and the tablespace. What I see says that BLOB is stored "separately." However, I don't know...
1
by: stabbert | last post by:
We are on DB2 UDB 8.2.2 on AIX. I know this question has been asked many times on the ng but I am just not finding a real good answer. I need to be able to not only determine existing table data...
1
by: db2udbgirl | last post by:
Env : DB2 UDB 8.2 / AIX 5.3 When I try to use some DB2 Utilities against a partitioned table which is not defined on a particular node (Node 0 in this case) I'm getting this error. ...
4
by: Suresh.Eddala | last post by:
Hi, I am trying to get file size information in my code. FileInfo().Length is returning the size of the file. I have checked on File information in windows right click properties, it has ...
7
by: xformer | last post by:
Hello everybody, today I was working on a web site when I found a strange effect. Take the following html document: ----begin---- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
2
by: BD | last post by:
Hi, all. My background is more Oracle than db2. My skills at SQL tuning are quite limited. I'm running 8.2 on Windows. I'm tasked with some SQL optimization, and am doing some explain plans...
6
by: shawno | last post by:
Hi, We're running DB2 v8.1 on a windows platform and have a database that is quite large. It basically contains one table with a BLOB field (each blob is a zip file, maybe 500K to 1MB), and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.