Wednesday, July 2, 2008

To Calculate size of table

By default, DB2 uses the following values for primary space allocation of DB2–managed data sets:
1 cylinder (720 KB) for non-LOB table spaces
10 cylinders for LOB table spaces
1 cylinder for indexes

How to calculate the size of Index:
I had been using Approach 1 across various DB2 UDB projects , other alternates are listed below Approach 1 ------------ Index Space Size = (average index key size + 8) * no of rows * 2 Approach 2 ------------ Index size estimation : Avg Sum of column widths * Expected no of rows
Approach 3 ------------- Use Control center

I've planned to use the following steps to determine the DMS tablespace size. Pls correct me if I'm wrong else pls give your ack.
Think Scenario:For a single table I've deceided to use a seperate tablespaces for Index & Data. hence
Table Size = Avg Byte count per Row * No. of rows
Avg Byte count per Row is derived using this query after runing the runstats against that table.
SELECT sum(AVGCOLLEN) FROM SYSCAT.COLUMNS where tabname='TestTable'

Hence in my case the mathematics involved is as follows..
Table Size = Avg Byte count per Row * No. of rows= 262 * 132800000
= 34793600000 bytes= 32.40406513214 GB

Can you please let me know whether this inference is correct ? Any suggestions highly appreciated.

DB2 Space ManagementObjects are stored in data files which are logically grouped in tablespaces. If you choose Database Managed Tablespace(DMS), then when the size you allocated to associated data files is over, you have to increase by desired amount. If it is System Managed Tablespace(SMS), then DB2 every time data files space is over, additional extents are allocated. This repeated allocation & OS checks lead to less performance.
The smallest unit of database storage is page whose sizes are like 4K, 8K, 16K, 32K etc. A number of these are contained in an OS block.
In windows when the drive closes & in UNIX the max folder/file size is exceeded, functioning stops till you clear some space.
In RAM, buffer pools exist having buffer size which should be same as page size of tablespace to which this bufferpool is assigned.
Only table & index need space for data else for all objects only definition is stored for which very less space is required.
Table, index & temporary tablespace sizes are calculated as follows:
Table size = ((Average row size * number of rows) + 8) * 1.5
Index Size = ((Average key size * number of rows) + 8) * 2
Temporary tablespace size = ((Average key size * number of rows) + 8) * 3.2
The unit will be bytes.Average row/key size for table/index can be got by right click on given table/index and choosing estimate size option.
The other way is total the bytes of all columns keeping 75% of varchar columns.
For temporary tablespace, group function columns like max, avg etc., group by and order by have to be considered since sorting is involved.
Apply the formula for each such set. 1.5, 2 & 3.2 are buffer multipliers.
Along with size, growth also needs to be estimated initially on project basis & later based on actual results.
To store objects & data which will be read only one can use SMS. But for growing database i.e. tablespaces i.e. datafiles i.e. bufferpools i.e. buffers, one has to select a DMS tablespace with optimum size balancing between maintainence & performance.
ReplicationYes, DB2 supports both synchronous & asynchronous and uni & bi-directional replication.
Synchronous means both source & target will be continuously in sync where as asynchronous implies periodaically.
Uni means one is source & the other target.
Bi means both are source & both are target.

SQL CompliantDB2 obeys/follows ANSI SQL 99 standards.User ManagementWhat ghp7000 said is true about this. DB2 can have only OS users & no database users. Hence number of users allowed by OS can become a limit. And off course the resources that are allocated to a OS user like part of RAM can decided the upper limit for their count. You can check Appendix G i.e. SQL limits in SQL Reference for the OS & DB2 type & version obtainable as a PDF from IBM DB2 site.
For estimating index and tablespace size in db2 i used the formula ------------------------------------------------------------------------------
1) Average Row Size: The average row size is the sum of the average column sizes
2) For each user table in the database, the number of 4 KB pages can be estimated by calculating: ROUND DOWN(4020/(average row size + 10)) = records_per_page
3) Then use records_per_page with: (number_of_records/records_per_page) * 1.1 = number_of_pagesThe factor of "1.1" is for overhead
4)For each index, the space needed can be estimated as: (average index key size + 9) * number of rows * 2

No comments: