SlideShare a Scribd company logo
8
Most read
12
Most read
13
Most read
DB2 TABLESPACES
Part 1
A BRIEF INTRODUCTION FOR
BEGINNERS WITH LIST OF
COMMANDS FOR REGULAR
REFERENCE
- Rahul Anand
WHAT IS A TABLESPACE
A tablespace is essentially a logical view of storage encompassing one or more
physical storage devices called containers. When you create a table or an index in
a DB2 (LUW) database, you basically create them in a tablespace. A tablespace is
equivalent to a file folder which holds one or more files.
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.
A container is a building block of a tablespace. A container is an entity that allows
you to write to a disk. It can be a file or a directory or a unformatted disk attached
to database host (raw device). A container belongs to only one tablespace, but a
tablespace can have one or more containers.
TABLE
TABLESPACE
TBSP_01
CONTAINER
/DIR1/TBSP_01/c001
CONTAINER
/DIR3/TBSP_01/c001
CONTAINER
/DIR3/TBSP_01/c001
(Fig. 1) A Tablespace is essentially a group of containers (files or directories)
TABLESPACES AND DATABASE PARTITION GROUPS
A tablespace is created in a database partition group (set of database partitions).
Each tablespace is a mapped to a bufferpool (database memory). The bufferpool
and tablespace must belong to the same database partition group. A database
partition is a subset of db2 database, having its own data and index. You can use
the command to view the database partition groups defined in the db2 database:
db2 "LIST DATABASE PARTITION GROUPS SHOW DETAIL"
DATABASE PARTITION GROUP PMAP_ID DATABASE PARTITION NUMBER IN_USE
---------------------------- ------- ---------------------------- ------
IBMCATGROUP 0 0 Y
IBMDEFAULTGROUP 1 0 Y
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
From operational management perspective, DB2 offers 3 types of tablespaces:
1) SYSTEM MANAGED SPACE (SMS)
2) DATABASE MANAGED SPACE (DMS)
3) AUTOMATIC STORAGE
SMS TABLESPACE: In SMS tablespace, the underlying containers of a
tablespace or PATHS or DIRECTORIES on storage media. Here the underlying
operating system takes over the allocation and growth management of the
tablespace. The space is allocated on demand. Each table/index/lob object is a
separate file in a SMS directory (denoted by SQL00XXX.DAT) file or so. We create
a SMS tablespace by specifying MANAGED BY SYSTEM clause in the CREATE
TABLESPACE command. In SMS tablespace, the user does not has to worry
about the managing the space growth of the tablespace, as long as there is
sufficient space on the disk for the directory to grow.
ILLUSTRATION: CREATING A SMS TABLESPACE
CREATE REGULAR TABLESPACE MY_SMS_TABLESPACE
IN DATABASE PARTITION GROUP IBMDEFAULTGROUP
PAGESIZE 8192
MANAGED BY SYSTEM USING ( 'C:db2sampleMY_SMS_TABLESPACE' )
ON DBPARTITIONNUM ( 0 )
BUFFERPOOL IBMDEFAULTBP
DROPPED TABLE RECOVERY ON;
DMS TABLESPACE: In DMS tablespace, the underlying container is a file or a
raw device. Here the onus of space management lies on the user(dba) of the
database. He or she is required to add space to the tablespace once it exhausts
the allocated space. In this case, all data objects lies on the container file(s). We
create a DMS tablespace by specifying MANAGED BY DATABASE clause in the
CREATE TABLESPACE command.
ILLUSTRATION: CREATE A DMS TABLESPACE
CREATE REGULAR TABLESPACE MY_DMS_TABLESPACE
IN DATABASE PARTITION GROUP IBMDEFAULTGROUP
PAGESIZE 8192
MANAGED BY DATABASE USING ( FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000, FILE
'C:db2sampleMY_DMS_TABLESPACEC01' 2000 )
BUFFERPOOL IBMDEFAULTBP;
AUTOMATIC STORAGE TABLESPACE: An automatic storage tablespace is a
kind of trade-off between DMS and a SMS tablespace. You don’t have to specify
the container path/file for these tablespaces. These tablespaces makes use of the
storage groups defined on the database. You can use the default one (defined
while database was created) or create your own customized one. In this type of
tablespaces, we define an initial size of the tablespace (in KB/MB/GB) and an
increment unit (either in KB/MB/GB or in percent of the current size of the
tablespace). When the space in the tablespace is exhausred, DB2 will increment
the size of the tablespace by this specified increment amout.
ILLUSTRATION: CREATE A AUTOMATIC STORAGE TABLESPACE
CREATE STOGROUP MY_STORAGE_GROUP ON 'C:db2sample'
CREATE REGULAR TABLESPACE MY_AUTOSTOR_TBSP
IN DATABASE PARTITION GROUP IBMDEFAULTGROUP
PAGESIZE 8192
MANAGED BY AUTOMATIC STORAGE
USING STOGROUP IBMSTOGROUP
AUTORESIZE YES
INCREASESIZE 10 M
MAXSIZE 10 G
BUFFERPOOL IBMDEFAULTBP
;
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
A user tablespace contains the data for the user-defined tables.
A system-temporary tablespace is used by DB2 to hold temporary data while
performing certain specific operations such as a join and a sorting data.
A user-temporary tablespace is used to hold data for GLOBAL TEMPORARY
TABLES (CGTT & DGTT).
Based on size of RID, tablespace can also be categorized as :
1) REGULAR TABLESPACES
2) LARGE TABLESPACES
REGULAR TABLESPACES: This was a feature of old db2 version. These
tablespace use 4-byte RID (record identifier). This has a limitation that the
maximum size of the table on a 32K pagesize tablespace could be 512G max.
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.
Max. Size of a table 4K PAGESIZE 8K PAGESIZE 16K PAGESIZE 32K PAGESIZE
REGULAR (GB) 64 128 256 512
LARGE (TB) 8 16 32 64
NOTE: The RID is used to uniquely identify a row for a table in a tablespace.
IMPORTANT CONFIGURATION PARAMETERS OF TABLESPACES
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.
The number of bytes in a page is called a PAGESIZE. DB2 supports 4 types of
pages – 4K (4096 bytes), 8K (8192 bytes), 16K (16384 bytes) and 32 K(32768
bytes). Just as a large paper page size (A4/A4 etc.) allows to write larger
sentences, similarly larger the tablespace page size, the larger the length of the
row will be.
PAGESIZE 4K PAGESIZE 8K PAGESIZE 16K PAGESIZE 32K PAGESIZE
ROW SIZE 4005 8101 16293 32677
EXTENT SIZE: This is applicable only when you have more than one container
defined for a tablespace (C:db2sampleMY_DMS_TABLESPACEC00 and
C:db2sampleMY_DMS_TABLESPACEC01 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
C01
1
1 1 1 5 5 5 5 9 9 9 9 … …
EXTENT
C02
2
2 2 2 6 6 6 6 10 10 10 10
EXTENT
C03
3 3 3 3 7 7 7 7 … …
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.
OVERHEAD: This is measured in number of milliseconds. It is the sum of IO
controller overhead and disk seek and latency time.
TRANSFERRATE: This is also measured in number of milliseconds and is another
IO cost parameter marker. This is the time required to read a PAGE to bufferpool.
Both OVERHEAD and TRANSFERRATE are used by DB2 Optimizer to determine
the IO costs involved with query execution. Both of them can be changed after a
tablespace is created.
BUFFERPOOL: A bufferpool is a working memory of the database (portion of
RAM or more precisely database memory allocated to DB2 to fetch data from disk
so that it could be processed and returned to the caller). A tablespace is bounded
to a bufferpool, since you cannot perform any data processing without first fetching
the data from disk to memory. Both the tablespace and the associated bufferpool
should have the same page size and must reside in the same database partition
group.
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
DB2 provides LIST TABLESPACE [SHOW DETAIL] command to check the
available tablespaces. A section of the output of the LIST TABLESPACES SHOW
DETAIL command executed on sample database is shown below for the
tablespace MY_DMS_TABLESPACE that we created above.
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
You can also query SYSCAT.TABLESPACES/SYSIBMADM.TBSP_UTILIZATION/
SYSIBMADM.MON_TBSP_UTILIZATION catalog table/views to get the details.
db2 "SELECT SUBSTR(TBSPACE, 1, 16)TBSPACE, TBSPACETYPE, DATATYPE, PAGESIZE,
EXTENTSIZE, PREFETCHSIZE FROM SYSCAT.TABLESPACES"
TBSPACE TBSPACETYPE DATATYPE PAGESIZE EXTENTSIZE PREFETCHSIZE
---------------- ----------- -------- ----------- ----------- ------------
SYSCATSPACE D A 8192 4 -1
TEMPSPACE1 S T 8192 32 -1
USERSPACE1 D L 8192 32 -1
IBMDB2SAMPLEREL D L 8192 32 -1
IBMDB2SAMPLEXML D L 8192 32 -1
SYSTOOLSPACE D L 8192 4 -1
MY_SMS_TABLESPAC S A 8192 32 -1
MY_DMS_TABLESPAC D A 8192 32 -1
MY_AUTOSTOR_TBSP D A 8192 32 -1
9 record(s) selected.
db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM, TBSP_PAGE_SIZE, TBSP_TOTAL_PAGES,
TBSP_USED_PAGES, TBSP_FREE_PAGES FROM SYSIBMADM.TBSP_UTILIZATION"
TBSP_NAME DBPARTITIONNUM TBSP_PAGE_SIZE TBSP_TOTAL_PAGES TBSP_USED_PAGES TBSP_FREE_PAGES
---------- -------------- -------------- -------------------- -------------------- --------------------
SYSCATSPAC 0 8192 20480 16940 3536
TEMPSPACE1 0 8192 0 0 0
USERSPACE1 0 8192 4096 2080 1984
IBMDB2SAMP 0 8192 4096 608 3456
IBMDB2SAMP 0 8192 4096 1440 2624
SYSTOOLSPA 0 8192 4096 112 3980
MY_SMS_TAB 0 8192 0 0 0
MY_DMS_TAB 0 8192 3000 288 2624
MY_AUTOSTO 0 8192 4096 96 3968
9 record(s) selected.
db2 " SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, MEMBER, TBSP_PAGE_SIZE, TBSP_TOTAL_SIZE_KB,
TBSP_UTILIZATION_PERCENT FROM SYSIBMADM.MON_TBSP_UTILIZATION"
TBSP_NAME MEMBER TBSP_PAGE_SIZE TBSP_TOTAL_SIZE_KB TBSP_UTILIZATION_PERCENT
---------------- ------ -------------------- -------------------- ------------------------
SYSCATSPACE 0 8192 163840 82.73
TEMPSPACE1 0 8192 8 100.00
USERSPACE1 0 8192 32768 51.18
IBMDB2SAMPLEREL 0 8192 32768 14.96
IBMDB2SAMPLEXML 0 8192 32768 35.43
SYSTOOLSPACE 0 8192 32768 2.73
MY_SMS_TABLESPAC 0 8192 48 100.00
MY_DMS_TABLESPAC 0 8192 24000 9.89
MY_AUTOSTOR_TBSP 0 8192 32768 2.36
9 record(s) selected.
In particular, sysibmadm.tbsp_utilization is very useful snapshot table. It provides
most of the details in order to perform the day to day administration with
tablespaces.
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)
TBSP_CREATE_TIME: The timestamp at which the tablespace was created
TBSP_STATE: The tablespace current state.
TBSP_TOTAL_SIZE_KB / TBSP_USABLE_SIZE_KB / USABLE_SIZE_KB /
TBSP_FREE_SIZE_KB: These columns gives us the size of the tablespaces in
KB. We can divide it by 1024 to give values in MB (or 1048576 for GB).
TBSP_UTILIZATION_PERCENT: The _PERCENT column gives us the %
utilization. This can used to writing tablespace usage monitoring scripts.
TBSP_TOTAL_PAGES / TBSP_USABLE_PAGES / TBSP_USED_PAGES /
TBSP_FREE_PAGES : These corresponds the classical output of LIST
TABLESPACE command and gives the tablespace allocation details in terms of
pages rather than actual size.
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.
DBPARTITIONNUM: This gives the tablespace details for a given partition of a
database. For single partition database, this value is 0. For DPF databases, it will
consists the partition numbers of the partitiongroup(DBPGNAME) in which the
tablespace has been built.
TBSP_NUM_CONTAINERS : This field gives the total number of containers for a
DMS tablespace.
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.
For list tablespace output, the state is given in hexadecimal value.
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
We can use the command db2tbst command to get the description of this
hexadecimal value.
For example, if the tablespace is currently being backed up (either by whole
database backup or tablespace backup), then the state filed in output of the list
tablespace will show 0x800.
Issue db2ts against this hex value to get the meaning of it.
db2tbst 0x800
State = Backup in Progress
For normal states, the Hex value will be 0X000
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.
SOME USEFUL COMMANDS FOR TABLESPACES
1. To show all tablespaces
db2 "LIST TABLESPACES SHOW DETAIL"
2. To get usage of dms tablespaces in MB
db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM , (TBSP_TOTAL_SIZE_KB/1024)
TBSP_TOTAL_SIZE_MB, (TBSP_FREE_SIZE_KB /1024) TBSP_FREE_SIZE_MB, TBSP_UTILIZATION_PERCENT FROM
SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_TYPE='DMS' "
3. To check the state of the tablespace
db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM , SUBSTR(CONTAINER_NAME,1,10)
CONTAINER_NAME, CONTAINER_TYPE, TOTAL_PAGES, FS_ID, FS_TOTAL_SIZE_KB, FS_USED_SIZE_KB FROM
SYSIBMADM.CONTAINER_UTILIZATION"
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'"
5. To add 1000 pages to each container of a tablespace
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (ALL 1000)"
6. To add 1000 Pages to just one container c00
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (FILE 'C:db2sampleMY_DMS_TABLESPACEC00'
1000)"
7. To add 1000 pages to container c00 and 2000 pages to c01
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000,
FILE 'C:db2sampleMY_DMS_TABLESPACEC01' 2000)"
8. To reduce 1000 pages from container c00
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE REDUCE (FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000)"
9. To change the prefetchsize to 64
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE PREFETCHSIZE 20"
10. To check which tablespaces use AUTO STORAGE
db2 "SELECT TBSP_NAME FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_USING_AUTO_STORAGE=1"
11. To check the AUTO STORAGE parameters of a tablespace
db2 "SELECT TBSP_MAX_SIZE, TBSP_INCREASE_SIZE, TBSP_INCREASE_SIZE_PERCENT, TBSP_AUTO_RESIZE_ENABLED FROM
SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_NAME='MY_AUTOSTOR_TBSP' "
12. To change the INCREASE_SIZE to 64K
db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP INCREASESIZE 64 K "
12. To change the INCREASE_SIZE to 5%
db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP INCREASESIZE 5 PERCENT "
13. To convert a REGULAR tablespace to LARGE
db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP CONVERT TO LARGE"
14. To turn ON filesystem caching,
db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP FILE SYSTEM CACHING "
15. To add a new container to the tablespace
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE ADD (FILE 'C:db2sampleMY_DMS_TABLESPACEC002' 2000)"
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE ADD (FILE 'C:db2sampleMY_DMS_TABLESPACEC003' 2M) "
(notice that 2M signifies 2 MB)
16. To drop a tablespace
db2 "DROP TABLESPACE MY_TBSP”
17. To bakup a tablespace
db2 "BACKUP DATABASE SAMPLE TABLESPACE MY_DMS_TABLESPACE ONLINE "
18. To bring a tablespace online
db2 "ALTER TABLESPACE MY_DMS_TABLESPACE SWITCH ONLINE"
About Me
I have been working as a DBA for last 10 years, currently with Financial Sector Company. There has been a shortage of documentation on DB2
topics (mostly coming from IBM Infocenter) when compared to MSSQL or Oracle so I wish to help the DBA community, especially the beginners
who face lots of challenges in their initial days. I have been trying to increase the volume of notes on specific topics which are of day to day use. I
hope my notes will be helpful to the DBA community.
I can be contacted via email at rahulanand_db2@yahoo.com .
Rahul Anand

More Related Content

PPT
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
PDF
DB2 LUW - Backup and Recovery
PPTX
SKILLWISE-DB2 DBA
PPTX
Ibm db2
PDF
IBM DB2 for z/OS Administration Basics
 
PDF
Db2 performance tuning for dummies
PPT
2 db2 instance creation
DOCX
Db2 Important questions to read
IBM DB2 LUW UDB DBA Online Training by Etraining.guru
DB2 LUW - Backup and Recovery
SKILLWISE-DB2 DBA
Ibm db2
IBM DB2 for z/OS Administration Basics
 
Db2 performance tuning for dummies
2 db2 instance creation
Db2 Important questions to read

What's hot (20)

PDF
DB2 for z/OS Architecture in Nutshell
PPSX
Solving the DB2 LUW Administration Dilemma
DOC
DB2 utilities
PDF
The InnoDB Storage Engine for MySQL
PPT
DB2 Interview Questions - Part 1
PPT
DB2 and storage management
PDF
Ibm db2 interview questions and answers
PPTX
Mongodb basics and architecture
PPT
Sql Server Basics
PDF
DB2 for z/OS - Starter's guide to memory monitoring and control
PPTX
Introduction to NoSQL Databases
DOC
DB2 DOCUMENT
PDF
DBA Basics guide
PPTX
Nosql databases
PDF
Redo log improvements MYSQL 8.0
PPT
Oracle Transparent Data Encryption (TDE) 12c
PDF
InnoDB Internal
PDF
Db2 recovery IDUG EMEA 2013
PDF
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
DB2 for z/OS Architecture in Nutshell
Solving the DB2 LUW Administration Dilemma
DB2 utilities
The InnoDB Storage Engine for MySQL
DB2 Interview Questions - Part 1
DB2 and storage management
Ibm db2 interview questions and answers
Mongodb basics and architecture
Sql Server Basics
DB2 for z/OS - Starter's guide to memory monitoring and control
Introduction to NoSQL Databases
DB2 DOCUMENT
DBA Basics guide
Nosql databases
Redo log improvements MYSQL 8.0
Oracle Transparent Data Encryption (TDE) 12c
InnoDB Internal
Db2 recovery IDUG EMEA 2013
Practical Recipes for Daily DBA Activities using DB2 9 and 10 for z/OS
Ad

Similar to DB2 TABLESPACES (20)

PPT
DB2UDB_the_Basics Day2
PPTX
tablespaces and datafiles in database administration
PDF
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
PDF
Sap On Udb Layout
 
PPT
Myth busters - performance tuning 103 2008
PDF
Vertica
PPT
DB2 and Storage Management
DOCX
Mohan Testing
PDF
Lecture storage-buffer
DOCX
Oracle Database 12c "New features"
PDF
8 i locally_mgr_tbsp
DOC
Db2 faqs
PPTX
NoSQL - A Closer Look to Couchbase
DOCX
Sql data shrink steps
PPT
Implementing the Databese Server session 02
PPTX
S3 l4 db2 environment - databases
PPTX
Presentation db2 best practices for optimal performance
PPTX
Apache Hadoop India Summit 2011 talk "Hadoop Map-Reduce Programming & Best Pr...
PDF
Presentation db2 best practices for optimal performance
DB2UDB_the_Basics Day2
tablespaces and datafiles in database administration
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
Sap On Udb Layout
 
Myth busters - performance tuning 103 2008
Vertica
DB2 and Storage Management
Mohan Testing
Lecture storage-buffer
Oracle Database 12c "New features"
8 i locally_mgr_tbsp
Db2 faqs
NoSQL - A Closer Look to Couchbase
Sql data shrink steps
Implementing the Databese Server session 02
S3 l4 db2 environment - databases
Presentation db2 best practices for optimal performance
Apache Hadoop India Summit 2011 talk "Hadoop Map-Reduce Programming & Best Pr...
Presentation db2 best practices for optimal performance
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
 
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...

DB2 TABLESPACES

  • 1. DB2 TABLESPACES Part 1 A BRIEF INTRODUCTION FOR BEGINNERS WITH LIST OF COMMANDS FOR REGULAR REFERENCE - Rahul Anand
  • 2. WHAT IS A TABLESPACE A tablespace is essentially a logical view of storage encompassing one or more physical storage devices called containers. When you create a table or an index in a DB2 (LUW) database, you basically create them in a tablespace. A tablespace is equivalent to a file folder which holds one or more files. 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. A container is a building block of a tablespace. A container is an entity that allows you to write to a disk. It can be a file or a directory or a unformatted disk attached to database host (raw device). A container belongs to only one tablespace, but a tablespace can have one or more containers. TABLE TABLESPACE TBSP_01 CONTAINER /DIR1/TBSP_01/c001 CONTAINER /DIR3/TBSP_01/c001 CONTAINER /DIR3/TBSP_01/c001
  • 3. (Fig. 1) A Tablespace is essentially a group of containers (files or directories) TABLESPACES AND DATABASE PARTITION GROUPS A tablespace is created in a database partition group (set of database partitions). Each tablespace is a mapped to a bufferpool (database memory). The bufferpool and tablespace must belong to the same database partition group. A database partition is a subset of db2 database, having its own data and index. You can use the command to view the database partition groups defined in the db2 database: db2 "LIST DATABASE PARTITION GROUPS SHOW DETAIL" DATABASE PARTITION GROUP PMAP_ID DATABASE PARTITION NUMBER IN_USE ---------------------------- ------- ---------------------------- ------ IBMCATGROUP 0 0 Y IBMDEFAULTGROUP 1 0 Y 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 From operational management perspective, DB2 offers 3 types of tablespaces: 1) SYSTEM MANAGED SPACE (SMS) 2) DATABASE MANAGED SPACE (DMS) 3) AUTOMATIC STORAGE SMS TABLESPACE: In SMS tablespace, the underlying containers of a tablespace or PATHS or DIRECTORIES on storage media. Here the underlying operating system takes over the allocation and growth management of the tablespace. The space is allocated on demand. Each table/index/lob object is a separate file in a SMS directory (denoted by SQL00XXX.DAT) file or so. We create a SMS tablespace by specifying MANAGED BY SYSTEM clause in the CREATE TABLESPACE command. In SMS tablespace, the user does not has to worry
  • 4. about the managing the space growth of the tablespace, as long as there is sufficient space on the disk for the directory to grow. ILLUSTRATION: CREATING A SMS TABLESPACE CREATE REGULAR TABLESPACE MY_SMS_TABLESPACE IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8192 MANAGED BY SYSTEM USING ( 'C:db2sampleMY_SMS_TABLESPACE' ) ON DBPARTITIONNUM ( 0 ) BUFFERPOOL IBMDEFAULTBP DROPPED TABLE RECOVERY ON; DMS TABLESPACE: In DMS tablespace, the underlying container is a file or a raw device. Here the onus of space management lies on the user(dba) of the database. He or she is required to add space to the tablespace once it exhausts the allocated space. In this case, all data objects lies on the container file(s). We create a DMS tablespace by specifying MANAGED BY DATABASE clause in the CREATE TABLESPACE command. ILLUSTRATION: CREATE A DMS TABLESPACE CREATE REGULAR TABLESPACE MY_DMS_TABLESPACE IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8192 MANAGED BY DATABASE USING ( FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000, FILE 'C:db2sampleMY_DMS_TABLESPACEC01' 2000 ) BUFFERPOOL IBMDEFAULTBP; AUTOMATIC STORAGE TABLESPACE: An automatic storage tablespace is a kind of trade-off between DMS and a SMS tablespace. You don’t have to specify the container path/file for these tablespaces. These tablespaces makes use of the storage groups defined on the database. You can use the default one (defined while database was created) or create your own customized one. In this type of tablespaces, we define an initial size of the tablespace (in KB/MB/GB) and an increment unit (either in KB/MB/GB or in percent of the current size of the tablespace). When the space in the tablespace is exhausred, DB2 will increment the size of the tablespace by this specified increment amout. ILLUSTRATION: CREATE A AUTOMATIC STORAGE TABLESPACE CREATE STOGROUP MY_STORAGE_GROUP ON 'C:db2sample' CREATE REGULAR TABLESPACE MY_AUTOSTOR_TBSP
  • 5. IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE 8192 MANAGED BY AUTOMATIC STORAGE USING STOGROUP IBMSTOGROUP AUTORESIZE YES INCREASESIZE 10 M MAXSIZE 10 G BUFFERPOOL IBMDEFAULTBP ; 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 A user tablespace contains the data for the user-defined tables. A system-temporary tablespace is used by DB2 to hold temporary data while performing certain specific operations such as a join and a sorting data. A user-temporary tablespace is used to hold data for GLOBAL TEMPORARY TABLES (CGTT & DGTT). Based on size of RID, tablespace can also be categorized as : 1) REGULAR TABLESPACES 2) LARGE TABLESPACES REGULAR TABLESPACES: This was a feature of old db2 version. These tablespace use 4-byte RID (record identifier). This has a limitation that the maximum size of the table on a 32K pagesize tablespace could be 512G max. 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. Max. Size of a table 4K PAGESIZE 8K PAGESIZE 16K PAGESIZE 32K PAGESIZE REGULAR (GB) 64 128 256 512
  • 6. LARGE (TB) 8 16 32 64 NOTE: The RID is used to uniquely identify a row for a table in a tablespace. IMPORTANT CONFIGURATION PARAMETERS OF TABLESPACES 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. The number of bytes in a page is called a PAGESIZE. DB2 supports 4 types of pages – 4K (4096 bytes), 8K (8192 bytes), 16K (16384 bytes) and 32 K(32768 bytes). Just as a large paper page size (A4/A4 etc.) allows to write larger sentences, similarly larger the tablespace page size, the larger the length of the row will be. PAGESIZE 4K PAGESIZE 8K PAGESIZE 16K PAGESIZE 32K PAGESIZE ROW SIZE 4005 8101 16293 32677 EXTENT SIZE: This is applicable only when you have more than one container defined for a tablespace (C:db2sampleMY_DMS_TABLESPACEC00 and C:db2sampleMY_DMS_TABLESPACEC01 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 C01 1 1 1 1 5 5 5 5 9 9 9 9 … … EXTENT C02 2 2 2 2 6 6 6 6 10 10 10 10 EXTENT C03 3 3 3 3 7 7 7 7 … … EXTENT C04 4 4 4 4 8 8 8 8 … … …
  • 7. 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. OVERHEAD: This is measured in number of milliseconds. It is the sum of IO controller overhead and disk seek and latency time. TRANSFERRATE: This is also measured in number of milliseconds and is another IO cost parameter marker. This is the time required to read a PAGE to bufferpool. Both OVERHEAD and TRANSFERRATE are used by DB2 Optimizer to determine the IO costs involved with query execution. Both of them can be changed after a tablespace is created. BUFFERPOOL: A bufferpool is a working memory of the database (portion of RAM or more precisely database memory allocated to DB2 to fetch data from disk so that it could be processed and returned to the caller). A tablespace is bounded to a bufferpool, since you cannot perform any data processing without first fetching the data from disk to memory. Both the tablespace and the associated bufferpool should have the same page size and must reside in the same database partition group. 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
  • 8. 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 DB2 provides LIST TABLESPACE [SHOW DETAIL] command to check the available tablespaces. A section of the output of the LIST TABLESPACES SHOW DETAIL command executed on sample database is shown below for the tablespace MY_DMS_TABLESPACE that we created above. 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 You can also query SYSCAT.TABLESPACES/SYSIBMADM.TBSP_UTILIZATION/ SYSIBMADM.MON_TBSP_UTILIZATION catalog table/views to get the details. db2 "SELECT SUBSTR(TBSPACE, 1, 16)TBSPACE, TBSPACETYPE, DATATYPE, PAGESIZE, EXTENTSIZE, PREFETCHSIZE FROM SYSCAT.TABLESPACES" TBSPACE TBSPACETYPE DATATYPE PAGESIZE EXTENTSIZE PREFETCHSIZE ---------------- ----------- -------- ----------- ----------- ------------ SYSCATSPACE D A 8192 4 -1 TEMPSPACE1 S T 8192 32 -1 USERSPACE1 D L 8192 32 -1 IBMDB2SAMPLEREL D L 8192 32 -1 IBMDB2SAMPLEXML D L 8192 32 -1 SYSTOOLSPACE D L 8192 4 -1 MY_SMS_TABLESPAC S A 8192 32 -1 MY_DMS_TABLESPAC D A 8192 32 -1 MY_AUTOSTOR_TBSP D A 8192 32 -1
  • 9. 9 record(s) selected. db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM, TBSP_PAGE_SIZE, TBSP_TOTAL_PAGES, TBSP_USED_PAGES, TBSP_FREE_PAGES FROM SYSIBMADM.TBSP_UTILIZATION" TBSP_NAME DBPARTITIONNUM TBSP_PAGE_SIZE TBSP_TOTAL_PAGES TBSP_USED_PAGES TBSP_FREE_PAGES ---------- -------------- -------------- -------------------- -------------------- -------------------- SYSCATSPAC 0 8192 20480 16940 3536 TEMPSPACE1 0 8192 0 0 0 USERSPACE1 0 8192 4096 2080 1984 IBMDB2SAMP 0 8192 4096 608 3456 IBMDB2SAMP 0 8192 4096 1440 2624 SYSTOOLSPA 0 8192 4096 112 3980 MY_SMS_TAB 0 8192 0 0 0 MY_DMS_TAB 0 8192 3000 288 2624 MY_AUTOSTO 0 8192 4096 96 3968 9 record(s) selected. db2 " SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, MEMBER, TBSP_PAGE_SIZE, TBSP_TOTAL_SIZE_KB, TBSP_UTILIZATION_PERCENT FROM SYSIBMADM.MON_TBSP_UTILIZATION" TBSP_NAME MEMBER TBSP_PAGE_SIZE TBSP_TOTAL_SIZE_KB TBSP_UTILIZATION_PERCENT ---------------- ------ -------------------- -------------------- ------------------------ SYSCATSPACE 0 8192 163840 82.73 TEMPSPACE1 0 8192 8 100.00 USERSPACE1 0 8192 32768 51.18 IBMDB2SAMPLEREL 0 8192 32768 14.96 IBMDB2SAMPLEXML 0 8192 32768 35.43 SYSTOOLSPACE 0 8192 32768 2.73 MY_SMS_TABLESPAC 0 8192 48 100.00 MY_DMS_TABLESPAC 0 8192 24000 9.89 MY_AUTOSTOR_TBSP 0 8192 32768 2.36 9 record(s) selected. In particular, sysibmadm.tbsp_utilization is very useful snapshot table. It provides most of the details in order to perform the day to day administration with tablespaces. 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
  • 10. 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) TBSP_CREATE_TIME: The timestamp at which the tablespace was created TBSP_STATE: The tablespace current state. TBSP_TOTAL_SIZE_KB / TBSP_USABLE_SIZE_KB / USABLE_SIZE_KB / TBSP_FREE_SIZE_KB: These columns gives us the size of the tablespaces in KB. We can divide it by 1024 to give values in MB (or 1048576 for GB). TBSP_UTILIZATION_PERCENT: The _PERCENT column gives us the % utilization. This can used to writing tablespace usage monitoring scripts. TBSP_TOTAL_PAGES / TBSP_USABLE_PAGES / TBSP_USED_PAGES / TBSP_FREE_PAGES : These corresponds the classical output of LIST TABLESPACE command and gives the tablespace allocation details in terms of pages rather than actual size. 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
  • 11. (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. DBPARTITIONNUM: This gives the tablespace details for a given partition of a database. For single partition database, this value is 0. For DPF databases, it will consists the partition numbers of the partitiongroup(DBPGNAME) in which the tablespace has been built. TBSP_NUM_CONTAINERS : This field gives the total number of containers for a DMS tablespace. 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. For list tablespace output, the state is given in hexadecimal value. 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
  • 12. We can use the command db2tbst command to get the description of this hexadecimal value. For example, if the tablespace is currently being backed up (either by whole database backup or tablespace backup), then the state filed in output of the list tablespace will show 0x800. Issue db2ts against this hex value to get the meaning of it. db2tbst 0x800 State = Backup in Progress For normal states, the Hex value will be 0X000 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. SOME USEFUL COMMANDS FOR TABLESPACES 1. To show all tablespaces db2 "LIST TABLESPACES SHOW DETAIL" 2. To get usage of dms tablespaces in MB db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM , (TBSP_TOTAL_SIZE_KB/1024) TBSP_TOTAL_SIZE_MB, (TBSP_FREE_SIZE_KB /1024) TBSP_FREE_SIZE_MB, TBSP_UTILIZATION_PERCENT FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_TYPE='DMS' " 3. To check the state of the tablespace db2 "SELECT SUBSTR(TBSP_NAME, 1, 16)TBSP_NAME, DBPARTITIONNUM , SUBSTR(CONTAINER_NAME,1,10) CONTAINER_NAME, CONTAINER_TYPE, TOTAL_PAGES, FS_ID, FS_TOTAL_SIZE_KB, FS_USED_SIZE_KB FROM SYSIBMADM.CONTAINER_UTILIZATION" 4.To check which tablespaces are currently being backed up (during whole database backup process)
  • 13. db2 "SELECT TBSP_NAME FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_STATE='BACKUP_IN_PROGRESS'" 5. To add 1000 pages to each container of a tablespace db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (ALL 1000)" 6. To add 1000 Pages to just one container c00 db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000)" 7. To add 1000 pages to container c00 and 2000 pages to c01 db2 "ALTER TABLESPACE MY_DMS_TABLESPACE EXTEND (FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000, FILE 'C:db2sampleMY_DMS_TABLESPACEC01' 2000)" 8. To reduce 1000 pages from container c00 db2 "ALTER TABLESPACE MY_DMS_TABLESPACE REDUCE (FILE 'C:db2sampleMY_DMS_TABLESPACEC00' 1000)" 9. To change the prefetchsize to 64 db2 "ALTER TABLESPACE MY_DMS_TABLESPACE PREFETCHSIZE 20" 10. To check which tablespaces use AUTO STORAGE db2 "SELECT TBSP_NAME FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_USING_AUTO_STORAGE=1" 11. To check the AUTO STORAGE parameters of a tablespace db2 "SELECT TBSP_MAX_SIZE, TBSP_INCREASE_SIZE, TBSP_INCREASE_SIZE_PERCENT, TBSP_AUTO_RESIZE_ENABLED FROM SYSIBMADM.TBSP_UTILIZATION WHERE TBSP_NAME='MY_AUTOSTOR_TBSP' " 12. To change the INCREASE_SIZE to 64K db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP INCREASESIZE 64 K " 12. To change the INCREASE_SIZE to 5% db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP INCREASESIZE 5 PERCENT " 13. To convert a REGULAR tablespace to LARGE db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP CONVERT TO LARGE" 14. To turn ON filesystem caching, db2 "ALTER TABLESPACE MY_AUTOSTOR_TBSP FILE SYSTEM CACHING " 15. To add a new container to the tablespace db2 "ALTER TABLESPACE MY_DMS_TABLESPACE ADD (FILE 'C:db2sampleMY_DMS_TABLESPACEC002' 2000)" db2 "ALTER TABLESPACE MY_DMS_TABLESPACE ADD (FILE 'C:db2sampleMY_DMS_TABLESPACEC003' 2M) " (notice that 2M signifies 2 MB) 16. To drop a tablespace db2 "DROP TABLESPACE MY_TBSP” 17. To bakup a tablespace db2 "BACKUP DATABASE SAMPLE TABLESPACE MY_DMS_TABLESPACE ONLINE " 18. To bring a tablespace online db2 "ALTER TABLESPACE MY_DMS_TABLESPACE SWITCH ONLINE"
  • 14. About Me I have been working as a DBA for last 10 years, currently with Financial Sector Company. There has been a shortage of documentation on DB2 topics (mostly coming from IBM Infocenter) when compared to MSSQL or Oracle so I wish to help the DBA community, especially the beginners who face lots of challenges in their initial days. I have been trying to increase the volume of notes on specific topics which are of day to day use. I hope my notes will be helpful to the DBA community. I can be contacted via email at rahulanand_db2@yahoo.com . Rahul Anand