[20191115]oracle实例占用内存计算.txt
--//以前学习oracle数据库时,总想了解实例占用内存多少,我曾经在一些会议底下问过一位高手,对方说计算这个相对很难,许多东西是共享的.
--//很难有一个好方法计算,不过当时给了一个命令pmap,可以查看进程的内存使用情况,我当时使用命令看了一些,感觉输出许多东西都不理解.
--//只能放弃.我现在基本使用smem大致了解该实例使用内存的情况.实际上上面的输出不包括共享内存段使用情况.
--//正好前几天论坛有人问类似的问题,链接http://www.itpub.net/thread-2121531-1-1.html,自己尝试了解学习这方面内容.
--//顺便说一下,对于操作系统这方面的内容十分欠缺,许多只能是猜测,也许完全不对.
1.环境:
SYS@book> @ ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
# cat /etc/issue
Oracle Linux Server release 5.9
Kernel on an m
2.共享内存段的确定:
$ ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | awk "{print $2}"| paste -sd" "
43689 43691 43693 43697 43699 43701 43703 43705 43707 43709 43711 43713 43715 43717 43719 43721 43723 43725 43727 43734 43737 43739 43741 43757 43822 52465 56819 57058
$ all=$(ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | awk "{print $2}"| paste -sd" ")
$ ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | awk "{print $2}"| wc
28 28 168
--//当前全部28个进程.
SYS@book> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
295 175 56818 DEDICATED 56819 21 62 alter system kill session "295,175" immediate;
$ pmap -x 56819 | head
56819: oraclebook (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
Address Kbytes RSS Dirty Mode Mapping
0000000000400000 189264 21624 0 r-x-- oracle
000000000bed4000 2020 352 76 rw--- oracle
000000000c0cd000 348 196 196 rw--- [ anon ]
000000000d6a6000 568 484 484 rw--- [ anon ]
0000000060000000 12288 0 0 rw-s- SYSV00000000 (deleted)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0000000060c00000 618496 0 0 rw-s- SYSV00000000 (deleted)
0000000086800000 2048 0 0 rw-s- SYSVe8a8ec10 (deleted)
00000032cac00000 520 124 0 r-x-- libm-2.5.so
--//你可以发现下划线内容应该上是共享内存段.很奇怪为什么后面标识都是deleted.另外我这里测试不包括AMM的情况.AMM好像共享内存段使用/dev/shm/...
$ sysresv
IPC Resources for ORACLE_SID "book" :
Shared Memory:
ID KEY
368312329 0x00000000
368345098 0x00000000
368377867 0xe8a8ec10
Semaphores:
ID KEY
324927491 0x6aa88594
Oracle Instance alive for sid "book"
--//可以发现完全能对上.
$ pmap -x $all | grep "SYSV" | sort | uniq -c
28 0000000060000000 12288 0 0 rw-s- SYSV00000000 (deleted)
28 0000000060c00000 618496 0 0 rw-s- SYSV00000000 (deleted)
28 0000000086800000 2048 0 0 rw-s- SYSVe8a8ec10 (deleted)
--//可以确定要确定Shared Memory segment的计算仅仅找一个相关进程就可以确定.
3.pmap的mode相关问题:
--//我注意到mode这列.我的理解rw表示这段内存可以读写权限.而r_仅仅有读权限.
--//先看看有多少mode模式:
$ pmap -q -x $all | grep -v ":" | awk "{print $5}" | sort | uniq -c
548 -----
218 r----
1438 rw---
104 rw-s-
656 r-x--
--//仅仅存在这些模式.
$ pmap -q -x $all | grep -v ":" | awk "($5=="r----" || $5=="-----" || $5=="r-x--") {print}" | sort | uniq -c | head -60
1 0000000000400000 189264 10968 0 r-x-- oracle
1 0000000000400000 189264 11068 0 r-x-- oracle
1 0000000000400000 189264 11636 0 r-x-- oracle
1 0000000000400000 189264 11668 0 r-x-- oracle
1 0000000000400000 189264 11708 0 r-x-- oracle
1 0000000000400000 189264 11724 0 r-x-- oracle
1 0000000000400000 189264 11788 0 r-x-- oracle
1 0000000000400000 189264 11860 0 r-x-- oracle
1 0000000000400000 189264 12032 0 r-x-- oracle
1 0000000000400000 189264 12080 0 r-x-- oracle
1 0000000000400000 189264 12096 0 r-x-- oracle
1 0000000000400000 189264 12148 0 r-x-- oracle
1 0000000000400000 189264 12152 0 r-x-- oracle
1 0000000000400000 189264 12180 0 r-x-- oracle
1 0000000000400000 189264 12368 0 r-x-- oracle
1 0000000000400000 189264 12568 0 r-x-- oracle
1 0000000000400000 189264 12592 0 r-x-- oracle
1 0000000000400000 189264 12736 0 r-x-- oracle
1 0000000000400000 189264 12808 0 r-x-- oracle
1 0000000000400000 189264 12920 0 r-x-- oracle
1 0000000000400000 189264 16504 0 r-x-- oracle
1 0000000000400000 189264 16952 0 r-x-- oracle
1 0000000000400000 189264 18828 0 r-x-- oracle
1 0000000000400000 189264 21152 0 r-x-- oracle
1 0000000000400000 189264 21624 0 r-x-- oracle
1 0000000000400000 189264 23452 0 r-x-- oracle
1 0000000000400000 189264 27616 0 r-x-- oracle
2 00000032cac00000 520 124 0 r-x-- libm-2.5.so
1 00000032cac00000 520 136 0 r-x-- libm-2.5.so
1 00000032cac00000 520 144 0 r-x-- libm-2.5.so
2 00000032cac00000 520 20 0 r-x-- libm-2.5.so
17 00000032cac00000 520 64 0 r-x-- libm-2.5.so
1 00000032cac00000 520 68 0 r-x-- libm-2.5.so
2 00000032cac00000 520 80 0 r-x-- libm-2.5.so
1 00000032cac00000 520 88 0 r-x-- libm-2.5.so
27 00000032cac82000 2044 0 0 ----- libm-2.5.so
27 00000032cae81000 4 4 4 r---- libm-2.5.so
27 0000003798c00000 112 108 0 r-x-- ld-2.5.so
27 0000003798e1c000 4 4 4 r---- ld-2.5.so
12 0000003799000000 1340 468 0 r-x-- libc-2.5.so
7 0000003799000000 1340 480 0 r-x-- libc-2.5.so
3 0000003799000000 1340 484 0 r-x-- libc-2.5.so
2 0000003799000000 1340 488 0 r-x-- libc-2.5.so
1 0000003799000000 1340 500 0 r-x-- libc-2.5.so
1 0000003799000000 1340 524 0 r-x-- libc-2.5.so
1 0000003799000000 1340 536 0 r-x-- libc-2.5.so
27 000000379914f000 2048 0 0 ----- libc-2.5.so
27 000000379934f000 16 16 8 r---- libc-2.5.so
27 0000003799800000 8 8 0 r-x-- libdl-2.5.so
27 0000003799802000 2048 0 0 ----- libdl-2.5.so
27 0000003799a02000 4 4 4 r---- libdl-2.5.so
25 000000379a000000 88 56 0 r-x-- libpthread-2.5.so
2 000000379a000000 88 60 0 r-x-- libpthread-2.5.so
27 000000379a016000 2048 0 0 ----- libpthread-2.5.so
27 000000379a216000 4 4 4 r---- libpthread-2.5.so
27 000000379a400000 28 16 0 r-x-- librt-2.5.so
27 000000379a407000 2048 0 0 ----- librt-2.5.so
27 000000379a607000 4 4 4 r---- librt-2.5.so
27 000000379c400000 84 24 0 r-x-- libnsl-2.5.so
27 000000379c415000 2044 0 0 ----- libnsl-2.5.so
$ pmap -q -x $all | grep -v ":" | awk "($5=="r----" || $5=="-----" || $5=="r-x--") {print}" | sort | uniq -c | tail
1 00007fffd35c2000 4 4 0 r-x-- [ anon ]
1 00007fffdfd90000 4 4 0 r-x-- [ anon ]
1 00007fffe77ea000 4 4 0 r-x-- [ anon ]
1 00007fffebbff000 4 4 0 r-x-- [ anon ]
1 00007fffef1ff000 4 4 0 r-x-- [ anon ]
1 00007ffff1dff000 4 4 0 r-x-- [ anon ]
1 00007ffff63ff000 4 4 0 r-x-- [ anon ]
1 00007ffffb1ff000 4 4 0 r-x-- [ anon ]
1 00007ffffb5ff000 4 4 0 r-x-- [ anon ]
27 ffffffffff600000 4 0 0 r-x-- [ anon ]
--//这些都是共享库以及oracle命令在内存中的映射.不知道为什么最后Mapping信息不包括路径.出了后面的标识"[ anon ]"
--//anon 应该是 anonymous的缩写,表示无名的; 假名的; 匿名的; 的意思.也就是这些基本对于的是oracle.
--//顺便说一下,我在测试中发现ora_w000_book进程会隔一段时间重新建立.不知道为什么.这样你看到的前面计数是27.好像20分钟重新建立一个.
$ ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | grep ora_w000_boo[k]
oracle 57612 1 0 10:11 ? 00:00:00 ora_w000_book
..
$ ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | grep ora_w000_boo[k]
oracle 57943 1 0 10:31 ? 00:00:00 ora_w000_book
--//继续查看mode="rw-s-"的情况:
$ pmap -q -x $all | grep -v ":" | awk "( $5=="rw-s-") {print}" | sort | uniq -c
27 0000000060000000 12288 0 0 rw-s- SYSV00000000 (deleted)
27 0000000060c00000 618496 0 0 rw-s- SYSV00000000 (deleted)
27 0000000086800000 2048 0 0 rw-s- SYSVe8a8ec10 (deleted)
1 00007f0ad0240000 4 4 0 rw-s- hc_book.dat
1 00007f143e5f5000 4 4 0 rw-s- hc_book.dat
1 00007f19de855000 4 4 0 rw-s- hc_book.dat
1 00007f1d13463000 4 4 0 rw-s- hc_book.dat
1 00007f1d7224d000 4 4 0 rw-s- hc_book.dat
1 00007f29117de000 4 4 0 rw-s- hc_book.dat
1 00007f35cb9ba000 4 4 0 rw-s- hc_book.dat
1 00007f36a9947000 4 4 0 rw-s- hc_book.dat
1 00007f4033b74000 4 4 0 rw-s- hc_book.dat
1 00007f4cb071b000 4 4 0 rw-s- hc_book.dat
1 00007f5631d35000 4 4 0 rw-s- hc_book.dat
1 00007f58f5e27000 4 4 0 rw-s- hc_book.dat
1 00007f59cc7ac000 4 4 0 rw-s- hc_book.dat
1 00007f68e6c57000 4 4 0 rw-s- hc_book.dat
1 00007f759b1f5000 4 4 0 rw-s- hc_book.dat
1 00007f7b9765e000 4 4 0 rw-s- hc_book.dat
1 00007fac270b9000 4 4 0 rw-s- hc_book.dat
1 00007fbb8cd8c000 4 4 0 rw-s- hc_book.dat
1 00007fcab3977000 4 4 0 rw-s- hc_book.dat
1 00007fd4459ac000 4 4 0 rw-s- hc_book.dat
1 00007fdba0f0a000 4 4 0 rw-s- hc_book.dat
1 00007ff09931d000 4 4 0 rw-s- hc_book.dat
1 00007ff844549000 4 4 0 rw-s- hc_book.dat
--//基本mode="rw-s-"都是Shared Memory segment以及hc_book.dat.
$ ls -l `which oracle `
-rwsr-s--x 1 oracle oinstall 239627073 2018-05-02 09:51:04 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/oracle
--//mode里面的s,表示什么,share吗?
$ ls -l `locate hc_book.dat`
-rw-rw---- 1 oracle oinstall 1544 2019-11-14 08:41:02 /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/hc_book.dat
--//--//继续查看mode="rw---"的情况:
$ pmap -q -x $all | grep -v ":" | awk "( $5=="rw---") {print}" | sort | uniq -c | head -60
13 000000000bed4000 2020 256 76 rw--- oracle
1 000000000bed4000 2020 256 80 rw--- oracle
1 000000000bed4000 2020 260 76 rw--- oracle
2 000000000bed4000 2020 264 76 rw--- oracle
2 000000000bed4000 2020 268 76 rw--- oracle
1 000000000bed4000 2020 272 76 rw--- oracle
1 000000000bed4000 2020 276 80 rw--- oracle
1 000000000bed4000 2020 308 76 rw--- oracle
1 000000000bed4000 2020 320 76 rw--- oracle
1 000000000bed4000 2020 344 76 rw--- oracle
2 000000000bed4000 2020 352 76 rw--- oracle
1 000000000bed4000 2020 432 76 rw--- oracle
18 000000000c0cd000 348 188 188 rw--- [ anon ]
7 000000000c0cd000 348 192 192 rw--- [ anon ]
2 000000000c0cd000 348 196 196 rw--- [ anon ]
1 000000000c1e0000 436 340 340 rw--- [ anon ]
1 000000000c37f000 436 376 376 rw--- [ anon ]
1 000000000c448000 436 340 340 rw--- [ anon ]
1 000000000c554000 568 516 516 rw--- [ anon ]
1 000000000c5d7000 1616 1460 1460 rw--- [ anon ]
1 000000000c635000 436 340 340 rw--- [ anon ]
1 000000000c737000 436 340 340 rw--- [ anon ]
1 000000000cb07000 436 340 340 rw--- [ anon ]
1 000000000cb4a000 436 340 340 rw--- [ anon ]
1 000000000ce91000 436 348 348 rw--- [ anon ]
1 000000000ce92000 436 348 348 rw--- [ anon ]
1 000000000cf23000 568 476 476 rw--- [ anon ]
1 000000000cfa4000 576 504 504 rw--- [ anon ]
1 000000000d087000 436 340 340 rw--- [ anon ]
1 000000000d0a9000 436 348 348 rw--- [ anon ]
1 000000000d1a1000 436 348 348 rw--- [ anon ]
1 000000000d1c0000 436 348 348 rw--- [ anon ]
1 000000000d29d000 436 344 344 rw--- [ anon ]
1 000000000d313000 436 340 340 rw--- [ anon ]
1 000000000d667000 436 340 340 rw--- [ anon ]
1 000000000d6a6000 568 484 484 rw--- [ anon ]
1 000000000d936000 436 340 340 rw--- [ anon ]
1 000000000d958000 436 388 388 rw--- [ anon ]
1 000000000dd0e000 436 348 348 rw--- [ anon ]
1 000000000de97000 436 348 348 rw--- [ anon ]
1 000000000dfc2000 436 348 348 rw--- [ anon ]
1 000000000dfcc000 436 340 340 rw--- [ anon ]
27 00000032cae82000 4 4 4 rw--- libm-2.5.so
27 0000003798e1d000 4 4 4 rw--- ld-2.5.so
27 0000003799353000 4 4 4 rw--- libc-2.5.so
27 0000003799354000 20 20 20 rw--- [ anon ]
27 0000003799a03000 4 4 4 rw--- libdl-2.5.so
27 000000379a217000 4 4 4 rw--- libpthread-2.5.so
27 000000379a218000 16 4 4 rw--- [ anon ]
27 000000379a608000 4 4 4 rw--- librt-2.5.so
27 000000379c615000 4 4 4 rw--- libnsl-2.5.so
27 000000379c616000 8 0 0 rw--- [ anon ]
1 000000379ea12000 4 4 4 rw--- libresolv-2.5.so
1 000000379ea13000 8 0 0 rw--- [ anon ]
1 00007f0ad0241000 8 8 8 rw--- [ anon ]
1 00007f0ad044d000 4 4 4 rw--- libnss_files-2.5.so
1 00007f0ad044e000 72 24 24 rw--- zero
1 00007f0ad0460000 64 16 16 rw--- zero
1 00007f0ad0470000 64 20 20 rw--- zero
1 00007f0ad0480000 64 56 56 rw--- zero
--//奇怪一些library文件也有一些区域可以写入.
4.继续探究:
--//pmap的输出第1,2个字段是Address,Kbytes看看是否出现重叠的情况.
SCOTT@book> create table tx ( a varchar2(40),b number );
Table created.
$ all=$(ps -ef | egrep "[o]raclebook|[o]ra_.*_book" | awk "{print $2}"| paste -sd" ")
$ pmap -q -x $all | grep -v ":" | sort | awk "{print $1 "x27," $2 }" | uniq | sed "s/^/insert into tx values ("/;s/$/);/" | sqlplus -s -l scott/book
WITH sub1
AS ( SELECT a, b, LEAD (a, 1, NULL) OVER (ORDER BY a) c
FROM tx
ORDER BY a)
,sub2
AS (SELECT TO_NUMBER (a, "xxxxxxxxxxxxxxxxxxxxxx") a1
,b * 1024 b1
,TO_NUMBER (c, "xxxxxxxxxxxxxxxxxxxxxx") c1
,a,c
FROM sub1)
SELECT c1 - a1 delta
,b1
,c1
,a1
,a,c
FROM sub2
WHERE c1 -a1
DELTA B1 C1 A1 A C
------ ---------- ---------- ---------- ---------------- ----------------
536576 581632 207450112 206913536 000000000c554000 000000000c5d7000
385024 1654784 207835136 207450112 000000000c5d7000 000000000c635000
274432 446464 213164032 212889600 000000000cb07000 000000000cb4a000
4096 446464 216604672 216600576 000000000ce91000 000000000ce92000
528384 581632 217726976 217198592 000000000cf23000 000000000cfa4000
139264 446464 218796032 218656768 000000000d087000 000000000d0a9000
196608 581632 219811840 219615232 000000000d171000 000000000d1a1000
126976 446464 219938816 219811840 000000000d1a1000 000000000d1c0000
139264 446464 227901440 227762176 000000000d936000 000000000d958000
40960 446464 234668032 234627072 000000000dfc2000 000000000dfcc000
167936 446464 234835968 234668032 000000000dfcc000 000000000dff5000
11 rows selected.
$ pmap -q -x $all | egrep "000000000c554000|000000000c5d7000|000000000cb07000|000000000ce91000|000000000cf23000|000000000d087000|000000000d171000|000000000d1a1000|000000000d936000|000000000dfc2000|000000000dfcc000"|sort
000000000c554000 568 516 516 rw--- [ anon ]
000000000c5d7000 1616 1460 1460 rw--- [ anon ]
000000000cb07000 436 340 340 rw--- [ anon ]
000000000ce91000 436 348 348 rw--- [ anon ]
000000000cf23000 568 476 476 rw--- [ anon ]
000000000d087000 436 340 340 rw--- [ anon ]
000000000d171000 568 480 480 rw--- [ anon ]
000000000d1a1000 436 348 348 rw--- [ anon ]
000000000d936000 436 340 340 rw--- [ anon ]
000000000dfc2000 436 348 348 rw--- [ anon ]
000000000dfcc000 436 340 340 rw--- [ anon ]
--//不知道为什么?不过这些重叠区域占用大小不大.
$ all=$(ps -ef | egrep "[o]racle${sid}|[o]ra_.*_${sid}" | awk "{print $2}"| paste -sd" " )
$ client=$(ps -ef | egrep "[o]racle${sid}" | awk "{print $2}"| paste -sd" " )
$ pmap -q -x $client >| /tmp/omapclient.txt
$ pmap -q -x $all >| /tmp/omap.txt
$ egrep ":|000000000c554000|000000000c5d7000|000000000cb07000|000000000ce91000|000000000cf23000|000000000d087000|000000000d171000|000000000d1a1000|000000000d936000|000000000dfc2000|000000000dfcc000" /tmp/omap.txt
564: ora_w000_book
43689: ora_pmon_book
000000000c554000 568 516 516 rw--- [ anon ]
43691: ora_psp0_book
000000000dfcc000 436 340 340 rw--- [ anon ]
43693: ora_vktm_book
000000000d087000 436 340 340 rw--- [ anon ]
43697: ora_gen0_book
000000000d1a1000 436 348 348 rw--- [ anon ]
43699: ora_diag_book
43701: ora_dbrm_book
43703: ora_dia0_book
000000000cb07000 436 340 340 rw--- [ anon ]
43705: ora_mman_book
43707: ora_dbw0_book
43709: ora_dbw1_book
000000000d936000 436 340 340 rw--- [ anon ]
43711: ora_dbw2_book
43713: ora_lgwr_book
43715: ora_ckpt_book
43717: ora_smon_book
43719: ora_reco_book
43721: ora_mmon_book
43723: ora_mmnl_book
000000000c5d7000 1616 1460 1460 rw--- [ anon ]
43725: ora_d000_book
43727: ora_s000_book
43734: ora_rvwr_book
000000000dfc2000 436 348 348 rw--- [ anon ]
43737: ora_arc0_book
000000000ce91000 436 348 348 rw--- [ anon ]
43739: ora_arc1_book
43741: ora_ctwr_book
43757: ora_cjq0_book
43822: ora_smco_book
52465: oraclebook (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
000000000cf23000 568 476 476 rw--- [ anon ]
58344: oraclebook (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
000000000d171000 568 480 480 rw--- [ anon ]
--//2个client也存在重叠区域.
000000000c554000=> 43689: ora_pmon_book
000000000c5d7000=> 43723: ora_mmnl_book
5.我根据前面的测试:
--//大致按照mode分类累加,消除重复的段,大概能得到oracle占用的内存量.当然这些还是不准的.比如libc共享库,其它程序也需要不仅仅oracle代码.
--//还有重叠的问题^_^.
--//另外我发现如果相关进程很多有点慢,我先snapshot到文件,这样能保存分析的一致性,避免一些进程已经退出的情况.
--//仅仅作为大致了解当前实例的汇总情况,估计给结合smem分析(smem包括交换,以及各个进程的情况).
--//测试时最好有1个专用连接数据库,不想做一些判断了.
$ seq 150 | xargs -I {} bash -c "sqlplus -s -l scott/book <<< "select sleep(20) from dual ;" & "
$ . omap.sh book
report memory used by oracle instance book as of 2019/11/15_15:35:29
=================================================================================
shared memory segments .................................... : 632832 KB
Shared binary code and shared libraries ................... : 6396384 KB
private memory (foreground and background)................. : 1129296 KB
sum memory for oracle instance ............................ : 8158512 KB
Number of current dedicated connections ................... : 172
private memory (foreground decicated connections).......... : 878672 KB
=================================================================================
--//顺便贴一个生产系统的情况:
# ./omap.sh xxxx1
report memory used by oracle instance xxxx1 as of 2019/11/15_15:57:31
=================================================================================
shared memory segments .................................... : 79431680 KB
Shared binary code and shared libraries ................... : 45661756 KB
private memory (foreground and background)................. : 9136504 KB
sum memory for oracle instance ............................ : 134229940 KB
Number of current dedicated connections ................... : 4405
private memory (foreground decicated connections).......... : 7372600 KB
=================================================================================
6.补充学习:
$ pmap -x 56819 | head
56819: oraclebook (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
Address Kbytes RSS Dirty Mode Mapping
0000000000400000 189264 21624 0 r-x-- oracle
000000000bed4000 2020 352 76 rw--- oracle
000000000c0cd000 348 196 196 rw--- [ anon ]
000000000d6a6000 568 484 484 rw--- [ anon ]
0000000060000000 12288 0 0 rw-s- SYSV00000000 (deleted)
0000000060c00000 618496 0 0 rw-s- SYSV00000000 (deleted)
0000000086800000 2048 0 0 rw-s- SYSVe8a8ec10 (deleted)
00000032cac00000 520 124 0 r-x-- libm-2.5.so
--//0x000000000bed4000 - 0x0000000000400000 = 195903488, 195903488/1024 = 191312
--//000000000c0cd000 - 000000000bed4000 = 2068480 ,2068480/1024 = 2020
$ size $(which oracle) | column -t
text data bss dec hex filename
193804111 2065800 357672 196227583 bb231ff /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/oracle
--//基本能对上size看到的text,data段大小.0xbb231ff = 196227583
7.源代码如下:
#! /bin/bash
# Purpose : calculate oracle using memory
# Author : lfree
# Date/Time : 2019-11-15 10:10:10
# Modified date: 2019-11-15 10:10:11
odebug=${ODEBUG:-0}
if [ $# -lt 1 ]; then
echo "Usage: $0 ORACLE_SID "
exit 1
fi
sid=$1
# substr oracle foreground and background of pids
all=$(ps -ef | egrep "[o]racle${sid}|[o]ra_.*_${sid}" | awk "{print $2}"| paste -sd" " )
client=$(ps -ef | egrep "[o]racle${sid}" | awk "{print $2}"| paste -sd" " )
conn=$(ps -ef | egrep "[o]racle${sid}" | wc -l )
if [ $odebug -eq 1 ] ; then
echo $client
echo $all
echo $conn
fi
pmap -q -x $client >| /tmp/omapclient.txt
pmap -q -x $all >| /tmp/omap.txt
sysvsz=$(cat /tmp/omap.txt | grep "SYSV" |awk "($5 ~ /^rw-/) {print $1,",",$2}" | sort | uniq | cut -f2 -d, | paste -sd+ | bc )
sharedsz=$(cat /tmp/omap.txt | grep -v ":" | awk "($5=="r----" || $5=="-----" || $5=="r-x--") {print $1,",",$2}" | sort | uniq | cut -f2 -d,| paste -sd+ | bc )
privatesz=$(cat /tmp/omap.txt | grep -v ":" | grep -v "SYSV" |awk "($5 ~ /^rw-/) {print $1,",",$2}" | sort | uniq | cut -f2 -d, | paste -sd+ | bc )
sumsz=$((sharedsz + privatesz + sysvsz ))
clientprivatesz=$(cat /tmp/omapclient.txt | grep -v ":" | grep -v "SYSV" |awk "($5 ~ /^rw-/) {print $1,",",$2}" | sort | uniq | cut -f2 -d, | paste -sd+ | bc )
if [ $odebug -eq 1 ] ; then
echo connect = $conn
echo sysvsz = $sysvsz
echo sharedsz = $sharedsz
echo privatesz = $privatesz
echo sumsz = $sumsz
fi
echo
echo "report memory used by oracle instance $sid as of " `date +"%Y/%m/%d_%T"`
echo "================================================================================="
printf "shared memory segments .................................... : %12d KB
" $sysvsz
printf "Shared binary code and shared libraries ................... : %12d KB
" $sharedsz
printf "private memory (foreground and background)................. : %12d KB
" $privatesz
printf "sum memory for oracle instance ............................ : %12d KB
" $sumsz
echo
printf "Number of current dedicated connections ................... : %12d
" $conn
printf "private memory (foreground decicated connections).......... : %12d KB
" $clientprivatesz
echo "================================================================================="
echo
#/bin/rm /tmp/omap.txt /tmp/omapclient.txt