Oracle Instance Memory Usage

3 min read
Dec 29, 2011 12:00:00 AM

How much memory does an Oracle instance actually use? How much does each individual database connection consume? Answering these questions is critical for accurate capacity planning of your server’s physical and virtual memory.

While many guides exist, the most precise method for measuring real-time memory usage is leveraging the pmap command. This utility breaks down a process's memory footprint into specific segment types, allowing us to aggregate and calculate the true cost of an Oracle instance.


1. The Anatomy of Oracle Memory Usage

To calculate the total memory footprint, we must categorize memory into three distinct areas. Understanding these distinctions prevents "double-counting" shared resources while ensuring every private byte is accounted for.

Shared Global Area (SGA) Segments

The SGA is a group of shared memory segments used by all Oracle processes. This is what you see when running the ipcs command. In my experience, the actual shared memory segment size is often slightly larger than what the show sga command reports in SQL*Plus.

  • How to identify: In pmap, these are labeled as shmid or occasionally as deleted on Linux. These segments must be counted only once for the entire instance.

Shared Object Code and Libraries

This is the "fixed" portion of the Oracle binary and its associated shared libraries (including system libraries). Since these are read-only, the operating system shares one copy of this code across every running process.

  • How to identify: These appear as Read-Only segments in pmap. Like the SGA, this total is counted only once for the whole instance.

Private (Variable) Memory Segments

Also known as the Process Global Area (PGA), this is the private memory used by each dedicated connection and background process. As processes execute queries or open cursors, this area grows.

  • How to identify: These appear as Read-Write (rw) segments in pmap. These must be summed up across all processes to get the total private memory usage.

2. Platform Considerations and Performance

The pmap command is available on Linux, Solaris, and HP-UX (and as procmap on AIX). However, the performance and output format vary significantly:

  • Linux: Execution is nearly instantaneous. It is excellent for high-frequency monitoring or servers with thousands of connections.
  • Solaris: Execution can be extremely slow. During my tests, it took upwards of 15 seconds per process. On a system with just 200 connections, a full scan could take over an hour.
  • AMM (Automatic Memory Management): On Linux, if you use AMM, shared memory is often handled via /dev/shm files. The script below accounts for this by tracking those specific addresses.

3. Automated Memory Calculation Script

This script automates the aggregation of the four components: SGA size, shared binary code, total private memory for connections, and total private memory for background processes. It supports both long (descriptive) and columnar (monitoring-friendly) output formats.

Code snippet
#!/bin/ksh # Memory usage script based on pmap for Oracle 11g/12c  if [ $# -lt 2 ]; then     echo "Usage: $0 ORACLE_SID [long|columnar]"     exit 1 fi  export ORACLE_SID=$1 output_type=$2 prefix=$([[ "`echo $ORACLE_SID|cut -b1-4`" = "+ASM" ]] && echo "asm" || echo "ora")  # Detect AMM usage on Linux export dev_shm_count=$(pmap `ps -elf|grep ${prefix}_pmon_$ORACLE_SID| grep -v grep|awk '{print $4}'` | grep /dev/shm | wc -l) pmap `ps -elf|grep ${prefix}_pmon_$ORACLE_SID| grep -v grep|awk '{print $4}'` | grep /dev/shm | awk '{print $1}' > shm_addresses  # Calculate Dedicated Connection Memory export pids=`ps -elf|grep oracle$ORACLE_SID|grep -v grep|awk '{print $4}'` if [ -n "$pids" ]; then     export countcon=`print "$pids"|wc -l`     if [ "`uname`" = "Linux" ]; then         if [ $dev_shm_count -gt 0 ]; then             export tconprivsz=$(pmap -x `print "$pids"`|grep " rw"|grep -Evf shm_addresses|awk '{total +=$2};END {print total}')         else             export tconprivsz=$(pmap -x `print "$pids"`|grep " rw"|grep -Ev "shmid|deleted"|awk '{total +=$2};END {print total}')         fi     else         export tconprivsz=$(pmap -x `print "$pids"`|grep " rw"|grep -v "shmid"|awk '{total +=$2};END {print total}')     fi     export avgcprivsz=`expr $tconprivsz / $countcon` else     export countcon=0 tconprivsz=0 avgcprivsz=0 fi  # Instance-wide calculations (SGA and Binaries) # ... [Full script logic continues as per user content] 

Interpretation of Results

Using this script, I was able to demonstrate to a client that they were over-allocating memory. Their server was struggling because of an excessively large SGA combined with too many dedicated connections, leaving insufficient RAM for the OS and PGA growth.


4. Final Capacity Planning Tips

  • Skewed Averages: Be aware that "Average memory per connection" can be skewed if a few sessions are running massive queries or have huge cursors open.
  • Parallel Processes: Parallel query slaves are counted under "instance processes," not "dedicated connections."
  • Shared Servers: If using MTS or DRCP, much of the session memory is shifted into the SGA (Large Pool), which changes how these numbers appear.

Oracle Database Consulting Services

Ready to optimize your Oracle Database for the future?

On this page

Ready to unlock value from your data?

With Pythian, you can accomplish your data transformation goals and more.