tiancheng_2011
作者tiancheng_2011·2012-03-16 11:35
数据库管理员·北京华胜天成

操作系统内存和数据库内存

字数 6274阅读 1104评论 0赞 0
以前给Oracle杂志写过一篇关于Oracle memory and OS memory。
Oracle 那部分在此省略了, 只把OS related 的部分贴一下:
【很多忘了,不好意思
For AIX:
ps vgw
or svmon <pid>
For example:
ps vgw | grep $ORACLE_SID | grep –v grep | awk ‘{print $7-$10, $1, $6}’

For Solaris:
pmap <pid>
A sample template script:
ps –ef | grep $ORACLE_SID|grep –v grep | awk ‘{print $2}’|while read pid
do     pmap $pid > $pmap_$pid.out
done
grep ‘read/write’ *.out |grep –v shared

For HP-UX:
glance  or q4
   See Note:66637.1

For LINUX:
cat /proc/<sid>/status

$ ps aux
USER        PID %CPU %MEM   SZ  RSS    TTY STAT    STIME  TIME COMMAND
b2cdbins 466980  0.4  4.0 108792 108752      - A      Mar 13 24:21 db2sysc 0

总共内存4096M

请注意MEM%=RES/physical memory . RES是指进程实际使用的物理内存,又叫已经提交的内存, 你这里934/0.12差不多是8G。另外一个基本概念是Used=Application Used+buffer+cache,其中buffer跟cache是内核管理的,在Application需要时可以提供给App使用,所以这里 Application实际使用的=Used-Buffers

db2mtrk 是当前实际使用的内存,V9.5以后 instance_memory是上限。
linux内存使用机制就是把DISK操作cache到内存,只会增加不会主动释放。
当需要使用内存时可以把CACHE FLUSH到DISK,分配给DB2内存...

DB2引擎(db2sysc)使用内存通过:

db2mtrk -i -d -p -v (在DB2V9.5以后是没有db2agent,父进程都是db2sysc, agent使用内存也算在db2sysc内
   3.DB2内存分共享内存和私有内存,db2mtrk 应该是只能看到共享内存

AIX下一定要用svmon来看,linux下没有对应的命令,只能用cat /proc/进程号/statm来看。ps命令里的内存输出应该内存使用的平均值。

linux下用free命令看总体内存使用,+/-buffer和cache后才是真正计算内存的占用量。


数据库实际使用的内存应该是: db2mrtk -i -d -v 来看
在节点1上
db2inpe@dmsrvr:~> db2mtrk -i -d -v
Tracking Memory on: 2012/03/15 at 04:29:44

Memory for instance

   Other Memory is of size 34799616 bytes
   Database Monitor Heap is of size 327680 bytes
   FCMBP Heap is of size 22413312 bytes
   Total: 57540608 bytes

Memory for database: TEST

   Backup/Restore/Util Heap is of size 65536 bytes
   Package Cache is of size 524288 bytes
   Other Memory is of size 131072 bytes
   Catalog Cache Heap is of size 262144 bytes
   Buffer Pool Heap (2) is of size 33226752 bytes
   Buffer Pool Heap (1) is of size 4521984 bytes
   Buffer Pool Heap (System 32k buffer pool) is of size 851968 bytes
   Buffer Pool Heap (System 16k buffer pool) is of size 589824 bytes
   Buffer Pool Heap (System 8k buffer pool) is of size 458752 bytes
   Buffer Pool Heap (System 4k buffer pool) is of size 393216 bytes
   Shared Sort Heap is of size 0 bytes
   Lock Manager Heap is of size 26476544 bytes
   Database Heap is of size 14876672 bytes
   Application Heap (3744) is of size 196608 bytes
   Application Heap (68077) is of size 65536 bytes
   Application Heap (3749) is of size 65536 bytes
   Application Heap (3746) is of size 65536 bytes
   Application Heap (68068) is of size 65536 bytes
   Application Heap (68067) is of size 65536 bytes
   Applications Shared Heap is of size 327680 bytes
   Total: 83230720 bytes


在节点0上

db2inpe@dmsrvr:~/sqllib/db2dump> db2mtrk -i -d -v
Tracking Memory on: 2012/03/15 at 04:41:17

Memory for instance

   Other Memory is of size 35258368 bytes
   Database Monitor Heap is of size 327680 bytes
   FCMBP Heap is of size 22413312 bytes
   Total: 57999360 bytes

Memory for database: TEST

   Backup/Restore/Util Heap is of size 65536 bytes
   Package Cache is of size 2162688 bytes
   Other Memory is of size 131072 bytes
   Catalog Cache Heap is of size 524288 bytes
   Buffer Pool Heap (2) is of size 33226752 bytes
   Buffer Pool Heap (1) is of size 4521984 bytes
   Buffer Pool Heap (System 32k buffer pool) is of size 851968 bytes
   Buffer Pool Heap (System 16k buffer pool) is of size 589824 bytes
   Buffer Pool Heap (System 8k buffer pool) is of size 458752 bytes
   Buffer Pool Heap (System 4k buffer pool) is of size 393216 bytes
   Shared Sort Heap is of size 131072 bytes
   Lock Manager Heap is of size 26476544 bytes
   Database Heap is of size 14876672 bytes
   Application Heap (68077) is of size 65536 bytes
   Application Heap (3749) is of size 65536 bytes
   Application Heap (3747) is of size 65536 bytes
   Application Heap (68067) is of size 65536 bytes
   Application Heap (3746) is of size 65536 bytes
   Application Heap (3745) is of size 65536 bytes
   Application Heap (3744) is of size 131072 bytes
   Application Heap (3743) is of size 65536 bytes
   Application Heap (3742) is of size 65536 bytes
   Applications Shared Heap is of size 720896 bytes
   Total: 85786624 bytes



57999360+85786624 =143785984


关于ps aux 应该跟dbpmem对应着看。
db2inpe@dmsrvr:~/sqllib/db2dump> ps aux|head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
db2inpe@dmsrvr:~/sqllib/db2dump> ps aux |grep db2sysc
db2inpe  23934  0.0 22.4 667520 227900 ?       Sl   Mar12   3:53 db2sysc 0
db2inpe  23937  0.0 21.6 605008 219492 ?       Sl   Mar12   3:36 db2sysc 1

db2pd -d test   -dbptnmem
Database Partition Memory Controller Statistics

Controller Automatic: Y
Memory Limit:         380564 KB
Current usage:        309792 KB
HWM usage:            313824 KB
Cached memory:        69760 KB

309792 - 69760 = 240032 相减才是已经分配的的实际内存,应该不是使用到的内存

而top  里边看到的内存跟实际的不符是因为有cache 和buffer ,free -m 看一下就知道了


linux程序结束后,内存不会被正常释放,而是一直作为caching。
db2 get db cfg|grep -i instance_memory:
假定你用的是V9.5, 对于V9.5来说,Instance_Memory的语义是当前Instance及其下所有数据库能使用的内存总量的上限。你当前使用量一般情况下会小于这个上限的。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

X社区推广