Les 13 Memory

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

Managing Memory

Copyright © 2009, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to:


• Describe the memory components in the SGA
• Implement Automatic Memory Management
• Manually configure SGA parameters
• Configure automatic PGA memory management

13 - 2 Copyright © 2009, Oracle. All rights reserved.


Memory Management: Overview

DBAs must consider memory management to be a crucial part


of their job because:
• There is a finite amount of memory available
• Allocating more memory to serve certain types of functions
can improve overall performance
• Automatically tuned memory allocation is often the
appropriate configuration, but specific environments or
even short-term conditions may require further attention

13 - 3 Copyright © 2009, Oracle. All rights reserved.


Reviewing Oracle Database Memory Structures

Stack User Stack User


space Global space Global
Area Area
Server Server
process 1 Program Global Area (PGA) process 2 PGA

Keep
Database buffer pool
Redo log
Shared pool buffer
buffer
cache Recycle
buffer pool

Java pool Streams nK buffer


Large pool pool cache

System Global Area (SGA)

13 - 4 Copyright © 2009, Oracle. All rights reserved.


Buffer Cache
• Pinned
• Clean
• Free/unused
SGA • Dirty

Server LRU Checkpoint


lists queue DB buffer cache

. .
. .
. .
. .

DB_BLOCK_SIZE
DB_CACHE_SIZE

DBWn

Data files

13 - 6 Copyright © 2009, Oracle. All rights reserved.


Using Multiple Buffer Pools

SGA
DB buffer caches
Recycle pool
DB_RECYCLE_CACHE_SIZE

Keep pool
DB_KEEP_CACHE_SIZE

Default pool
DB_CACHE_SIZE

13 - 8 Copyright © 2009, Oracle. All rights reserved.


Using Multiple Buffer Pools

CREATE INDEX cust_idx …


STORAGE (BUFFER_POOL KEEP);

ALTER TABLE oe.customers


STORAGE (BUFFER_POOL RECYCLE);

ALTER INDEX oe.cust_lname_ix


STORAGE (BUFFER_POOL KEEP);

13 - 9 Copyright © 2009, Oracle. All rights reserved.


Shared Pool

Contents:
• Library cache: Command text, parsed code, and execution
plan
• Data dictionary cache: Definitions for tables, columns, and
privileges from the data dictionary tables
• Result cache: Results from SQL queries and PL/SQL
functions
• User Global Area (UGA): Shared Data dictionary
SQL area cache
Session information for the
Oracle shared server Result cache

Library UGA
cache

SHARED_POOL_SIZE Shared pool


SGA

13 - 10 Copyright © 2009, Oracle. All rights reserved.


Large Pool

• Provides large memory allocations for:


– Session memory for the shared server and the Oracle XA
interface
– I/O server processes
– Oracle Database backup and restore operations
– Parallel query operations
– Advanced Queuing memory table storage
• Reduces potential fragmentation of shared pool
• Is managed by AMM and ASMM
• Is sized with the parameter

13 - 11 Copyright © 2009, Oracle. All rights reserved.


Java Pool and Streams Pool

• Java pool memory is used in server memory for all


session-specific Java code and data in the JVM.
• Streams pool memory is used exclusively by Oracle
Streams to:
– Store buffered queue messages
– Provide memory for Oracle Streams processes

Keep
Database buffer pool
Redo log
Shared pool buffer
buffer
cache Recycle
buffer pool

Java pool Streams nK buffer


Large pool pool cache

Java pool System Global Area (SGA) Streams pool

13 - 12 Copyright © 2009, Oracle. All rights reserved.


Redo Log Buffer

• Is a circular buffer in the SGA


• Holds information about changes made to the database
• Contains redo entries that have the information to redo
changes made by operations such as DML and DDL
Content transferred by log writer process (LGWR):
– When a user process commits a transaction
– When the redo log buffer is one-third full
– Before a n process writes modified buffers to disk

LGWR

Redo log buffer LogWriter process Redo log files

13 - 13 Copyright © 2009, Oracle. All rights reserved.


Automatic Memory Management: Overview

With Automatic Memory Management, the database can size


the SGA and PGA automatically according to your workload.
11g 11g
350 MB 350 MB
Memory Memory
Max Target Max Target

300 MB
Memory Target

250 MB
Memory Target

ALTER SYSTEM SET


MEMORY_TARGET=300M;

Oracle recommends the use of AMM unless you have special requirements.

13 - 14 Copyright © 2009, Oracle. All rights reserved.


Oracle Database Memory Parameters

MEMORY_MAX_TARGET

SGA_MAX_SIZE MEMORY_TARGET This enables AMM.

SGA_TARGET PGA_AGGREGATE_TARGET
–This enables ASMM.
–Changing
Child parameters:
affects only automatically • Providing minimum values
sized components. Others
• Automatic change of size only
LOG_BUFFER with autotuned parameters
SHARED_POOL_SIZE RESULT_CACHE_SIZE
DB_CACHE_SIZE
LARGE_POOL_SIZE DB_KEEP_CACHE_SIZE
JAVA_POOL_SIZE DB_RECYCLE_CACHE_SIZE
STREAMS_POOL_SIZE DB_nK_CACHE_SIZE

13 - 15 Copyright © 2009, Oracle. All rights reserved.


Monitoring Automatic Memory Management

13 - 16 Copyright © 2009, Oracle. All rights reserved.


Monitoring Automatic Memory Management

If you want to monitor the decisions made by Automatic


Memory Management via a command line:
• has the current status
of all memory components
• has a circular history buffer of
the last 800 memory resize requests
• provides tuning advice for
the initialization parameter

13 - 17 Copyright © 2009, Oracle. All rights reserved.


Efficient Memory Usage: Guidelines

• Fit the SGA into physical memory.


• Tune for a high buffer cache hit ratio, with the following
caveats:
– Even valid and necessary full table scans lower it.
– It is possible that unnecessary repeated reads of the same
blocks are artificially raising it.
• Use the Memory Advisors.

13 - 18 Copyright © 2009, Oracle. All rights reserved.


Memory Tuning Guidelines for the Library Cache

• Establish formatting conventions for developers so that


SQL statements match in the cache.
• Use bind variables.
• Eliminate unnecessary duplicate SQL.
• Consider using .
• Use PL/SQL when possible.
• Cache sequence numbers.
• Pin objects in the library cache.

13 - 20 Copyright © 2009, Oracle. All rights reserved.


Automatic Shared Memory Management:
Overview
• Automatically adapts to workload changes
• Maximizes memory utilization
• Helps eliminate out-of-memory errors

Buffer cache
Buffer cache

Example: Large pool


Large pool

Shared pool Shared pool

Java pool Java pool


Streams pool Streams pool
Online users Batch jobs

13 - 22 Copyright © 2009, Oracle. All rights reserved.


How ASMM Works

• ASMM is based on workload information that


captures in the background.
• uses memory advisors.
• Memory is moved to where it is needed the most by .
• If an SPFILE is used (which is recommended):
– Component sizes are saved across shutdowns
– Saved values are used to bootstrap component sizes
– There is no need to relearn optimal values

13 - 23 Copyright © 2009, Oracle. All rights reserved.


Enabling Automatic Shared Memory Management

To enable ASMM from manual shared memory management:


1. Get a value for SGA_TARGET:
SELECT ((SELECT SUM(value) FROM V$SGA) - (SELECT CURRENT_SIZE
FROM V$SGA_DYNAMIC_FREE_MEMORY)) "SGA_TARGET" FROM DUAL;

2. Use that value to set SGA_TARGET.


3. Set the values of the automatically sized SGA components
to 0.
To switch to ASMM from Automatic Memory Management:
1. Set the MEMORY_TARGET initialization parameter to 0.
2. Set the values of the automatically sized SGA components
to 0.

13 - 24 Copyright © 2009, Oracle. All rights reserved.


Disabling ASMM

• Setting to 0 disables autotuning.


• Autotuned parameters are set to their current sizes.
• The SGA size as a whole is unaffected.

SGA size = 8 GB SGA size = 8 GB


Parameters:
sga_target = 0
Parameters: db_cache_size = 5G
sga_target = 8G shared_pool_size = 2G
shared_pool_size = 1G large_pool_size = 512M
java_pool_size = 256M
Original values
streams_pool_size = 256M

13 - 25 Copyright © 2009, Oracle. All rights reserved.


Program Global Area (PGA)

Server Private Cursor


PGA Session Work
process
SQL and SQL
memory area
areas area
Dedicated
connections PGA

Shared
PGA
server Shared pool
or PGA
Shared server large pool
connections

Automatic PGA memory management is enabled by default.

13 - 26 Copyright © 2009, Oracle. All rights reserved.


Using the V$PARAMETER View

SGA_TARGET = 8G

DB_CACHE_SIZE = 0
JAVA_POOL_SIZE = 0
LARGE_POOL_SIZE = 0
SHARED_POOL_SIZE = 0
STREAMS_POOL_SIZE = 0

SELECT name, value, isdefault


FROM v$parameter
WHERE name LIKE '%size';

13 - 28 Copyright © 2009, Oracle. All rights reserved.


Quiz

For best performance, you should enable both Automatic


Memory Management (AMM) and Automatic Shared Memory
Management (ASMM) by setting the and the
parameters.
1. True
2. False

13 - 29 Copyright © 2009, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


• Describe the memory components in the SGA
• Implement Automatic Memory Management
• Manually configure SGA parameters
• Use automatic PGA memory management

13 - 30 Copyright © 2009, Oracle. All rights reserved.


Practice 13 Overview: Using AMM to Correct a
Memory Allocation Problem
This practice covers the following topics:
• Diagnosing a memory allocation problem
• Enabling and implementing Automatic Memory
Management

13 - 31 Copyright © 2009, Oracle. All rights reserved.

You might also like