原文链接:DB2内存使用过高优化
最近在在做DB2的benchmark,发现数据库的内存占用特别高,因为是做benchmark测试,所以表并不多,并且主要是针对其中的一张表做测试,当这张表的数据快到1亿的时候,用top查询系统状态如下
# top
top - 20:06:34 up 5 days, 22:20, 12 users, load average: 18.53, 6.57, 3.19
...
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
32458 db2inst 20 0 42.3g 27g 27g S 63.7 44.3 0:27.13 db2sysc 0
...
使用db2mtrk命令来查看db2的内存使用情况,如下:
# db2mtrk -i -d -v
Tracking Memory on: 2014/06/22 at 21:50:19
Memory for instance
Other Memory is of size 63111168 bytes
FCMBP Heap is of size 851968 bytes
Database Monitor Heap is of size 983040 bytes
Total: 64946176 bytes
Memory for database: PA913
Backup/Restore/Util Heap is of size 65536 bytes
Package Cache is of size 262144 bytes
Other Memory is of size 196608 bytes
Catalog Cache Heap is of size 262144 bytes
Buffer Pool Heap (1) is of size 24465047552 bytes
Buffer Pool Heap (System 32k buffer pool) is of size 1835008 bytes
Buffer Pool Heap (System 16k buffer pool) is of size 1572864 bytes
Buffer Pool Heap (System 8k buffer pool) is of size 1441792 bytes
Buffer Pool Heap (System 4k buffer pool) is of size 1376256 bytes
Shared Sort Heap is of size 0 bytes
Lock Manager Heap is of size 3881172992 bytes
Database Heap is of size 94830592 bytes
Application Heap (47) is of size 131072 bytes
Application Heap (45) is of size 65536 bytes
Application Heap (44) is of size 65536 bytes
Application Heap (43) is of size 65536 bytes
Application Heap (42) is of size 65536 bytes
Application Heap (41) is of size 65536 bytes
Application Heap (40) is of size 65536 bytes
Application Heap (39) is of size 65536 bytes
Application Heap (38) is of size 65536 bytes
Application Heap (37) is of size 65536 bytes
Application Heap (36) is of size 65536 bytes
Application Heap (35) is of size 65536 bytes
Application Heap (34) is of size 65536 bytes
Application Heap (33) is of size 65536 bytes
Application Heap (32) is of size 65536 bytes
Application Heap (31) is of size 65536 bytes
Application Heap (30) is of size 65536 bytes
Application Heap (29) is of size 65536 bytes
Application Heap (28) is of size 65536 bytes
Application Heap (27) is of size 65536 bytes
Application Heap (26) is of size 65536 bytes
Application Heap (25) is of size 65536 bytes
Application Heap (24) is of size 65536 bytes
Application Heap (23) is of size 65536 bytes
Application Heap (22) is of size 65536 bytes
Application Heap (21) is of size 65536 bytes
Application Heap (20) is of size 65536 bytes
Application Heap (19) is of size 65536 bytes
Application Heap (18) is of size 65536 bytes
Application Heap (17) is of size 65536 bytes
Application Heap (16) is of size 65536 bytes
Application Heap (15) is of size 65536 bytes
Application Heap (14) is of size 65536 bytes
Application Heap (13) is of size 65536 bytes
Application Heap (12) is of size 65536 bytes
Application Heap (11) is of size 196608 bytes
Application Heap (10) is of size 65536 bytes
Application Heap (9) is of size 65536 bytes
Application Heap (8) is of size 65536 bytes
Application Heap (7) is of size 131072 bytes
Applications Shared Heap is of size 393216 bytes
Total: 28451340288 bytes
查了一下资料,可以通过修改database_memory系统参数来设置数据库内存的使用。默认情况下database_memory的设置是AUTOMATIC,这里可以通过下面的命令来修改参数,修改完后要重新启动db2
$ db2 update db cfg for using database_memory 8000000
$ db2stop force
$ db2start
在真实的DB2使用情况下,修改这个值是需要慎重的,可以参考下面列出的参考资料。
参考
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.5.0/com.ibm.db2.luw.admin.config.doc/doc/r0006017.html?lang=en
http://www-01.ibm.com/support/knowledgecenter/api/content/SSEPGG_9.5.0/com.ibm.db2.luw.admin.config.doc/doc/r0005181.html
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0008712.html?lang=en
http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0406qi/
http://www.db2china.net/home/space.php?uid=3821&do=blog&id=8829
http://www.db2china.net/home/space.php?uid=3821&do=blog&id=8830
http://www.db2china.net/home/space.php?uid=3821&do=blog&id=8831