2019-02-22

Showing Total Memory Used Per Oracle DB Instance


The following command gets the output of "ps aux"...
... takes only the lines regarding Oracle DB ("ora_") ...
... and sums up the RSS (resident set size, the non-swapped physical memory that a task has used (in kiloBytes)) ...
... grouped by DB SID


ps aux --sort -rss | awk '/USER +PID | ora_/{ split($11,a,"_"); db=a[3]; if(db!="" && db!="RSS"){ m[db]+=$6; } } END{for (db in m){ printf("DB:%9s uses %7.1f MB RAM\n",db,m[db]/1024); tot+=m[db]} printf("%12sTotal %7.1f GB RAM\n"," ",tot/(1024*1024))}'

Output Example
(DB "Dfug" is a temporary DB that has been automatically created by RMAN in order to make a TSPITR)
DB:     Dfug uses   884.9 MB RAM
DB: C0201Z01 uses  4196.6 MB RAM
            Total     5.0 GB RAM

2019-02-05

Number Comparison Statements in KSH (Korn-Shell)


Before showing two variants of a number comparison statement, I want to show an alternative method counting the occurrence of a string in another one.

The following "grep -c" counts the occurrences of ":" in the echoed string:
echo "gu:gus:bla:bla" | grep -c ":"
Output
3

Another way to write the statement from above is:
grep -c ":" <<< "gu:gus:bla:bla"
Output
3


Here two examples of similar number comparison statements using the output of the statement from above:
OS> if (( $(grep -c ":" <<< "gugus:blabla") == 1 )); then echo "TRUE"; else echo "FALSE"; fi
TRUE

OS> if (( $(grep -c ":" <<< "gugus blabla") == 1 )); then echo "TRUE"; else echo "FALSE"; fi
FALSE

OS> if [[ $(grep -c ":" <<< "gugus:blabla") -eq 1 ]]; then echo "TRUE"; else echo "FALSE"; fi
TRUE

OS> if [[ $(grep -c ":" <<< "gugus blabla") -eq 1 ]]; then echo "TRUE"; else echo "FALSE"; fi
FALSE

I consider the first variant to be more elegant.
But if you are mixing character and numerical comparisons, you will need to use the 2nd variant with "[[ ... ]]"
For example:
X="Hello"; if [[ "${X}" == "Hello" && $(grep -c ":" <<< "gugus:blabla") -eq 1 ]]; then echo "TRUE"; else echo "FALSE"; fi
TRUE
X="Bella"; if [[ "${X}" == "Hello" && $(grep -c ":" <<< "gugus:blabla") -eq 1 ]]; then echo "TRUE"; else echo "FALSE"; fi
FALSE

The following syntax gives wrong results
OS> X="Xello"; if (( "${X}" == "Hello" && $(grep -c ":" <<< "gugus:blabla") == 1 )); then echo "TRUE"; else echo "FALSE"; fi
TRUE

OS> X="Bella"; if (( "${X}" == "Hello" && $(grep -c ":" <<< "gugus:blabla") == 1 )); then echo "TRUE"; else echo "FALSE"; fi
TRUE <== Wrong

Matematical
Syntax
"In Words"
==
-eq
<
-lt
>
-gt
=<
-le
>=
-ge
!=
-ne