Escolar Documentos
Profissional Documentos
Cultura Documentos
Part 1
- Rahul Anand
WHAT IS A TABLESPACE
When you create a table (or an index), you create them in a tablespace. They
make you life easy by relieving you from the need to specify the full storage path
for every single table you create, which otherwise would have made the task of
creating a single table too cumbersome, complex and error prone.
TABLE
TABLESPACE
TBSP_01
For db2 SAMPLE database, the output is shown above. For a single partition
databases, there is only one partition group by default – IBMDEFAULTGROUP. A
bufferpool is a "RAM" memory of the database where data is fetched from the
containers of a tablespace for further processing by DB2.
CLASSIFICATION OF TABLESPACES
I will illustrate the other options used in CREATE TABLESPACE commands used
in above illustrations later.
From the type of data the tablespace deals with, it can be categorized as
1) USER TABLESPACE
2) SYSTEM TEMPORARY TABLESPACE
3) USER TEMPORARY TABLESPACE
1) REGULAR TABLESPACES
2) LARGE TABLESPACES
LARGE TABLESPACES: From V9, DB2 introduced 6BYTE RID to identify each
row of a table. These larger RID allows bigger table sizes and hence bigger
tablespace sizes.
NOTE: The RID is used to uniquely identify a row for a table in a tablespace.
PAGE & PAGESIZE: The smallest building block of tablespace is called PAGE. It
is the number of bytes of storage (or memory location) that is allocated for the
purpose of storing information (data). It is similar to a paper page used in files. A
file consists of several classified documents and each of these classified
documents contains information written over a set of papers (writing material).
Similarly, we have a PAGE in database system. Each table/index (classified
information about an entity) occupies space on storage. The smallest unit of
storage that is allocated to these tables (paper page) is called a page.
EXTENT SIZE: This is applicable only when you have more than one container
defined for a tablespace (C:\db2\sample\MY_DMS_TABLESPACE\C00 and
C:\db2\sample\MY_DMS_TABLESPACE\C01 in our example for MY_DMS_TABLESPACE tablespace).
When there are multiple containers, DB2 reserves a predefined number of pages
from the first container (defined by the parameter EXTENT SIZE). Once all the
pages are exhausted, it skips to the next container (C01) and reserves another
extent of pages. This is repeated in a round-robin fashion. The default value is 32.
Once a tablespace is created, you cannot change this value.
Extent size =4
EXTENT 1
C01 1 1 1 5 5 5 5 9 9 9 9 … …
EXTENT 2
2 2 2 6 6 6 6 10 10 10 10
C02
EXTENT
3 3 3 3 7 7 7 7 … …
C03
EXTENT
C04 4 4 4 4 8 8 8 8 … … …
PREFETCH SIZE: When data is fetched is from pages of tablespaces to be read
in memory (bufferpools), they are fetched in block of pages. These number of
pages in these blocks is called PREFETCH SIZE. Pre Fetching helps in reducing
wait cycles in IO and improves READ performance, especially for sequential bulk
reads. This parameter can be changed after a tablespace is created.
TABLESPACE ACCESS
You can specify a tablespace for your table (or index) by using the IN clause of the
create table command.
db2 "CREATE TABLE ABC.T3(C1 INT, C2 CLOB(1000) ) IN DATA_TBSP INDEX IN INDEX_TBSP
LONG IN LONG_TBSP"
The IN clause identifies the tablespace for data, INDEX IN for index data and
LONG IN for LOB/XML data. If you don’t specify the index/long tablespaces, DB2
will use the DATA tablespace for the same. If you don’t specify the tablespace for
DATA, DB2 will pick up the first available tablespace with the minimum page size.
If no tablespace is available, an error is thrown.
In order to be able to use a tablespace for a table, the ID that creates the table
must have direct (or indirect access via group/role membership) USE privilege on
the tablespace. You can grant the USE privilege on a tablespace by using the
GRANT USE OF TABLESPACE command.
db2 "GRANT USE OF TABLESPACE MY_SMS_TABLESPACE to user1"
VIEWING TABLESPACES
On a DPF database, the command shows the output only for the partition that you
are connected to. In order to get the output on all the nodes, use db2_all.
db2 "list tablespaces show detail"
db2_all "db2 list tablespaces show detail"
Tablespace ID = 7
Name = MY_DMS_TABLESPACE
Type = Database managed space
Contents = All permanent data. Regular table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 3000
Useable pages = 2912
Used pages = 288
Free pages = 2624
High water mark (pages) = 288
Page size (bytes) = 8192
Extent size (pages) = 32
Prefetch size (pages) = 64
Number of containers = 2
9 record(s) selected.
9 record(s) selected.
SYSIBMADM.TBSP_UTILIZATION
Data type Column
Column name schema Data type name Length Scale Nulls
SNAPSHOT_TIMESTAMP SYSIBM TIMESTAMP 10 6 Yes
TBSP_ID SYSIBM BIGINT 8 0 Yes
TBSP_NAME SYSIBM VARCHAR 128 0 Yes
TBSP_TYPE SYSIBM VARCHAR 10 0 Yes
TBSP_CONTENT_TYPE SYSIBM VARCHAR 10 0 Yes
TBSP_CREATE_TIME SYSIBM TIMESTAMP 10 6 No
TBSP_STATE SYSIBM VARCHAR 256 0 Yes
TBSP_TOTAL_SIZE_KB SYSIBM BIGINT 8 0 Yes
TBSP_USABLE_SIZE_KB SYSIBM BIGINT 8 0 Yes
TBSP_USED_SIZE_KB SYSIBM BIGINT 8 0 Yes
TBSP_FREE_SIZE_KB SYSIBM BIGINT 8 0 Yes
TBSP_UTILIZATION_PERCENT SYSIBM DECIMAL 5 2 Yes
TBSP_TOTAL_PAGES SYSIBM BIGINT 8 0 Yes
TBSP_USABLE_PAGES SYSIBM BIGINT 8 0 Yes
TBSP_USED_PAGES SYSIBM BIGINT 8 0 Yes
TBSP_FREE_PAGES SYSIBM BIGINT 8 0 Yes
TBSP_PAGE_TOP SYSIBM BIGINT 8 0 Yes
TBSP_PAGE_SIZE SYSIBM INTEGER 4 0 No
TBSP_EXTENT_SIZE SYSIBM INTEGER 4 0 No
TBSP_PREFETCH_SIZE SYSIBM BIGINT 8 0 Yes
TBSP_MAX_SIZE SYSIBM BIGINT 8 0 Yes
TBSP_INCREASE_SIZE SYSIBM BIGINT 8 0 Yes
TBSP_INCREASE_SIZE_PERCENT SYSIBM SMALLINT 2 0 Yes
TBSP_LAST_RESIZE_TIME SYSIBM TIMESTAMP 10 6 Yes
TBSP_LAST_RESIZE_FAILED SYSIBM SMALLINT 2 0 Yes
TBSP_USING_AUTO_STORAGE SYSIBM SMALLINT 2 0 Yes
TBSP_AUTO_RESIZE_ENABLED SYSIBM SMALLINT 2 0 Yes
DBPGNAME SYSIBM VARCHAR 128 0 No
TBSP_NUM_CONTAINERS SYSIBM BIGINT 8 0 Yes
REMARKS SYSIBM VARCHAR 254 0 Yes
DBPARTITIONNUM SYSIBM SMALLINT 2 0 Yes
SNAPSHOT_TIMESTAMP: The timestamp at which you ran the SQL to get the
info (or current time)
Please note that total size of tablespace can be calculated by formula: Total
pages * Total pages (in bytes).
TBSP_PAGE_TOP: This is the current page number of the first free extent that is
available above the last allocated extent. (Remember tablespace pages are
allocated in terms of extent sizes). This indicates the HIGH WATERMARK of the
tablespace. It is not an indicator of the total used space. There could be
pages(extents) that are free but lie below the HIGH WATER MARK(HWM). These
extents are not usable, because DB2 allocated extents of pages above the HWM.
This is applicable for DMS tablespaces only.
Consider, for a tablespace, Total pages = 4096 and Extent size = 32. Then total
number of extents=Total Pages/Extent Size= 128. Now, if LIST TABLESPACE
command shows High water mark =96. Then it means that the last extent number
(all extents in a tablespace are indexed from 0 onwards) that was allocated is
96/Extent Size, i.e. 96/32 or 4.
If the last allocated Extent number (or HWM) is very high ~ Total number of
extents available and there are still considerable number of Free extents (Free
pages/extent size) available, then we need to reorganize the tablespace in order to
bring the HWM down. There are several ways to reduce HWM (like table reorg/
dropping and recreating tables/ ALTER TABLESPACE operations. I don’t want to
dwell much into this topic now.
TABLESPACE STATES
In order to control data integrity and in certain cases, data protection and
recoverability, DB2 controls the access on the tablespace as well as its availability
by putting it in different states. DB2 10.5 infocenter lists 25 different states
available now. This information is available in all the tablespace information
gathering methods discussed above.
Issue db2ts against this hex value to get the meaning of it.
db2tbst 0x800
State = Backup in Progress
db2tbst 0x0000
State = Normal
You can also get the current state of the tablespace by issuing query against
SYSIBMADM.TBSP_UTILIZATION (or SYSIBMADM.MON_TBSP_UTILIZATION).
db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, SUBSTR(TBSP_STATE,1,20)TBSP_STATE FROM
SYSIBMADM.TBSP_UTILIZATION "
TBSP_NAME TBSP_STATE
------------------------------ --------------------
SYSCATSPACE NORMAL
TEMPSPACE1 NORMAL
USERSPACE1 NORMAL
IBMDB2SAMPLEREL NORMAL
IBMDB2SAMPLEXML NORMAL
SYSTOOLSPACE NORMAL
MY_SMS_TABLESPACE BACKUP_IN_PROGRESS
MY_DMS_TABLESPACE BACKUP_IN_PROGRESS
MY_AUTOSTOR_TBSP BACKUP_IN_PROGRESS
9 record(s) selected.
4.To check which tablespaces are currently being backed up (during whole database backup process)
db2 "SELECT TBSP_NAME FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_STATE='BACKUP_IN_PROGRESS'"
Rahul Anand