[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 \r 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 <b1;
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\n" $sysvsz
printf "Shared binary code and shared libraries ................... : %12d KB\n" $sharedsz
printf "private memory (foreground and background)................. : %12d KB\n" $privatesz
printf "sum memory for oracle instance ............................ : %12d KB\n" $sumsz
echo
printf "Number of current dedicated connections ................... : %12d\n" $conn
printf "private memory (foreground decicated connections).......... : %12d KB\n" $clientprivatesz
echo "================================================================================="
echo
#/bin/rm /tmp/omap.txt /tmp/omapclient.txt
html