Summary: This article helps the new DB2® database administrator understand the importance of table spaces and buffer pools. The article also explains how properly designing and tuning table spaces and buffer pools can enhance database performance.[Originally written in 2002, this article has been updated for IBM DB2 V9.7 for Linux®, UNIX®, and Windows®.]
View more content in this series
Tags for this article: administration, basic, basics, buffer, buffer_pool, bufferpool, buffpage,configuration_and_administration, database, databases_and_data_management... more tags
Date: 22 Apr 2010 (Published 19 Dec 2002)
Level: Introductory
PDF: A4 and Letter (63KB | 16 pages)Get Adobe® Reader®
Also available in: Russian Portuguese Spanish
Activity: 62684 views
Comments: 12 (View | Add comment - Sign in)
For the database administrator (DBA) who is just stepping into the world of DB2 or for the prospective DBA, the design and performance choices for a new database can be very confusing. This article discusses two areas in which the DBA has important choices to make: table spaces and buffer pools. The design and tuning of table spaces and buffer pools can have a profound impact on how the DB2 server performs.
In this article, the examples use DB2 Version 9.7, Enterprise Server Edition. Most of the examples also apply to downlevel versions, unless otherwise indicated.
The article does the following:
All data for a database is stored in a number of table spaces. You can think of a table space as a child and a database as its parent, where the table space (child) cannot have more than one database (parent). Because there are different uses for table spaces, they are classified according to their usage and how they will be managed. There are five different table spaces, named according to their usage:
Table spaces can be managed in one of two ways:
However, containers cannot be dropped from SMS table spaces, and adding new ones is restricted to partitioned databases. In version 9.1 and above, the only default SMS tablespace created during database creation is TEMPSPACE1.
Listing 1 shows how to increase container sizes:
ALTER TABLESPACE TS1 RESIZE (FILE '/conts/cont0' 2000, DEVICE '/dev/rcont1' 2000, FILE 'cont2' 2000) |
You can also use options such as EXTEND or REDUCE to increase or decrease the size of a container.
How to create and view your table spaces
When you create a database, three table spaces are created (SYSCATSPACE, TEMPSPACE1, and USERSPACE1). Listing 2 shows you how to create a database called testdb, connect to it, and list the table spaces using the DB2 command window or the UNIX command line.
CREATE DATABASE testdb CONNECT TO testdb LIST TABLESPACES |
Listing 3 shows the output from the LIST TABLESPACES command.
Tablespaces for Current Database Tablespace ID = 0 Name = SYSCATSPACE Type = Database managed space Contents = All permanent data. Regular table space. State = 0x0000 Detailed explanation: Normal Tablespace ID = 1 Name = TEMPSPACE1 Type = System managed space Contents = System Temporary data State = 0x0000 Detailed explanation: Normal Tablespace ID = 2 Name = USERSPACE1 Type = Database managed space Contents = All permanent data. Large table space. State = 0x0000 Detailed explanation: Normal |
The CREATE DATABASE command automatically creates the three table spaces in Listing 3. The user can override the default table space creation by including table space specifications in the command, but a catalog table space and at least one regular or large and one system temporary table space must be created at database creation time. More table spaces of all types (except catalog table space) can be created either with the CREATE DATABASE command, or later using the CREATE TABLESPACE command.
Each table space has one or more containers. Again, you might think of a container as being a child and a table space as its parent. Each container can belong to only a single table space, but a table space can have many containers. Containers can be added to or dropped from a DMS table space, and their sizes can be modified. Containers can only be added to SMS table spaces on partitioned databases in a partition that does not yet have a container allocated for the table space. When new containers are added, an automatic rebalancing distributes the data across all containers. Rebalancing does not prevent concurrent access to the database.
There are several settings that you can specify for table spaces, either when you create them or later with an ALTER TABLESPACE statement. The following list describes the settings.
4 005 | 500 | 64 GB |
8 101 | 1 012 | 128 GB |
16 293 | 1 012 | 256 GB |
32 677 | 1 012 | 512 GB |
Table spaces are limited to 16,777,216 pages, so choosing a larger page size will increase the capacity of the table space.
Example of a CREATE TABLESPACE statement
Listing 4 creates a regular table space, including all the settings from this article.
CREATE TABLESPACE USERSPACE3 PAGESIZE 8K MANAGED BY SYSTEM USING ('d:\usp3_cont1', 'e:\usp3_cont2', 'f:\usp3_cont3') EXTENTSIZE 64 PREFETCHSIZE 32 BUFFERPOOL BP3 OVERHEAD 7.5 TRANSFERRATE 0.06 |
How to view your table space attributes and containers
Specifying the SHOW DETAIL option of the LIST TABLESPACES command shows additional information: LIST TABLESPACES SHOW DETAIL
.
Listing 5 shows the output for the USERSPACE1 table space. By default, the three table spaces created at database creation time will be listed.
Tablespaces for Current Database Tablespace ID = 2 Name = USERSPACE1 Type = Database managed space Contents = All permanent data. Large table space. State = 0x0000 Detailed explanation: Normal Total pages = 8192 Useable pages = 8160 Used pages = 96 Free pages = 8064 High water mark (pages) = 96 Page size (bytes) = 4096 Extent size (pages) = 32 Prefetch size (pages) = 32 Number of containers = 1 |
To list the containers needed to use the Tablespace ID from the output above, enter LIST TABLESPACE CONTAINERS FOR 2
.
Tablespace Containers for Tablespace 2 Container ID = 0 Name = C:\DB2\NODE0000\SQL00004\SQLT0002.0 Type = Path |
The command lists all containers for the specified table space. The path in Listing 6 points to where the container physically resides.
A buffer pool is associated with a single database and can be used by more than one table space. When considering a buffer pool for one or more table spaces, you must ensure that the table space page size and the buffer pool page size are the same for all table spaces that the buffer pool services. A table space can only use one buffer pool.
When the database is created, a default buffer pool named IBMDEFAULTBP is created, which is shared by all table spaces. More buffer pools can be added using the CREATE BUFFERPOOL statement. The buffer pool size defaults to the size specified by the BUFFPAGE database configuration parameter, but you can override it by specifying the SIZE keyword in the CREATE BUFFERPOOL command. Adequate buffer pool size is essential to good database performance, because it will reduce disk I/O, which is the most time consuming operation. Large buffer pools also have an effect on query optimization, because more of the work can be done in memory.
Example of CREATE BUFFERPOOL statement
For an example of the CREATE BUFFERPOOL statement, enter: CREATE BUFFERPOOL BP3 SIZE 2000 PAGESIZE 8K
This buffer pool is assigned to USERSPACE3 on this article's CREATE TABLESPACE example and is created before creating the table space. Note that the page sizes of 8K for the buffer pool and table space are the same. If you create the table space after creating the buffer pool, you can leave out the BUFFER POOL BP3 syntax in the CREATE TABLESPACE statement. Instead, you can use the ALTER TABLESPACE command to add the buffer pool to the existing table space by entering ALTER TABLESPACE USERSPACE3 BUFFERPOOL BP3
.
How to view your buffer pool attributes
You can list buffer pool information by querying the SYSCAT.BUFFERPOOLS system view, as shown in Listing 7.
SELECT * FROM SYSCAT.BUFFERPOOLS BPNAME BUFFERPOOLID DBPGNAME NPAGES PAGESIZE ESTORE NUMBLOCKPAGES BLOCKSIZE ------------ ------------ -------- ------ -------- ------ ------------- --------- IBMDEFAULTBP 1 - 1000 4096 N 0 0 1 record(s) selected. |
To find out which buffer pool is assigned to table spaces, run the query shown in Listing 8.
SELECT TBSPACE, BUFFERPOOLID FROM SYSCAT.TABLESPACES TBSPACE BUFFERPOOLID ----------- ------------ SYSCATSPACE 1 TEMPSPACE1 1 USERSPACE1 1 3 record(s) selected. |
The BUFFERPOOLID is shown in the query in Listing 8, enabling you to see which buffer pool is associated with each table space.
Visual diagram of how a database holds table spaces
Now that you know what a table space and buffer pool are and how to create them, Figure 1 shows an example of how they are visually organized within a database.
The example database has five table spaces: one catalog, two regular, one large, and one system temporary table space. No user temporary table space was created. There are eight containers. In this example, buffer pools might be assigned as follows:
Examining performance implications
In general, when designing table space and container placement on physical devices, the goal is to maximize I/O parallelism and buffer utilization. To achieve that goal, you need a thorough understanding of the database design and applications. Only then can you determine such issues as whether segregating two tables to different devices will lead to parallel I/O, or whether a table should be created in a separate table space so it can be fully buffered.
Start designing the physical layout of a new database by designing the table space organization, as shown in the following steps.
This process is iterative, and the design should be verified with stress-testing and benchmarking. Clearly, arriving at the best design can be quite an intensive effort, so the time it takes can only be justified if the database performance must be the best possible. As a rule:
Often a slight degradation in performance is well worth the reduced complexity of administering and maintaining a simpler database design. DB2 has sophisticated resource-management logic, which standardly produces very good performance without elaborate design.
Each table, depending on how it is accessed most frequently, has a most efficient set of table space settings: PAGESIZE, EXTENTSIZE, and PREFETCHSIZE.
The catalog table space and system temporary table spaces should usually be allocated as SMS. There is no reason to have more than one temporary table space of the same page size, and usually one with the largest page size is sufficient.
The salient question is whether to split up the user data into multiple table spaces or not. One consideration is the utilization of pages. Rows cannot be split between pages, so tables with long rows require the appropriate page size. However, there cannot be more than 255 rows on a page, so tables with short rows do not utilize the whole page.
For example, a table with a row length of 12 bytes placed in a table space with 32K page size utilizes only about 10% of each page, which is calculated as (255 rows * 12 bytes) + 91 bytes of overhead) / 32k page size = ~10%. This is only a consideration if the table is large, which means the wasted space is significant. It also makes I/O and buffering less efficient, because the actual useful content of each page is small.
If a table can either be placed into a smaller page size table space or fully utilize a larger page size, then the most frequent method of access determines which one is better. If typically more rows are accessed sequentially (maybe the table is clustered), then the larger page size is more efficient. If rows are accessed randomly, then the smaller page size enables DB2 to make better use of the buffer, because more pages fit into the same storage area.
After you group the tables by page size, access frequency and type determine whether further grouping the data into separate table spaces is warranted. EXTENTSIZE is the number of pages of data that will be written to a container before writing to the next container (if multiple containers exist in the table space).
PREFETCHSIZE specifies the number of pages to be read from the table space when data prefetching is being performed. Prefetching is used when the Database Manager determines that sequential I/O is appropriate and that prefetching can help to improve performance (typically large table scans). It is a good practice to explicitly set the PREFETCHSIZE value as a multiple of the EXTENTSIZE value for your table space and the number of table space containers. For example, if the EXTENTSIZE is 32 and there are four containers, then good PREFETCHSIZEs would be 128, 256, and so on. If one or more heavily used tables require a different set of these parameters than the values that are best for the rest of the table space performance, put the heavily used tables into a separate table space to improve overall performance.
If prefetching is an important factor in a table space, consider setting aside part of the buffer for block-based I/O. The block size should be equal to the PREFETCHSIZE.
The most important reason to use more than one user table space is to manage buffer utilization. A table space can be associated with only one buffer pool, but one buffer pool can be used for more than one table space.
The goal of buffer pool tuning is to help DB2 make the best possible use of the memory available for buffers. The overall buffer size has a significant effect on DB2 performance, because a large number of pages can significantly reduce I/O, which is the most time-consuming operation. However, if the total buffer size is too large, and there is not enough storage to allocate them, a minimum system buffer pool for each page size is allocated, and performance is sharply reduced. To calculate the maximum buffer size, DB2 considers all other storage utilization, the operating system, and any other applications. Once the total available size is determined, this area can be divided into different buffer pools to improve utilization. If there are table spaces with different page sizes, there must be at least one buffer pool per page size.
Having more than one buffer pool can preserve data in the buffers. For example, you might have a database with many very-frequently used small tables, which would normally be in the buffer in their entirety to be accessible very quickly. You might also have a query that runs against a very large table that uses the same buffer pool and involves reading more pages than the total buffer size. When this query runs, the pages from the small, very frequently used tables are lost, making it necessary to re-read them when they are needed again. If the small tables have their own
评论