Download DB2 LUW Automatic Memory Management Configuration

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database model wikipedia , lookup

Clusterpoint wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Transcript
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
Would you like to set a minimum or maximum limit for an instance or database configuration value and still be able
to use the automatic memory manager feature of DB2 LUW? If you would then you can use the script below to
accomplish this.
This parameter driven script will echo display the parameters it needs to operate. You can test it manually and then
when you have identified the configuration parameter you want to maintain, the minimum value you would like to
maintain, the frequency and duration you'd like the script to run, you can then schedule it to run in cron or some
other scheduling software and this script will monitor the current value the automatic memory manager has
established and change it setting it to a minimum value if the current value falls below the minimum.
Likewise, this script will reduce the value to the maximum parameter value if the automatic memory manager has
taken the configuration above your maximum. You may need the frequency of this script to be quite short to keep
up with what the memory manager programs are doing but at least this script gives you the option to use a hybrid
approach if you wish to do so.
Some people like the automatic memory manager features and say they work well in some database environments
and others do not like them because they cause performance and other types of problems. Using fixed configuration
values can help improve performance but when these limits are hit by some application SQL, errors can happen
which can be avoided if the automatic memory manager is used. But for those of you who have used the automatic
memory manager, you know that there can be quiet times when this can lower configuration limits too low and this
can be problematic for dynamic SQL. Likewise, during busy times the automatic memory manager can take things
too high and cause other types of imbalances and problems in the database environment.
Having the ability to establish and maintain a minimum and maximum configuration range that the automatic
memory manager can operate in may help you get the best of both worlds and avoid some problems that can happen
if you choose to have the automatic memory manager turned on.
This script does not have edits to prevent you from using invalid configuration values. These could change with
new releases of DB2 LUW so I did not bother to add this type of logic. I did not add edits to ensure the minimum
and maximum values are in fact lower and higher than one another but that edit could be added easily enough or if
you know what you want to do, it is not even required. Use this script at your own risk and set the frequency and
duration to meet the needs of your operating environment.
If IBM enhances DB2 LUW in the future to support automatic memory management configuration values with a
low and/or high range then the need for a script like this will be obsolete. Until that time, feel free to test this and
use it if you get good results. If you do not get good results then please do not use this script.
This is a KORN shell script. This could just as easily be a BORN shell or Perl script or converted into some other
type of script that will run against a DB2 LUW database. The concept and design are the same, basically, monitor a
configuration value that is set to AUTOMATIC and then update it to a minimum or maximum value if the automatic
memory manager takes the configuration below the minimum or above the maximum.
db2update_cfg_automatic_min_max_limits.ksh
#!/bin/ksh
#----------------------------------------------------------------------# Program
: db2update_cfg_automatic_min_max_limits.ksh
# Description
: This script runs.
# Author
# Date
: Mark Mulligan
: 12/03/2012
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
#----------------------------------------------------------------------ScriptVer='12/03/2012'
ScriptName='db2update_cfg_automatic_min_max_limits'
Server=$(hostname)
if [ "$1" = "" ]
then
echo ""
echo "Parm 1 Instance (required)."
echo "Parm 2 Database (required)."
echo "Parm 3 ConfigName (required). Must be one of the configuration parameter names listed below like
MON_HEAP_SZ"
echo ""
echo "
Database monitor heap size (4KB)
(MON_HEAP_SZ) = AUTOMATIC(90)"
echo "
Size of instance shared memory (4KB) (INSTANCE_MEMORY) = AUTOMATIC(1948077)"
echo "
Agent pool size
echo "
Max number of coordinating agents
(NUM_POOLAGENTS) = AUTOMATIC(100)"
echo "
Max number of client connections
AUTOMATIC(MAX_COORDAGENTS)"
(MAX_COORDAGENTS) = AUTOMATIC(200)"
(MAX_CONNECTIONS) =
echo "
Number of pooled fenced processes
AUTOMATIC(MAX_COORDAGENTS)"
(FENCED_POOL) =
echo "
No. of int. communication buffers(4KB)(FCM_NUM_BUFFERS) = AUTOMATIC(16384)"
echo "
No. of int. communication channels (FCM_NUM_CHANNELS) = AUTOMATIC(2048)"
echo "
Size of database shared memory (4KB) (DATABASE_MEMORY) = AUTOMATIC(1737423)"
echo "
Package cache size (4KB)
echo "
Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(61070)"
echo "
Sort list heap (4KB)
echo "
Database heap (4KB)
echo "
SQL statement heap (4KB)
(STMTHEAP) = AUTOMATIC(16384)"
echo "
Default application heap (4KB)
(APPLHEAPSZ) = AUTOMATIC(2000)"
echo "
Application Memory Size (4KB)
echo "
Statistics heap size (4KB)
(PCKCACHESZ) = AUTOMATIC(8193)"
(SORTHEAP) = AUTOMATIC(1390)"
(DBHEAP) = AUTOMATIC(32768)"
(APPL_MEMORY) = AUTOMATIC(40000)"
(STAT_HEAP_SZ) = AUTOMATIC(8500)"
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
echo "
Number of asynchronous page cleaners (NUM_IOCLEANERS) = AUTOMATIC(2)"
echo "
Number of I/O servers
echo "
Max number of active applications
echo "
Average number of active applications
(NUM_IOSERVERS) = AUTOMATIC(18)"
(MAXAPPLS) = AUTOMATIC(1435)"
(AVG_APPLS) = AUTOMATIC(1)"
echo ""
echo "Parm 4 Frequency (optional). Defaults to 300 seconds (i.e. 5 minutes)"
echo "Parm 5 Duration (optional). Defaults to 86400 seconds (i.e. 24 hours)"
echo "Parm 6 Minimum
echo "Parm 7 Maximum
range."
(optional). Minimum or Maximum is required."
(optional). Minimum and Maximum values allowed to maintain an operating
echo ""
return 8
else
Instance=`echo $1 | tr '[A-Z]' '[a-z]'`
fi
if [ "$2" = "" ]
then
echo ""
echo "Parm 2 Database (required)."
echo "Parm 3 ConfigName (required). Must be one of the configuration parameter names listed below like
MON_HEAP_SZ"
echo ""
echo "
Database monitor heap size (4KB)
(MON_HEAP_SZ) = AUTOMATIC(90)"
echo "
Size of instance shared memory (4KB) (INSTANCE_MEMORY) = AUTOMATIC(1948077)"
echo "
Agent pool size
echo "
Max number of coordinating agents
(NUM_POOLAGENTS) = AUTOMATIC(100)"
echo "
Max number of client connections
AUTOMATIC(MAX_COORDAGENTS)"
echo "
Number of pooled fenced processes
AUTOMATIC(MAX_COORDAGENTS)"
(MAX_COORDAGENTS) = AUTOMATIC(200)"
(MAX_CONNECTIONS) =
(FENCED_POOL) =
echo "
No. of int. communication buffers(4KB)(FCM_NUM_BUFFERS) = AUTOMATIC(16384)"
echo "
No. of int. communication channels (FCM_NUM_CHANNELS) = AUTOMATIC(2048)"
echo "
Size of database shared memory (4KB) (DATABASE_MEMORY) = AUTOMATIC(1737423)"
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
echo "
Package cache size (4KB)
(PCKCACHESZ) = AUTOMATIC(8193)"
echo "
Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(61070)"
echo "
Sort list heap (4KB)
echo "
Database heap (4KB)
echo "
SQL statement heap (4KB)
(STMTHEAP) = AUTOMATIC(16384)"
echo "
Default application heap (4KB)
(APPLHEAPSZ) = AUTOMATIC(2000)"
echo "
Application Memory Size (4KB)
echo "
Statistics heap size (4KB)
echo "
Number of asynchronous page cleaners (NUM_IOCLEANERS) = AUTOMATIC(2)"
echo "
Number of I/O servers
echo "
Max number of active applications
echo "
Average number of active applications
(SORTHEAP) = AUTOMATIC(1390)"
(DBHEAP) = AUTOMATIC(32768)"
(APPL_MEMORY) = AUTOMATIC(40000)"
(STAT_HEAP_SZ) = AUTOMATIC(8500)"
(NUM_IOSERVERS) = AUTOMATIC(18)"
(MAXAPPLS) = AUTOMATIC(1435)"
(AVG_APPLS) = AUTOMATIC(1)"
echo ""
echo "Parm 4 Frequency (optional). Defaults to 300 seconds (i.e. 5 minutes)"
echo "Parm 5 Duration (optional). Defaults to 86400 seconds (i.e. 24 hours)"
echo "Parm 6 Minimum
echo "Parm 7 Maximum
range."
(optional). Minimum or Maximum is required."
(optional). Minimum and Maximum values allowed to maintain an operating
echo ""
return 8
else
Database=`echo $2 | tr '[a-z]' '[A-Z]'`
fi
if [[ "$3" != "MON_HEAP_SZ" && "$3" != "INSTANCE_MEMORY" && "$3" != "NUM_POOLAGENTS" &&
"$3" != "MAX_COORDAGENTS" && "$3" != "MAX_CONNECTIONS" && "$3" != "FENCED_POOL" &&
"$3" != "FCM_NUM_BUFFERS" && "$3" != "FCM_NUM_CHANNELS" && "$3" !=
"DATABASE_MEMORY" && "$3" != "PCKCACHESZ" && "$3" != "SHEAPTHRES_SHR" && "$3" !=
"SORTHEAP" && "$3" != "DBHEAP" && "$3" != "STMTHEAP" && "$3" != "APPLHEAPSZ" && "$3" !=
"APPL_MEMORY" && "$3" != "STAT_HEAP_SZ" && "$3" != "NUM_IOCLEANERS" && "$3" !=
"NUM_IOSERVERS" && "$3" != "MAXAPPLS" && "$3" != "AVG_APPLS" ]]
then
echo ""
echo "Parm 3 ConfigName (required). Must be one of the configuration parameter names listed below like
MON_HEAP_SZ"
echo ""
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
echo "
Database monitor heap size (4KB)
(MON_HEAP_SZ) = AUTOMATIC(90)"
echo "
Size of instance shared memory (4KB) (INSTANCE_MEMORY) = AUTOMATIC(1948077)"
echo "
Agent pool size
echo "
Max number of coordinating agents
(NUM_POOLAGENTS) = AUTOMATIC(100)"
echo "
Max number of client connections
AUTOMATIC(MAX_COORDAGENTS)"
(MAX_COORDAGENTS) = AUTOMATIC(200)"
(MAX_CONNECTIONS) =
echo "
Number of pooled fenced processes
AUTOMATIC(MAX_COORDAGENTS)"
(FENCED_POOL) =
echo "
No. of int. communication buffers(4KB)(FCM_NUM_BUFFERS) = AUTOMATIC(16384)"
echo "
No. of int. communication channels (FCM_NUM_CHANNELS) = AUTOMATIC(2048)"
echo "
Size of database shared memory (4KB) (DATABASE_MEMORY) = AUTOMATIC(1737423)"
echo "
Package cache size (4KB)
echo "
Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(61070)"
echo "
Sort list heap (4KB)
echo "
Database heap (4KB)
echo "
SQL statement heap (4KB)
(STMTHEAP) = AUTOMATIC(16384)"
echo "
Default application heap (4KB)
(APPLHEAPSZ) = AUTOMATIC(2000)"
echo "
Application Memory Size (4KB)
echo "
Statistics heap size (4KB)
echo "
Number of asynchronous page cleaners (NUM_IOCLEANERS) = AUTOMATIC(2)"
echo "
Number of I/O servers
echo "
Max number of active applications
echo "
Average number of active applications
(PCKCACHESZ) = AUTOMATIC(8193)"
(SORTHEAP) = AUTOMATIC(1390)"
(DBHEAP) = AUTOMATIC(32768)"
(APPL_MEMORY) = AUTOMATIC(40000)"
(STAT_HEAP_SZ) = AUTOMATIC(8500)"
(NUM_IOSERVERS) = AUTOMATIC(18)"
(MAXAPPLS) = AUTOMATIC(1435)"
(AVG_APPLS) = AUTOMATIC(1)"
echo ""
echo "Parm 4 Frequency (optional). Defaults to 300 seconds (i.e. 5 minutes)"
echo "Parm 5 Duration (optional). Defaults to 86400 seconds (i.e. 24 hours)"
echo "Parm 6 Minimum
echo "Parm 7 Maximum
range."
(optional). Minimum or Maximum is required."
(optional). Minimum and Maximum values allowed to maintain an operating
echo ""
return 8
else
ConfigName=`echo $3 | tr '[a-z]' '[A-Z]'`
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
fi
if [ "$4" = "" ]
then
Frequency=300
else
Frequency=$4
fi
if [ "$5" = "" ]
then
Duration=86400
else
Duration=$5
fi
if [[ "$6" = "" && "$7" = "" ]]
then
echo ""
echo "Parm 6 Minimum
echo "Parm 7 Maximum
range."
(optional). Minimum or Maximum is required."
(optional). Minimum and Maximum values allowed to maintain an operating
echo ""
return 8
else
Minimum=$6
Maximum=$7
fi
. /db2home/${Instance}/sqllib/db2profile
if [ -d ${HOME}/reports ]
then
:
else
mkdir ${HOME}/reports
fi
export OutputDir="${HOME}/reports"
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
export Datetime="`date +%Y%m%d%H%M%S`"
FileName=${OutputDir}/${ScriptName}_${Server}_${Instance}_${Database}_${ConfigName}_${Datetime}
OutputFile=${FileName}.txt
echo "$ScriptName Vers: $ScriptVer started on " `uname -n` on `date` | tee $OutputFile
echo "" | tee -a $OutputFile
ElapsedSeconds=0
until [[ $ElapsedSeconds -ge $Duration ]]
do
#
echo "ElapsedSeconds=$ElapsedSeconds -ge Duration=$Duration"
if [[ "$3" = "MON_HEAP_SZ" || "$3" = "INSTANCE_MEMORY" || "$3" = "NUM_POOLAGENTS" || "$3" =
"MAX_COORDAGENTS" || "$3" = "MAX_CONNECTIONS" || "$3" = "FENCED_POOL" || "$3" =
"FCM_NUM_BUFFERS" || "$3" = "FCM_NUM_CHANNELS" ]]
then db2 -x get dbm cfg | grep AUTOMATIC | grep $ConfigName | sed 's/(/ /g' | sed 's/)/ /g' | sed 's/Database
monitor heap size 4KB
//g' | sed 's/Size of instance shared memory 4KB //g' | sed 's/Agent pool
size
//g' | sed 's/Max number of coordinating agents
//g' | sed 's/Max number of client
connections
//g' | sed 's/Number of pooled fenced processes
//g' | sed 's/No\. of int\. communication buffers
4KB //g' | sed 's/No\. of int\. communication channels //g' | sed 's/ = AUTOMATIC//g' | read aa bb cc dd ee ff gg
hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz
#
echo "Database Manager Configuration" | tee -a $OutputFile
#
db2 -x get dbm cfg | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
#
echo "$aa $bb" | tee -a $OutputFile
if [ "$Minimum" != "" ]
then
if [ $bb -lt $Minimum ]
then
#
date | tee -a $OutputFile
echo "$aa size $bb is less than $Minimum" | tee -a $OutputFile
db2 -x attach to $Instance >/dev/null 2>&1
db2 -x get dbm cfg | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
db2 -x "update dbm cfg using $aa $Minimum AUTOMATIC IMMEDIATE" >/dev/null 2>&1
db2 -x get dbm cfg | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
db2 -x detach >/dev/null 2>&1
fi
fi
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
if [ "$Maximum" != "" ]
then
if [ $bb -gt $Maximum ]
then
#
date | tee -a $OutputFile
echo "$aa size $bb is greater than $Maximum" | tee -a $OutputFile
db2 -v attach to $Instance >/dev/null 2>&1
db2 -x get dbm cfg | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
db2 -x "update dbm cfg using $aa $Maximum AUTOMATIC IMMEDIATE" >/dev/null 2>&1
db2 -x get dbm cfg | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
db2 -v detach >/dev/null 2>&1
fi
fi
fi
if [[ "$3" = "DATABASE_MEMORY" || "$3" = "PCKCACHESZ" || "$3" = "SHEAPTHRES_SHR" || "$3" =
"SORTHEAP" || "$3" = "DBHEAP" || "$3" = "STMTHEAP" || "$3" = "APPLHEAPSZ" || "$3" =
"APPL_MEMORY" || "$3" = "STAT_HEAP_SZ" || "$3" = "NUM_IOCLEANERS" || "$3" = "NUM_IOSERVERS"
|| "$3" = "MAXAPPLS" || "$3" = "AVG_APPLS" ]]
then db2 -x get db cfg for $Database | grep AUTOMATIC | grep $ConfigName | sed 's/(/ /g' | sed 's/)/ /g' | sed
's/Size of database shared memory 4KB //g' | sed 's/Package cache size 4KB
//g' | sed 's/Sort heap
thres for shared sorts 4KB //g' | sed 's/Sort list heap 4KB
//g' | sed 's/Database heap
4KB
//g' | sed 's/SQL statement heap 4KB
//g' | sed 's/Default application heap
4KB
//g' | sed 's/Application Memory Size 4KB
//g' | sed 's/Statistics heap size 4KB
//g'
| sed 's/Number of asynchronous page cleaners //g' | sed 's/Number of I\/O servers
//g' | sed 's/Max
number of active applications
//g' | sed 's/Average number of active applications
//g' | sed 's/ =
AUTOMATIC//g' | read aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz
#
echo "Database Configuration" | tee -a $OutputFile
#
db2 -x get db cfg for $Database | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a $OutputFile
#
echo "$aa $bb" | tee -a $OutputFile
if [ "$Minimum" != "" ]
then
if [ $bb -lt $Minimum ]
then
#
date | tee -a $OutputFile
echo "$aa size $bb is less than $Minimum" | tee -a $OutputFile
db2 -x connect to $Database >/dev/null 2>&1
db2 -x get db cfg for $Database | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a
$OutputFile
DB2 LUW Automatic Memory Management Configuration Minimum Maximum Limits script
db2 -x "update db cfg for $Database using $aa $Minimum AUTOMATIC IMMEDIATE"
>/dev/null 2>&1
db2 -x get db cfg for $Database | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a
$OutputFile
db2 -v connect reset >/dev/null 2>&1
fi
fi
if [ "$Maximum" != "" ]
then
if [ $bb -gt $Maximum ]
then
#
date | tee -a $OutputFile
echo "$aa size $bb is greater than $Maximum" | tee -a $OutputFile
db2 -v connect to $Database >/dev/null 2>&1
db2 -x get db cfg for $Database | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a
$OutputFile
db2 -x "update db cfg for $Database using $aa $Maximum AUTOMATIC IMMEDIATE"
>/dev/null 2>&1
db2 -x get db cfg for $Database | grep AUTOMATIC | grep "${ConfigName}) =" | tee -a
$OutputFile
db2 -v connect reset >/dev/null 2>&1
fi
fi
fi
sleep $Frequency
((ElapsedSeconds=ElapsedSeconds+Frequency))
done
echo "" | tee -a $OutputFile
echo "$ScriptName Vers: $ScriptVer ended on " `uname -n` on `date` | tee -a $OutputFile
echo "Output located in $OutputFile" | tee -a $OutputFile