<DB2> "Detailed Introduction to DB2 Memory"

1 Architecture Diagram

insert image description here

2 main concepts

2.1 Memory Set (Memory Set)

DB2's memory sets include instance memory sets, database shared memory sets, application memory sets, and agent private memory sets

2.2 Memory Pool (Memory Pool)

The memory pool is composed of several memory blocks, and its address space is not continuous.
①The memory pool tracks the sum of its related memory blocks, and controls its sum value to not exceed the specified size when the pool is created.
②Each memory pool belongs to a memory set; the memory blocks of the same memory pool are allocated from this memory set.
③MemoryPool is a group of memory allocated by DB2 Memory Manager to different components. DB2 organizes the allocation according to the scope, purpose, and behavior of the memory.

2.3 Memory Block (Memory Block)

A continuous memory space is the basic unit of DB2 internal memory allocation.
①A memory block is a continuous memory address range, which is mainly used to be applied by other components.
②DB2 tracks the allocation of memory blocks by the internal structure.
③A memory block can only belong to one memory pool.

3 memory scheme

3.1 Level 1 server memory

Allocatable part:
The total server allocatable memory
will be allocated to the next level:
operating system memory, instance shared memory.
Explanation:
① Multiple instances can be created in one database. If there are multiple instances, then multiple instances share memory.

3.2 Second level operating system memory and instance shared memory

1. The memory used by the operating system.
Note: The memory size allocated to the operating system accounts for more than 10%.

2. Instance shared memory
The memory allocated to the database instance;
allocated when the database manager starts (db2start).
Used for instance-level tasks (monitoring, auditing, and inter-node communication, etc.)
① All databases under the instance use a collection of memory. Shared instance memory.
② There are multiple databases under the instance.
③ Contains mon_heap_sz (monitor heap),
audit_buf_sz (audit buffer),
fcm_num_buffers (multi-partition node communication),
④ physical memory RAM percentage 75% to 95%, the larger the system, the higher the percentage.

3.3 Third-level database shared memory

memory allocated to the database

Allocated when the database is activated; released when inactive.

For database-level tasks (backup and recovery, locking and SQL execution, etc.)
①Each database has a database shared memory set.
② Contains database buffer pool, hidden buffer pool (not in syscat.bufferpool, exists in db2 get snapshot) util_heap_sz, pckcachesz, logbufsz, dbheap, locklist, sortheap, sheapthres, sheapthres_shr

3.4 The fourth level application group shared memory

Application Shared Memory (appl_memory)

shared application memory

Application-specific content
Application heap (applheapsz)
Statistics heap (stat_heap_sz)
Statement heap (stmtheap)
①appl_memory
②applheapsz
③stmtheap
④stat_heap_sz

3.5 The fifth-level proxy private memory

Each DB2 agent process requires memory to perform its tasks.
The agent process will use memory on behalf of the application to optimize, build and execute access plans, order execution, record cursor information (such as position and status), collect statistics, etc.
In response to connection requests or new SQL requests in a parallel environment, DB2 agents must allocate agent-private memory.
application heap (applheapsz)
sort heap (sortheap)
statement heap (stmtheap)
statistics heap (stat_heap_sz)
query_heap (query_heap_sz)
java heap size (java_heap_sz)
agent stack size (java_stack_sz)

4 memory view

4.1 Operating system memory

4.1.1

System memory query

命令:prtconf|grep -i "Memory Size"

4.1.2 System Memory Monitoring

命令:svmon -G

insert image description here
virtual > size ==>> The virtual value gives the number of pages required for the system to work. If virtual > size value, it means that the physical memory resources are insufficient, and paging is inevitable. Solution: Upgrade memory or configure user applications on the hardware, or solve this performance bottleneck by reducing the memory requirements of applications.

4.1.3 Collect memory usage data and paging data

命令:vmstat -w 1 6

4.1.4 Check the usage of paging space

命令:lsps -a

insert image description here
A high and continuous increase in paging space usage is a sign of insufficient physical memory resources.
Failure to take steps to improve memory usage in a timely manner may eventually cause the operating system to crash.

4.1.5 Configuration parameters of computing memory and file cache in physical memory

命令:vmstat -v

insert image description here

4.2 Database memory

4.2.1 Memory occupied by the database

	命令:db2mtrk -i -d -v
db2mtrk是用于在DB2数据库中进行内存跟踪的工具,可以用于查看示例、数据库、代理进程当前对内存的使用状态。
  
  db2mtrk -i    显示当前实例的内存使用情况
  db2mtrk -i -v 显示当前实例的内存使用的详细信息
  db2mtrk -d    显示数据库的内存使用情况
  db2mtrk -d -v 显示数据库的内存使用情况的详细信息
  db2mtrk -p    显示代理进程专用内存使用率
  db2mtrk -h    显示帮助信息
  
  -m       参数选项用于显示最大的内存使用上线
  -w       参数选项用于显示使用过程中内存达到的最大值,即watermark
  -r       参数选项用于重复显示,其中interval是重复显示的时间间隔数,count是要重复显示的次数
  interval 指定以秒为单位的重复的间隔
  count    指定间隔的次数
  -v       详细输出
  -h       显示帮助信息

  在db2mtrk工具的输出的信息中有几种类型的信息:
  *当前值得大小
  *最大值的限制(hard limit*最高值(high water mark)
  *类型(用于指定使用了哪种内存)
  *代理进程使用的内容(只针对私有内存池)

4.2.2 Database partition memory

命令:db2pd -dbptnmem

insert image description here

Controller Automatic Memory controller settings. If the instance_memory configuration parameter is set to automatic, the value is displayed as Y. The database determines its own upper memory consumption limit.
Memory Limit Memory Limit: If an instance memory limit is enforced. Then the value of the instance_memory configuration parameter is the upper limit of the DB2 server memory that can be consumed.
Current usage The amount of memory the server is currently consuming
HWM usage High water mark (HWM) or peak memory consumed since the database partition was activated (when the db2start command was run)
Cached memory The amount of memory that is not used in the current usage but is cached to improve the performance of future memory requests
APPL-TYCJDB Application memory consumed for database dbname.
DBMS-db2inst1 DBMS-name: Global database manager memory requirements.
FMP_RESOURCES The memory required to communicate with db2fmps.
PRIVATE Additional dedicated memory requirements.
DB-TYCJDB Database memory consumed for database dbname.
Name The short distinguished name of the memory "consumer", eg APPL-dbname is the application memory consumed by the database dbname.
Mem Used(KB) The amount of memory currently allocated to the consumer
HWM Used(KB) The high water mark (HWM) of the amount of memory consumed by the user, that is, the peak amount of memory.
Cached(KB) In Used Memory, the amount of memory that is not currently in use but is immediately available for future memory allocations.
命令:db2pd -memblock
命令:db2pd -bufferpool

4.2.3 Query the DB2 instance shared memory

命令:db2 get dbm cfg | grep -i mem

4.2.4 View DB2 database shared memory

命令:db2 get db cfg | grep -i mem

4.2.5 Instance-level memory query

命令:db2pd -inst -memsets

insert image description here
Name: the name of the memory set; Id: the identifier of the memory set. Size (Kb): The total size of the memory set, which is the sum of Cmt (Kb) and UnCmt (Kb).
Unrsv (Kb): refers to the size not reserved for a specific memory pool, any memory pool can use this part. Used (Kb): The size currently allocated to the memory pool.
Cmt (Kb): It is the memory that DB2 has submitted to the operating system. This memory can be either physical memory or swap space.
Uncmt (Kb): Memory that is not currently used but is marked as uncommitted by DB2. Depending on the operating system, this memory can be either physical memory or swap space.
In the figure above, there are three db2 instance-level memory sets: instance usage (DBMS), protected stored procedure usage (FMP), and tracking tool usage (Trace).

命令:ipcs -m

insert image description here

4.2.6 View the BUFFERPOOL statement used by the system table space

select A.TBSPACE,A.OWNER,A.OWNERTYPE,A.CREATE_TIME,A.TBSPACEID,A.DBPGNAME,A.BUFFERPOOLID,B.BPNAME from syscat.tablespaces A ,syscat.bufferpools B where A.BUFFERPOOLID=B.BUFFERPOOLID
select TABSCHEMA,TABNAME,OWNER,TYPE,CREATE_TIME,ALTER_TIME,STATS_TIME,TBSPACEID,TBSPACE,INDEX_TBSPACE,CARD,NPAGES from syscat.tables where OWNER !='SYSIBM' and TYPE='T'

4.2.7 View table information

select TABSCHEMA,TABNAME,OWNER,TYPE,CREATE_TIME,ALTER_TIME,STATS_TIME,TBSPACEID,TBSPACE,INDEX_TBSPACE,CARD,NPAGES from syscat.tables where OWNER !='SYSIBM' and TYPE='T'

Guess you like

Origin blog.csdn.net/tangcoolcole/article/details/131057976
db2
db2