IBM Books

Administration Guide


Estimating Space Requirements for Tables

The following information provides a general rule for estimating the size of a database:

After reading these sections, you should read "Designing and Choosing Table Spaces".

Information is not provided for the space required by such things as:

Information such as row size and structure is precise. However, multiplication factors for file overhead because of disk fragmentation, free space, and variable length columns will vary in your own database since there is such a wide range of possibilities for the column types and lengths of rows in a database. After initially estimating your database size, create a test database and populate it with representative data. You will then find a multiplication factor that is more accurate for your own particular database design.

System Catalog Tables

When a database is initially created, system catalog tables are created. The system tables will grow as database objects and privileges are added to the database. Initially, they use approximately 2.5 MB of disk space.

The amount of space allocated for the catalog tables depends on the type of table space and the extent size for the table space containing the catalog tables. For example, if a DMS table space with an extent size of 32 is used, the catalog table space will initially be allocated 20MB of space. For more information, see "Designing and Choosing Table Spaces".
Note:For databases with multiple partitions, the catalog tables only reside on the partition where the CREATE DATABASE was issued. Disk space for the catalog tables is only required for that partition.

User Table Data

By default, table data is stored on 4KB pages. Each 4 KB page contains 76 bytes of overhead for the database manager. This leaves 4020 bytes to hold user data (or rows), although no row can exceed 4005 bytes in length. A row will not span multiple pages. You can have a maximum of 500 columns when using a 4 KB page size.

Note that the table data pages do not contain the data for columns defined with LONG VARCHAR, LONG VARGRAPHIC, BLOB, CLOB, or DBCLOB data types. The rows in a table data page do, however, contain a descriptor of these columns. (See "Long Field Data" and "Large Object (LOB) Data" for information about estimating the space required for the table objects that will contain the data stored using these data types.)

Typically, rows are inserted into the table in an approximate first-fit order. The file is searched (using a free space map) for the first available space that is large enough to hold the new row. When a row is updated, it is updated in place unless there is insufficient room left on the page to contain it. If this is the case, a record is created in the original row location which points to the new location in the table file of the updated row.

If the ALTER TABLE APPEND ON statement is used, then data will always be appended and information about any free space on the data pages will not be kept.

See "Long Field Data" and "Large Object (LOB) Data" for information about how LONG VARCHAR, LONG VARGRAPHIC, BLOB, CLOB and DBCLOB data is stored and for estimating the space required to store these types of columns.

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

Then use records_per_page with:

   (number_of_records/records_per_page) * 1.1 = number_of_pages
Note:This formula is only an estimate and is not guaranteed to be accurate. Accuracy of the estimate lessens if the length of records varies due to fragmentation and overflow records.

The average row size is the sum of the average column sizes. For information on the size of each column, see CREATE TABLE in the SQL Reference.

The factor of "1.1" is for overhead.

You also have the option to create buffer pools or table spaces that have an 8 KB page size. All tables created within this type of table space will have 8 KB page sizes. A single table or index object can then be as large as 128 GB in size (the maximum is 64 GB for a single table or index object with a 4 KB page size). You can have a maximum of 1012 columns when using an 8 KB page size. Rows can be up to 8101 bytes in length.

Having a larger page size allows for the possible reduction in the number of levels in any index. If you are working with OLTP applications which do random row reads and writes, a smaller page size is better because it wastes less buffer space with undesired rows. If you are working with DSS applications which access large numbers of consequtive rows at a time, a larger page size is better because it reduces the number of Input/Output requests required to read a specific number of rows. An exception in this latter cases occurs when the row size is smaller than the page size divided by 256. In such a case, there is wasted space on each page. (Recall that there can only be a maximum of 256 rows per page.) To reduce this wasted space, a smaller page size may be more appropriate.

There are some restrictions when using an 8 KB page size. Using the extended storage cache is not allowed. LOB and LONG data cannot reside on pages 8 KB in size. When conducting backup and restore operations, a table space restore cannot be done from a 4 KB page size to an 8 KB page size; nor the reverse. In addition, you cannot import IXF data files that represent more than 755 columns.

Long Field Data

If a table has LONG VARCHAR or LONG VARGRAPHIC data, in addition to the byte count of 20 for the LONG VARCHAR or LONG VARGRAPHIC descriptor (in the table row), the data itself must be stored. Long field data is stored in a separate table object which is structured differently from the other data types (see "User Table Data" and "Large Object (LOB) Data").

Data is stored in 32KB areas that are broken up into segments whose sizes are "powers of two" times 512 bytes. (Hence these segments can be 512 bytes, 1024 bytes, 2048 bytes, and so on, up to 32,700 bytes.)

Each of these data types is stored in a fashion that enables free space to be reclaimed easily. Allocation and free space information is stored in 4KB allocation pages, which appear infrequently throughout the object.

The amount of unused space in the object depends on the size of the long field data and whether this size is relatively constant across all occurrences of the data. For data entries larger than 255 bytes, this unused space can be up to 50 percent of the size of the long field data.

If character data is less than 4KB in length, and it fits in the record with the rest of the data, the CHAR, GRAPHIC, VARCHAR, or VARGRAPHIC data types should be used instead of LONG VARCHAR or LONG VARGRAPHIC.

Large Object (LOB) Data

If a table has BLOB, CLOB, or DBCLOB data, in addition to the byte count (between 72 and 312 bytes) for the BLOB, CLOB, or DBCLOB descriptor (in the table row), the data itself must be stored. This data is stored in two separate table objects that are structured differently than other data types (see "User Table Data" and "Long Field Data").

To estimate the space required by large object data, you need to consider the two table objects used to store data defined with these data types:

If character data is less than 4KB in length, and it fits in the record with the rest of the data, the CHAR, GRAPHIC, VARCHAR, or VARGRAPHIC data types should be used instead of BLOB, CLOB or DBCLOB.

Index Space

For each index, the space needed can be estimated as:

   (average index key size + 8) * number of rows * 2

where:

Note:For every column that allows nulls, add one extra byte for the null indicator.

Temporary space is required when creating the index. The maximum amount of temporary space required during index creation can be estimated as:

   (average index key size + 8) * number of rows * 3.2

Where the factor of 3.2 is for index overhead as well as space required for the sorting needed to create the index.
Note:In the case of non-unique indexes, only four (4) bytes are required to store duplicate key entries. The estimates shown above assume no duplicates. The space required to store an index may be over-estimated by the formula shown above.

The following two calculations can be used to estimate the number of leaf pages. The results are not guaranteed. The results are only an estimate, and the accuracy depends largely on how well the averages used reflect the actual data.
Note:For SMS, the minimum space is 12KB. For DMS, the minimum is an extent.

Following are two methods that you can use when calculating index space. The first method is a rough estimate, while the second method provides a more accurate estimate:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]