Escolar Documentos
Profissional Documentos
Cultura Documentos
29 November 2008
Download Scripts
Introduction
Have you ever run the db2 "call get_dbsize_info(?,?,?,0)" command to get the size of your
DB2 LUW database and noticed that the size is much smaller than the space used on your
UNIX file systems? Do you need to monitor database growth over time to help plan for future
storage requirements?
This article describes a script that will calculate the size of a DB2 LUW database on a UNIX
server using UNIX commands that will give you a more accurate measure of the space used
by the database. This script also stores this information in an operational table that you may
use as part of your DBA Monitoring Dash Board to help you monitor and manage space in
relation to growth trends.
A disadvantage to this approach is that it does not include the size of transaction log files on
disk, archive log files if you keep them on disk or temporary tablespaces. If you wish to
include that information in the database size you will have to enhance the script to do this.
Description
The DB2 list tablespace command and list tablespace container command can be used to
obtain the path or file for tablespace containers in a database. The UNIX list command (ls)
can be used to obtain the size of the tablespace container paths and files and accumulated
by partition and summarized by database. This script captures partition and database size
information and stores it in a table. If the script is run daily then the size information can be
seen over time.
Having this partition and database size information available in a table named
OPERATIONS.DATABASE_INFORMATION can show database size information for one day or
over time.
In the two examples shown below, the call to the get_dbsize_info stored procedure returns a
database size of roughly 1.36 terabytes and the db2extract_database_size.ksh script returns
a database size of roughly 3.09 terabytes. The difference between these two approaches is
significant and when it comes to terabytes of storage it is important to be accurate in your
measurements for storage planning purposes. Also, if you notice significant size differences
in the database partition sizes then this could indicate an out of balance condition that you
may need to correct at the tablespace or table level in the database.
Return Status = 0
Environment
The script in this article was tested on a server running the AIX operating system and DB2
versions 9.1 and 9.5. The KORN shell script should work on any server that has a UNIX-like
operating system that supports these types of scripts. (Linux and Linux/390 come to mind.)
This script is designed to run in a native UNIX environment and is not intended to run under
the DB2 Script Center Client Window. The extract script must be run under the DB2 instance
id or an id that has the correct UNIX permissions to be able to run the UNIX list command
(ls) against the database tablespace container paths and files.
The script
#!/bin/ksh
#----------------------------------------------------------------------t
# Program : db2extract_database_size_information.ksh
# Description : This script runs the DB2 list tablespace command
# : to identify the tablespace id's in a partition
# : and then runs the db2 list tablespace containers
# : for each id that is not a temporary tablespace
# : and extracts the name for each container path
# : or file and then runs a UNIX list (ls) command
# : and accumulates the size of the files to
# : calculate the size of the partition and
# : ultimately the size of the database.
# Author : Mark Mulligan
# Date : 04/07/2005
# Input Arguments : 1st Parameter = (Required) Instance.
# : 2nd Parameter = (Required) Database.
# Output : None.
# Required Files : None.
# Maintenance :
#-----------------------------------------------------------------------
ScriptVer='04/07/2005'
ScriptName='db2extract_database_size_information'
Server=$(hostname)
if [ "$1" = "" ]
then echo ""
echo "Parm 1 Instance (required)"
echo "Parm 2 Database (required)"
echo 'Parm 3 Script Output Directory Path (optional) Defaults to
/dbawork/reports'
echo ""
return
else Instance=`echo $1 | tr '[A-Z]' '[a-z]'`
fi
if [ "$2" = "" ]
then echo ""
echo "Parm 2 Database (required)"
echo 'Parm 3 Script Output Directory Path (optional) Defaults to
/dbawork/reports'
echo ""
return
else Database=`echo $2 | tr '[a-z]' '[A-Z]'`
fi
if [ "$3" = "" ]
then OutputDir='/dbawork/reports'
else OutputDir=$3
fi
#.${HOME)/sqllib/db2profile
. ${HOME}/.${Server}_${Instance}
Datetime="`date +%Y%m%d%H%M%S`"
FileName=${OutputDir}/${ScriptName}_${Server}_${Instance}_${Database}_${Datetime}
OutputFile=${FileName}.txt
The Table
------------------------------------------------
-- DDL Statements for table "OPERATIONS"."DATABASE_INFORMATION"
------------------------------------------------
Example
If you run the script in foreground without passing it any parameters, it will echo display the
parameters that the script uses. The first two parameters for the script are required so that
the common reusable DBA script will know what DB2 instance and database to use. The third
parameter is optional.
db2extract_database_size_information.ksh
When you run the script in foreground and pass it a DB2 instance id and database, you
should see output displayed that is similar to the example shown below.
Select Examples
The output created by this script is stored in a DB2 table. You may develop SQL or a script
that runs different types of select SQL statements that will help you use this information to
help you monitor database size changes over time. The first select statement shows you the
size of all partitions in the database and the total database size yesterday. The second select
statement shows you the database sizes only over time. This information could be presented
in a graph to show the database size growth over time.
If you have any questions related to this article, feel free to contact me, Mark Mulligan, at
mark.mulligan.sr@sbcglobal.net and I will be glad to try to answer your questions.