Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

DBA - Memory Structure: Program Global Area

Back


Program Global Area (PGA)

Instance_PGA


show parameter pga_aggregate_limit
show parameter PGA_aggregate_target

select value from v$parameter where name = 'pga_aggregate_limit';
select value from v$parameter where name = 'PGA_aggregate_target';

ALTER SYSTEM SET pga_aggregate_limit = 2G SCOPE=both;
ALTER SYSTEM SET PGA_AGGREGATE_TARGET = 1024M SCOPE=both;
# SCOPE=both part ensures that the change takes effect immediately and is persistent across both the current session and future sessions.

Contents of the PGA

PGA_Contents


Memory allocation

Memory Area Dedicated Server Shared Server
Nature of session memory Private Shared
persistent area PGA SGA
run-time area for DML and DDL statements PGA PGA

V$PGASTAT - PGA statistics

select name, value from v$pgastat;

pga_v$pgastat


Private SQL Area - Cursor


  Private SQL Area shared SQL area
Memory Structure PGA SGA
Store Info a parsed SQL statement + session-specific stores execution plans

run-time area


persistent area


Cursor

cursor

SHOW PARAMETER OPEN_CURSORS;
SELECT value
FROM v$parameter
WHERE name = 'open_cursors';

ALTER SYSTEM SET OPEN_CURSORS = 500 SCOPE=both;

pga_private_SQL_area_cursor


Example: Private SQL area & Cursor

DECLARE
  CURSOR c_employee (dept_id NUMBER) IS
    SELECT employee_name
    FROM employees
    WHERE department_id = dept_id;
  v_employee_name VARCHAR2(50);
  v_department_id NUMBER := 10; -- Bind Variable
BEGIN
  OPEN c_employee(v_department_id); -- Bind variable value supplied at runtime
  LOOP
    FETCH c_employee INTO v_employee_name; -- Interacts with private SQL area (run-time area)
    EXIT WHEN c_employee%NOTFOUND;
    -- Process the current row (v_employee_name)
    DBMS_OUTPUT.PUT_LINE('Employee Name: ' || v_employee_name);
  END LOOP;
  CLOSE c_employee; -- Deallocates private SQL area (run-time area) and persistent area
END;

Execution Details:


SQL Work Areas

Parameter Desc
SORT_AREA_SIZE size of the memory allocated for sorting operation
HASH_AREA_SIZE size of the memory allocated for hashing operation
# HASH_AREA_SIZE
SHOW PARAMETER HASH_AREA_SIZE;
SELECT value
FROM v$parameter
WHERE name = 'hash_area_size';
ALTER SYSTEM SET hash_area_size = <new_size> SCOPE=both;

SHOW PARAMETER SORT_AREA_SIZE;
SELECT value
FROM v$parameter
WHERE name = 'sort_area_size';
ALTER SYSTEM SET sort_area_size = <new_size> SCOPE=both;

Example

SELECT *
FROM   employees e JOIN departments d
ON     e.department_id=d.department_id
ORDER BY last_name;

/* query plan */
--------------------------------------------------------------------------------
#| Id| Operation           | Name        | Rows  | Bytes | Cost (%CPU)| Time    |
--------------------------------------------------------------------------------
#| 0 | SELECT STATEMENT    |             |   106 |  9328 |    7  (29)| 00:00:01 |
#| 1 |  SORT ORDER BY      |             |   106 |  9328 |    7  (29)| 00:00:01 |
#|*2 |   HASH JOIN         |             |   106 |  9328 |    6  (17)| 00:00:01 |
#| 3 |    TABLE ACCESS FULL| DEPARTMENTS |    27 |   540 |    2   (0)| 00:00:01 |
#| 4 |    TABLE ACCESS FULL| EMPLOYEES   |   107 |  7276 |    3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

TOP