0% found this document useful (0 votes)
115 views9 pages

Oracle DB 19C ADMINISTRATION SERIES

The document provides guidelines for setting the System Global Area (SGA) and Program Global Area (PGA) in Oracle databases based on different workloads (OLTP, OLAP/DSS, and Mixed). It includes formulas for calculating memory allocation ratios and examples for a server with 50 GB RAM. Additionally, it offers a shell script and SQL code for automating the memory allocation process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views9 pages

Oracle DB 19C ADMINISTRATION SERIES

The document provides guidelines for setting the System Global Area (SGA) and Program Global Area (PGA) in Oracle databases based on different workloads (OLTP, OLAP/DSS, and Mixed). It includes formulas for calculating memory allocation ratios and examples for a server with 50 GB RAM. Additionally, it offers a shell script and SQL code for automating the memory allocation process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1

SGA and PGA Setting

Database Installation:
SGA and PGA Formula

ORACLE DATABASE
ADMINISTRATION SERIES

S.N STEPHEN NJOROGE

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE

LinkedIn: www.linkedln.com/in/stephen-njoroge
2
SGA and PGA Setting

Formula to calculate the SGA:PGA ratio in Oracle database .The


ratio between SGA and PGA varies depending on whether the
database is OLTP, OLAP/DSS or Mixed workload.

General Formula
Total Memory for Oracle ( ~75%) of Physical RAM

 T = Total server RAM (e.g., 50 GB)


 M = Memory allocated to Oracle instance
 SGA = Memory allocated to SGA
 PGA = Memory allocated to PGA

 M=0.75×T
 SGA+PGA=M

OLTP Workload (Online Transactions )

Component % of M Ratio
SGA 75% 3:1
PGA 25% 1:3

Formula:
 SGA=0.77×M
 PGA=0.25×M

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE


3
SGA and PGA Setting

OLAP / DSS Workload ( Heavy Queries)

Component % of M Ratio
SGA 40% 2:5
PGA 60% 3:5

Formula:
 SGA=0.40×M
 PGA=0.60×M

Mixed Workload

Component % of M Ratio
SGA 60 3:5
PGA 40 2:5

Formula:
 SGA=0.40×M
 PGA=0.60×M

Example Calculation for (50 GB RAM) server.


Use Case:

 T = 50 GB
 M = 0.75 × 50 = 37.5 GB

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE


4
SGA and PGA Setting

Scenario:
OLTP Instances (Ratio ~ 3:1)

 SGA=0.75×37.5=28.125 GB
 PGA=0.25×37.5=9.375 GB

OLAP Instances (Ratio ~ 2:3)

 SGA=0.40×37.5=15 GB
 PGA=0.60×37.5=22.5 GB

Mixed Workload Instances (Ratio ~ 2:1)

 SGA=0.66×37.5=24.75 GB,
 PGA=0.34×37.5=12.75 GB

Reference Table

Workload Ratio SGA


PGA (GB)
Type (SGA:PGA) (GB)
OLTP 3:1 28.13 9.38
OLAP 2:3 15 22.5
Mixed 2:1 24.75 12.75

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE


5
SGA and PGA Setting

Tip

For Automatic Memory Management (AMM) :

ALTER SYSTEM SET memory_target = 37.5G SCOPE = SPFILE;


ALTER SYSTEM SET memory_max_target = 40G SCOPE =
SPFILE;

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE


6
SGA and PGA Setting

Shell Script (for Linux servers)

#!/bin/bash

echo "=== Oracle Memory Allocation Script ==="


read -p "Enter total server RAM in GB: " TOTAL_RAM
read -p "Enter workload type (OLTP, OLAP, MIXED): "
WORKLOAD

# Convert to MB
TOTAL_MB=$((TOTAL_RAM * 1024))
ORACLE_MB=$((TOTAL_MB * 75 / 100))

case "$WORKLOAD" in
"OLTP"|"oltp")
SGA_MB=$((ORACLE_MB * 75 / 100))
PGA_MB=$((ORACLE_MB - SGA_MB))
;;
"OLAP"|"olap")
SGA_MB=$((ORACLE_MB * 45 / 100))
PGA_MB=$((ORACLE_MB - SGA_MB))
;;
"MIXED"|"mixed")
SGA_MB=$((ORACLE_MB * 66 / 100))
PGA_MB=$((ORACLE_MB - SGA_MB))
;;
*)
echo "Invalid workload type. Use OLTP, OLAP, or
MIXED."
ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE
7
SGA and PGA Setting
exit 1
;;
esac

echo
echo "Estimated Oracle Memory: $((ORACLE_MB / 1024))
GB"
echo " - SGA Target : $SGA_MB MB"
echo " - PGA Target : $PGA_MB MB"
echo
echo "You can apply these settings using SQL:"
echo "------------------------------------------"
echo "ALTER SYSTEM SET sga_target = ${SGA_MB}M SCOPE =
SPFILE;"
echo "ALTER SYSTEM SET pga_aggregate_target =
${PGA_MB}M SCOPE = SPFILE;"
echo "ALTER SYSTEM SET sga_max_size = ${SGA_MB}M SCOPE
= SPFILE;"

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE


8
SGA and PGA Setting

SQL Version

-- Replace values manually here

DEFINE total_ram_gb = 50
DEFINE workload = 'OLTP' -- Options: OLTP, OLAP, MIXED

DECLARE
total_ram_mb NUMBER := &total_ram_gb * 1024;
usable_mem_mb NUMBER := total_ram_mb * 0.75;
sga_target_mb NUMBER;
pga_target_mb NUMBER;
BEGIN
CASE UPPER('&workload')
WHEN 'OLTP' THEN
sga_target_mb := usable_mem_mb * 0.75;
WHEN 'OLAP' THEN
sga_target_mb := usable_mem_mb * 0.45;
WHEN 'MIXED' THEN
sga_target_mb := usable_mem_mb * 0.66;
ELSE
raise_application_error(-20001, 'Invalid
workload type');
END CASE;

pga_target_mb := usable_mem_mb - sga_target_mb;

DBMS_OUTPUT.PUT_LINE('SGA_TARGET = ' ||
ROUND(sga_target_mb) || 'M');
ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE
9
SGA and PGA Setting
DBMS_OUTPUT.PUT_LINE('PGA_AGGREGATE_TARGET = ' ||
ROUND(pga_target_mb) || 'M');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('Run these commands:');
DBMS_OUTPUT.PUT_LINE('ALTER SYSTEM SET sga_target =
' || ROUND(sga_target_mb) || 'M SCOPE = SPFILE;');
DBMS_OUTPUT.PUT_LINE('ALTER SYSTEM SET
pga_aggregate_target = ' || ROUND(pga_target_mb) || 'M
SCOPE = SPFILE;');
END;
/

ORACLE DATABASE ADMINISTRATON STEPHEN NJOROGE

You might also like