Saturday 15 December 2012

DB2 Memory Architecture


DB2 is very interesting database product which can grow in size as much you want, literally from couple MBs to Multi-Terabytes. Capacity totally depends on a) Disk where the real data will be stored, b) Memory allocation which is utilized to process the multi-terabytes of data to end users.

Lets talk how DB2 manages memory : DB2 memory is allocated in terms of shared memory and private memory. Shared memory is the one which is being shared by all of the db2 agents and gets allocated as soon as Instance/database is started. Whereas private memory is the one which is used by db agents individually.

Let's understand first about the shared memory : This is allocated at 3 different levels :
1. Instance
2. Database
3. Application

Instace level shared memory is allocated when its started, and its de-allocated as soon as you stop it. Its been controlled through following Instance configuration parameters :
MON_HEAP_SZ
AUDIT_BUF_SZ
FCM_NUM_BUFFERS

Database level shared memory is allocated when its either activated explicitly or with the first db connection, and de-allocated when its either deactivated explicitly or with the reset of last db connection. Following configuration parameters control the shared memory of database :
BUFFERPOOL
PACKAGE CACHE
CATALOG CACHE
LOCKLIST
DATABASE HEAP
UTILITY HEAP
SHARED SORT HEAP (if INTRA_PARALLEL is enabled)

Application level shared memory is not allocated in every situation. It gets allocated when the database agents (db connections) need to coordinate with each other. This happens in a specific scenario when you have either multi-partitioned database or have enabled the intra_parallel configuration in a single partitioned database. In these specific scenario, a single db agent forks the multiple subagents to serve the request in parallel but still share the same application memory which was allocated to their parent agent. Following configuration parameters control this shared memory :
APP_GROUP_MEM_SZ
GROUPHEAP_RATIO
APP_CTL_HEAP_SZ

Private memory is often referred as agent private memory. Its allocated through a database connection when its assigned to a database agent. Its usage is very dynamic and totally depends on how long that specific agent is busy in processing the request. This memory is utilized to perform sort,to acquire lock,
to build the access plan of SQL etc. Following configuration parameters are responsible for utilizing private memory :
APPLICATION HEAP
SORTHEAP
STATEMENT HEAP
STATISTICS HEAP
QUERY HEAP
JAVA INTERPRETER HEAP

You can monitor the usage of these memory allocation using db2 memory tracker ( db2mtrk) utility and you can keep re-adjusting based on the database size growth and its utilization.

Note:- This information is shared based on my knowledge and the experience.

2 comments:

  1. HI ,i never enabled the autostorage . Can you please tell me in which scenario we will enable the autostorage and from which version of db2 we are using it ? what happens exactly when we enable this parameter ?

    ReplyDelete
    Replies
    1. Autostorage is introduced from DB2 8.2 and from the version 9.1 it has been made by default ON. So, when you create the database from DB2 9.1 onwards, you have to explicitly specify AUTOSTORAGE NO in case you don't want it. By enabling the AUTOSTORAGE YES, you are letting DB2 to manage your tablespaces. But, this is an absolute requirement when you want to configure Purescale, and in other scenario you can live without it.
      Soon, I will blog about it in detail.

      Delete