Document 1516229.1
Document 1516229.1
1
Copy right (c) 2024, Oracle. A ll rights reserv ed. Oracle Confidential.
In this Document
Goal
Solution
References
APPLIES TO:
NOTE: In the images and/or the document content below, the user information and data used represents fictitious data.
Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.
GOAL
This note describes how to monitor SGA memory usage on pluggable databases using queries against database views.
On RAC configuration, the scripts should be run on each instance since only V$ views are used to provide a accurate
memory usage for individual database instance.
The scripts must be run in SQL*Plus session since specific SQL*Plus functions are used.
Scripts must be run as sysdba or database user account having access to CDB*, DBA* and V$ tables.
Example scripts and their output are provided to demonstrate that purpose.
This sample code is provided for educational purposes only and not supported by Oracle Support Services. It has been
tested internally, however, and works as documented. We do not guarantee that it will work for you, so be sure to test it in
your environment before relying on it.
Proofread this sample code before using it! Due to the differences in the way text editors, e-mail packages and operating
systems handle text formatting (spaces, tabs and carriage returns), this sample code may not be in an executable state
when you first receive it. Check over the sample code to ensure that errors of this type are corrected.
SOLUTION
The queries are intended to be run on the root container database (CDB) containing pluggable databases, since many of
the queries refer to container specific views or columns. For queries against non-container database see NOTE:430473.1.
The CDB and all pluggable databases (PDBs) share a single database instance composed of the system global area (SGA)
and background processes. Because of this sharing of memory resources, it would be desirable to distinguish resource
usage among databases sharing the instance. When possible, a query will be provided that breaks down SGA memory
usage associated with each pluggable database.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 1/10
4/12/24, 16:31 Document 1516229.1
The ROUND function is used to make query results more presentable in terms of MegaBytes. Because of this rounding of
values, results may not match exactly when comparing against different sga views.
This query will indicate if the scripts are being run on the root container database.
The results from con_name should indicate the container name CDB$ROOT and container id 1 for con_id.
The command show pdbs will show all PDBs associated with the CDB, their open status and if database is opened in
restricted mode. This can be used to identify the PDB name associated with the container id (identified by con_id) which is
used in many of the queries to breakdown memory usage to a specific container.
These example results shown below indicate four additional PDBs in addition to the seed PDB associated with this CDB. The
PDB id 5 named PDB_COPY is not open. All other PDBs are open.
show con_name
show con_id
show pdbs
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 2/10
4/12/24, 16:31 Document 1516229.1
CON_NAME
------------------------------
CDB$ROOT
CON_ID
------------------------------
1
This query provides the name of the root container database CDB. In this example, named CDB1.
This query shows additional id information about each container as well as database status.
The following query provides parameter settings related to the SGA and PGA. If values for sga_target and
pga_aggregate_target are zero, then these values are sized dynamically according to AMM when memory_target > 0.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 3/10
4/12/24, 16:31 Document 1516229.1
This query provides the current size of dynamic SGA components as well as other basic information related to sizing of
each component.
The query results below show all sga components are associated with the root container id 0. The current value of
sga_target is 392M.
The following query against V$SGAINFO provides sga component sizes, the granule size, and free sga memory.
The example below shows free sga memory of 208M. This is memory above the current sga_target size of 392M as shown
in above query results. This is memory that can be allocated to the sga for increase of the sga_target.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 4/10
4/12/24, 16:31 Document 1516229.1
NAME Mbytes
------------------------- ------------
Fixed SGA Size 2
Redo Buffers 7
Buffer Cache Size 88
Shared Pool Size 276
Large Pool Size 12
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 20
Data Transfer Cache Size 0
Granule Size 4
Maximum SGA Size 597
Startup overhead in Share 107
d Pool
Free SGA Memory Available 208
The following query against V$SGA provides basic sga size information. The variable size indicated includes various sga
components and free sga memory.
NAME Mbytes
------------------------- ------------
Fixed Size 2
Variable Size 500
Database Buffers 88
Redo Buffers 7
The following query from V$SGA_DYNAMIC_FREE_MEMORY shows available free memory that can be allocated to the sga
for increase of the sga_target. This should correspond closely with the value shown in V$SGAINFO.
Mbytes
------------
208
The next two queries below provide sum of sga components and free sga memory.
These queries basically determine the worst case sga memory usage scenario, since this summation includes any free sga
memory above sga_target. The amount of free can be determined from prior query.
These results will show the maximum size the sga could ever be and can be used for planning purposes for determining
how much ram would be required to handle sga requirements. The pga memory usage then needs to be considered to
determine total memory usage.
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 5/10
4/12/24, 16:31 Document 1516229.1
Depending on how the OS allocates memory, not all this memory may actually be resident in physical ram. Portions of the
memory could possibly be in a virtual state on disk. You would need to use appropriate OS utilities to determine actual
physical memory usage of sga. However, it is good practice to assume majority of this sga memory will be in physical
memory due to the nature of the database and block access.
If lock_sga is set true, then all the sga memory is in physical memory. When memory_target is set, lock_sga cannot be
used.
--these two queries assume scenario of max sga size allocated in shared memory including the free
sga memory
--depending on the configuration and OS, the actual pinned/resident shared memory can only be
determined using OS commands
--If lock_sga is used you know this sga is resident in memory
select ROUND(sum(bytes)/1024/1024) as Mbytes from v$sgainfo
where name not in ('Maximum SGA Size','Startup overhead in Shared Pool','Granule Size');
Mbytes
------------
617
Mbytes
------------
597
The difference in the sum of above two queries is due to the Shared IO Pool Size currently listed in v$sgainfo and not
currently accounted for in v$sga.
The following two queries do not include the free sga memory. These queries can be used to determine the actual sga
memory currently allocated
--when memory_target is used(lock_sga cannot be used), depending on db configuration and OS, the
shared memory may be shrunk to satisfy pga requirements
--these queries show the sum of actual sga allocated which does not include free sga memory above
sga_target
--still possible not all this sga memory is resident, some in virtual
select ROUND(sum(bytes)/1024/1024) as Mbytes from v$sgastat;
Mbytes
------------
389
Mbytes
------------
409
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 6/10
4/12/24, 16:31 Document 1516229.1
Again, there is a difference in the sum of above two queries due to Shared IO Pool Size not currently accounted for in
v$sga.
The following query breaks down sga memory usage at the container level.
The query results below show container id 4 using 19M and container id 6 using 11M. The majority of sga memory usage is
used by the root container as indicated by container id 0 and 1.
CON_ID Mbytes
------ ------------
0 136
1 213
2 3
3 7
4 19
5 0
6 11
The following query breaks down sga memory usage at container level and further to individual sga components.
break on off
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 7/10
4/12/24, 16:31 Document 1516229.1
****** ------------
sum 212
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 8/10
4/12/24, 16:31 Document 1516229.1
The following query is same as above, but includes a where clause to limit the results to only larger memory allocations
over 10M.
This can be altered for even larger allocation sizes and can be used to show only the very large memory allocations in the
containers.
If you are getting sga memory errors such as ORA-4031, then this query may indicate one container using majority of
resources and could be a candidate to be moved out of the root container into its own non-container database.
The following query provides summation of sga and pga, and gives a value of total memory usage by the oracle instance.
This query should always be used when sga is locked in memory and can be used for determining memory usage with
largest possible sga allocated.
The sum on v$sga assumes scenario of max sga size allocated in shared memory by including the free sga memory.
Mbytes
------------
663
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 9/10
4/12/24, 16:31 Document 1516229.1
The following query should be used when memory_target >0
Sum on v$sgastat does not include the free sga memory available. Depending on the configuration and OS, the actual
pinned/resident shared memory can only be determined using OS commands. Use above query if you want to calculate full
sga size including free sga available.
Mbytes
------------
465
REFERENCES
NOTE:399497.1 - FAQ: ORA-4030
Didn't find what you are looking for?
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=vzl1qxid2_4&id=1516229.1 10/10