Database/Oracle Database

[오라클] 메모리 관리 - PGA

Dong538 2022. 1. 13. 16:41

PGA 영역은 크게 세가지로 나눌 수 있습니다. SQL 워크 영역, UGA영역, 프라이빗 SQL 영역

 

SQL Work Area: 
- 비트맵 생성 영역: 비트맵 인덱스 사용 시 사용하는 비트맵 인덱스 생성 영역.
- 비트맵 병합 영역: 비트맵 인덱스를 이용하여 실행을 분석한 후, 비트맵을 병합해야 하는 경우 사용하는 영역. where 조건에서 or 연산자를 사용하는 경우 2개의 비트 값을 비교해야 하므로 비트맵 병합이 발생한다.
- 정렬 공간: ORDER BY, GROUP BY 정렬을 수행하기 위한 공간. 메모리 공간 부족 시 디스크에 구성되는 임시 테이블스페이스를 이용
- 해시 공간: 조인 방식 중 하나인 해시 조인의 해시 영역을 생성하는 공간

 

UGA:
- 세션 메모리: 서버 프로세스에 의해 추출된 결과 값 전달하기 위해 필요한 유저 프로세스의 세션 정보를 저장

 

Private SQL Area:
- 영구 영역: 바인드 변수 값을 저장. 런타임 시 해당 변수가 SQL문에 제공된다. SQL 문장이 완료될 때마다 영구 영역은 해제된다. 
- 런타임 영역: 쿼리 실행 상태 정보를 저장한다. DML 문의 경우 SQL 문 완료시마다 런타임 영역도 해제된다. 


시스템 측면에서 PGA의 파라미터와 관련된 내용을 확인해보겠습니다. 

 

- V$PGASTAT: 활성화된 경우(즉, PGA_AGGREGATE_TARGET이 설정된 경우) PGA 메모리 사용 통계와 자동 PGA 메모리 관리자에 대한 통계를 표시합니다. V$PGASTAT의 누적 값은 인스턴스 시작 이후 누적됩니다.

SQL> select * from v$pgastat;

NAME                                          VALUE UNIT             CON_ID
---------------------------------------- ---------- ------------ ----------
aggregate PGA target parameter            486539264 bytes                 0
aggregate PGA auto target                 251458560 bytes                 0
global memory bound                        97307648 bytes                 0
total PGA inuse                           207138816 bytes                 0
total PGA allocated                       261968896 bytes                 0
maximum PGA allocated                     265346048 bytes                 0
total freeable PGA memory                  21889024 bytes                 0
MGA allocated (under PGA)                         0 bytes                 0
maximum MGA allocated                             0 bytes                 0
process count                                    54                       0
max processes count                              55                       0
PGA memory freed back to OS                 6094848 bytes                 0
total PGA used for auto workareas                 0 bytes                 0
maximum PGA used for auto workareas               0 bytes                 0
total PGA used for manual workareas               0 bytes                 0
maximum PGA used for manual workareas             0 bytes                 0
over allocation count                             0                       0
bytes processed                            34999296 bytes                 0
extra bytes read/written                          0 bytes                 0
cache hit percentage                            100 percent               0
recompute count (total)                          35                       0

21 rows selected.

참고: https://docs.oracle.com/cd/E18283_01/server.112/e17110/dynviews_2096.htm

 

V$PGASTAT

V$PGASTAT V$PGASTAT displays PGA memory usage statistics as well as statistics about the automatic PGA memory manager when it is enabled (that is, when PGA_AGGREGATE_TARGET is set). Cumulative values in V$PGASTAT are accumulated since instance startup. Col

docs.oracle.com

select name, round(value/1024/1024) "value",
case unit when 'bytes' then 'M' END "unit" from v$pgastat
where unit = 'bytes'
union
select name, value, unit from v$pgastat
where unit != 'bytes'
union
select name, value, unit from v$pgastat
  9  where unit is null;

NAME                                          value unit
---------------------------------------- ---------- ------------
MGA allocated (under PGA)                         0 M
PGA memory freed back to OS                       6 M
aggregate PGA auto target                       234 M
aggregate PGA target parameter                  464 M
bytes processed                                  35 M
cache hit percentage                            100 percent
extra bytes read/written                          0 M
global memory bound                              93 M
max processes count                              59
maximum MGA allocated                             0 M
maximum PGA allocated                           264 M
maximum PGA used for auto workareas               0 M
maximum PGA used for manual workareas             0 M
over allocation count                             0
process count                                    57
recompute count (total)                         400
total PGA allocated                             254 M
total PGA inuse                                 204 M
total PGA used for auto workareas                 0 M
total PGA used for manual workareas               0 M
total freeable PGA memory                        18 M

21 rows selected.

오라클은 기본적으로 인스턴스 PGA 전용 메모리의 총량을 자동으로 그리고 전역적으로 관리합니다. 위 쿼리에서 파라미터 PGA_AGGREGATE_TARGET을 설정하여 이 양을 제어(인스턴스에 할당 + 미할당 포함한 크기)할 수 있습니다.

total PGA allocated는 인스턴스에서 할당한 현재 PGA 메모리 양입니다. Oracle 데이터베이스는 이 숫자를 PGA_AGGREGATE_TARGET 파라미터 값 아래로 유지하려고 시도합니다. 그러나 작업 영역 워크로드가 매우 빠르게 증가하거나 PGA_AGGREGATE_TARGET이 작은 값으로 설정된 경우 할당된 PGA가 해당 값을 짧은 시간 동안 작은 비율로 초과는 가능합니다.


work area 메모리의 할당 및 사용 통계는 다음 동적 성능 뷰에서 볼 수 있습니다:

V$SYSSTAT
V$SESSTAT
V$PGASTAT
V$SQL_WORKAREA
V$SQL_WORKAREA_ACTIVE

 

V$PROCESS 뷰의 다음 세 컬럼은 Oracle Database 프로세스에서 할당 및 사용하는 PGA 메모리를 보고합니다.:PGA_USED_MEM
PGA_ALLOC_MEM
PGA_MAX_MEM

select
round(sum(pga_used_mem)/1024/1024) "pga_used_mem/MB" ,
round(sum(pga_alloc_mem)/1024/1024) "pga_alloc_mem/MB",
round(sum(pga_max_mem)/1024/1024) "pga_max_mem/MB"
from v$process;

pga_used_mem/MB pga_alloc_mem/MB pga_max_mem/MB
--------------- ---------------- --------------
            207              259            264

 

PGA 메모리 사용량을 target으로 제한하려고 하지만 사용량이 때때로 설정을 초과할 수 있습니다. PGA 메모리 사용에 대한 hard limit을 지정하려면 PGA_AGGREGATE_LIMIT 파라미터를 사용하십시오. Oracle Database는 PGA 크기가 이 제한을 초과하지 않도록 합니다. 데이터베이스가 제한을 초과하면 데이터베이스는 조정할 수 없는(untunable) PGA 메모리 할당이 가장 높은 세션의 호출을 종료합니다. 자동 메모리 관리 사용 여부에 관계없이 PGA_AGGREGATE_LIMIT를 설정할 수 있습니다. PGA_AGGREGATE_LIMIT가 설정되지 않은 경우 Oracle Database는 적절한 기본 제한을 결정합니다. 

 

Oracle Database 10g 이전 릴리스에서 데이터베이스 관리자는 SORT_AREA_SIZE, HASH_AREA_SIZE, BITMAP_MERGE_AREA_SIZE 및 CREATE_BITMAP_AREA_SIZE 매개변수를 설정하여 SQL 작업 영역의 최대 크기를 제어했습니다. 최대 작업 영역 크기는 데이터 입력 크기와 시스템에서 활성화된 총 작업 영역 수에서 이상적으로 선택되기 때문에 이러한 매개변수를 설정하는 것은 어렵습니다. 이 두 가지 요소는 작업 영역과 시간에 따라 크게 다릅니다. 따라서 다양한 *_AREA_SIZE 매개변수는 최상의 상황에서 조정하기 어렵습니다.

이러한 이유로 Oracle은 자동 PGA 메모리 관리를 활성화된 상태로 둘 것을 강력히 권장합니다.

SQL 작업 영역을 수동으로 조정하려면 WORKAREA_SIZE_POLICY 초기화 매개변수를 MANUAL로 설정해야 합니다.


메모리 관리에 대한 정보를 제공하는 동적 성능 뷰:

V$SGA

V$SGAINFO

V$SGASTAT

V$PGASTAT

V$MEMORY_DYNAMIC_COMPONENTS

V$SGA_DYNAMIC_COMPONENTS

V$SGA_DYNAMIC_FREE_MEMORY

V$MEMORY_CURRENT_RESIZE_OPS

V$SGA_CURRENT_RESIZE_OPS

V$MEMORY_RESIZE_OPS

V$SGA_RESIZE_OPS

V$MEMORY_TARGET_ADVICE

V$SGA_TARGET_ADVICE

V$PGA_TARGET_ADVICE

V$IM_SEGMENTS

 

참고: https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/managing-memory.html#GUID-2D28DBE2-1CA8-484E-A1CF-3280F939D009

 

Database Administrator’s Guide

Memory management involves maintaining optimal sizes for the Oracle Database instance memory structures as demands on the database change.

docs.oracle.com