There’s a way to know the REAL memory usage by Oracle Instance, including all connecting processes and using the shell rather than a connection to oracle?
The short answer is “I think so” 🙂
Summing up RSS column from ps output, is not reliable because Linux uses a copy-on-write on process forks and also doesn’t take into account correctly the shared memory and other shared allocations.
I’ve come across this post on Pythian’s Blog from Marc Billette.
While it seems good I’ve had discording results depending on platform and release.
Instead, I’ve tried to create a shell snippet that always uses pmap but works differently and SEEMS to work correctly on Linux ans Solaris.
Basically, using the pmap script I get a lot of information about the different memory areas allocated to the process:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
21010: ora_d000_db1p 0000000000400000 208908K r-x-- /ccv/app/oracle/product/11.2.0.3/bin/oracle 000000000D012000 1536K rw--- /ccv/app/oracle/product/11.2.0.3/bin/oracle 000000000D192000 1040K rw--- [ heap ] 0000000060000000 12288K rwxs- [ dism shmid=0x4300000e ] 0000000080000000 1036288K rwxs- [ dism shmid=0x7600000f ] 00000000C0000000 12K rwxs- [ dism shmid=0x4f000011 ] FFFFFD7FFC7A0000 64K rwx-- [ anon ] FFFFFD7FFC7BD000 704K rw--- [ anon ] FFFFFD7FFC86E000 200K rw--- [ anon ] FFFFFD7FFC8A0000 312K rw--- [ anon ] FFFFFD7FFC8EF000 1280K rw--- [ anon ] FFFFFD7FFCA30000 64K rwx-- [ anon ] FFFFFD7FFCA4F000 256K rw--- [ anon ] FFFFFD7FFCA90000 64K rwx-- [ anon ] FFFFFD7FFCAB0000 36K r-x-- /lib/amd64/libuutil.so.1 ... |
Initially I’ve tried to decode correctly the different kinds of memory the same way other scripts I’ve found online do:
1 2 3 4 5 6 7 8 9 |
rwxs- = shared memory rw--- = private heap rwx-- = private code stack r-x-- = shared code stack (?) etc... |
but finally the ADDRESS is the same from different processes when the memory area is shared, so my script now just get a unique line for each address and sums up the memory size (not the rss one!):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
username=`whoami` sids=`ps -eaf | grep "^$username" | grep pmon | grep -v " grep " | awk '{print substr($NF,10)}'` total=0 for sid in $sids ; do pids=`ps -eaf | grep "^$username" | grep -- "$sid" | grep -v " grep " | awk '{print $2}'` mem=`pmap $pids 2>&1 | grep "K " | sort | awk '{print $1 " " substr($2,1,length($2)-1)}' | uniq | awk ' BEGIN { sum=0 } { sum+=$2} END {print sum}' ` echo "$sid : $mem" total=`expr $total + $mem` done echo "total : $total" |
This should give the total virtual memory allocated by the different Oracle instances.
The results I get are plausible both on Linux and Solaris.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ ./test_mem.ksh db1p: 3334852 db2p: 2052048 db3p: 6765280 db4p: 2687928 db5p: 4385616 total : 19225724 |
If you find any error let me know and I’ll fix the script!
—
Ludovico