Upload
gabriel-reynold-murphy
View
245
Download
2
Embed Size (px)
Citation preview
Copyright © 2006, Oracle. All rights reserved.13-2
Objectives
After completing this lesson, you should be able to do the following:
• Diagnose PGA memory issues
• Size the PGA memory
• Diagnose temporary space issues
• Specify temporary tablespace parameters for efficient operation
Copyright © 2006, Oracle. All rights reserved.13-3
SQL Memory Usage
• Memory-intensive SQL operators:– Sort-based (sort, group-by, rollup, window, ...)– Hash-join– Bitmap operators (merge and inversion)
• Concept of work area:– Memory allocated by a memory-intensive operator
to process its input data
• Performance impact of memory:– Optimal: Input data fits into the work area (cache).– One-pass: Perform one extra pass over input data.– Multi-pass: Perform several extra passes over input
data.
Copyright © 2006, Oracle. All rights reserved.13-4
Performance Impact
Response Time
Memory
..
1-pass optimalM-pass
Sort
Response Time
..Hash-Join
M1-pass Moptimal
M1-pass
Moptimal
1-pass optimalM-passMemory
Copyright © 2006, Oracle. All rights reserved.13-5
Automatic PGA Memory
• Dynamically adapts the SQL memory allocation based on:– PGA memory available
– SQL operator needs
– System workload
• Improves manageability:– No need to set *_AREA_SIZE parameters
– DBA sets a memory target: PGA_AGGREGATE_TARGET
• Improves performance:– PGA memory is really returned to the OS.
– Memory is allocated to the operation to maximize throughput.
– Maximize overall memory utilization by dynamically adapting memory with workload variation.
– Operation adapts its memory usage during the execution.
Copyright © 2006, Oracle. All rights reserved.13-6
SQL Memory Manager
...
HJ
GB
HJ
WP1
Lo
cal SM
M
HJ
GB
WP5
Server-1
Server-n
SGA
Globalmemorybound Global SMM (CKPT)
AggregatePGA
auto-target
Memory BoundComputation
every 3sWP2
Lo
cal SM
M
WP3
WP4
V$SQL_WORKAREA_ACTIVE
V$SQL_WORKAREA
PGA MemoryUsage
Statistics
PGA_AGGREGATE_TARGET
V$PROCESSV$PROCESS_MEMORY
V$PGASTAT
WP5
WP2
WP1
V$PGASTAT
Auto-TargetComputation
WP3
WP4
Copyright © 2006, Oracle. All rights reserved.13-8
Configuring Automatic PGA Memory
• PGA_AGGREGATE_TARGET:– Specifies the target aggregate amount of PGA
memory available to the instance– Can be dynamically modified at the instance level– Examples: 100,000 KB; 2,500 MB; 50 GB– Default value: 10 MB or 20% of the size of the SGA,
whichever is greater
• WORKAREA_SIZE_POLICY:– Optional– Can be dynamically modified at the instance or
session level– Allows you to fall back to static SQL memory
management for a particular session
Copyright © 2006, Oracle. All rights reserved.13-9
Setting PGA_AGGREGATE_TARGET Initially
• Leave 20% of the available memory to other applications.
• Leave 80% of memory to the Oracle instance.
• For OLTP:
• For DSS:
PGA_AGGREGATE_TARGET=(total_mem*80%)*20%
PGA_AGGREGATE_TARGET=(total_mem*80%)*50%
Copyright © 2006, Oracle. All rights reserved.13-10
Monitoring SQL Memory Usage
V$SQL_WORKAREA_ACTIVE
V$SQL_WORKAREAV$PGASTAT
V$SQL_PLANV$SQL
V$SQL_WORKAREA_HISTOGRAMS
V$PROCESS_MEMORY
V$SYSSTATV$TEMPSEG_USAGE
Copyright © 2006, Oracle. All rights reserved.13-12
Monitoring SQL Memory Usage: Examples
SELECT sql_text, sum(onepass_executions) onepass_cnt, sum(multipasses_executions) mpass_cntFROM V$SQL s, V$SQL_WORKAREA wa WHERE s.address = wa.addressGROUP BY sql_textHAVING sum(onepass_executions+multipasses_executions)>0;
SELECT TO_NUMBER(DECODE(sid, 65535, NULL, sid)) sid, operation_type OPERATION, TRUNC(expected_size/1024) ESIZE, TRUNC(actual_mem_used/1024) MEM, TRUNC(max_mem_used/1024) MAXMEM, number_passes PASS, TRUNC(tempseg_size/1024) TSIZEFROM V$SQL_WORKAREA_ACTIVEORDER BY 1,2;
1
2
Copyright © 2006, Oracle. All rights reserved.13-13
Tuning SQL Memory Usage
• Determine the best PGA_AGGREGATE_TARGET value by using:– V$PGA_TARGET_ADVICE– V$PGA_TARGET_ADVICE_HISTOGRAM
• Monitor AWR reports/Statspack reports for:– direct path read temp– direct path write temp
Copyright © 2006, Oracle. All rights reserved.13-14
PGA Target Advice Statistics
• V$PGA_TARGET_ADVICE predicts how cache hit percentages shown in V$PGASTAT evolve.
• STATISTICS_LEVEL must be set to at least TYPICAL.
V$PGA_TARGET_ADVICE
13%
25%
50%
75%
100%
120%
140%
160%
180%
200%
300%
400%
PGA_TARGET_FACTORESTD_PGA_CACHE_HIT_PERCENTAGE
CurrentvalueO
ve
r a
llo
ca
tio
nzo
ne
Goodvalue
ESTD_OVERALLOC_COUNT
0102030405060708090100
Copyright © 2006, Oracle. All rights reserved.13-15
PGA Target Advice Histograms
• V$PGA_TARGET_ADVICE_HISTOGRAM predicts how histograms shown in V$SQL_WORKAREA_HISTOGRAM evolve.
• STATISTICS_LEVEL must be set to at least TYPICAL.
Copyright © 2006, Oracle. All rights reserved.13-18
Temporary Tablespace Management: Overview
• Temporary data generated by a database include:– Bitmap merges– Hash-join– Bitmap index creation– Sort– Temporary LOBs– Global temporary tables
• Data persists for the duration of a transaction or session.
• High concurrency of the space management operation is critical.
• Media and instance recovery is not required.
Copyright © 2006, Oracle. All rights reserved.13-19
Temporary Tablespace: Best Practice
Using locally managed temporary tablespace:
• Allows high-concurrency space management– At steady state, all space metadata is cached in
SGA.– Operations are serialized by the SGA latch.
• Allows faster writes to temp files. Redo generated on temporary blocks is not written to disk.
• Makes READ ONLY databases possible
Copyright © 2006, Oracle. All rights reserved.13-20
Configuring Temporary Tablespace
• Locally managed temporary tablespaces are uniform-extent tablespaces.
• 1 MB to 10 MB extent size:– For DSS, OLAP applications involving huge work
areas– Large temporary LOBs are predominant.
• 64 KB or multiple less than 1 MB:– Small global temporary tables are predominant.– OLTP
• Use V$TEMPSEG_USAGE to monitor space usage and workload distribution.
Copyright © 2006, Oracle. All rights reserved.13-22
Temporary Tablespace Group: Overview
• Groups multiple temporary tablespaces
• Characteristics:– At least one temporary tablespace– Same namespace as tablespaces– Created implicitly on first assignment– No explicit deletion
Default tablespace
EXAMPLE …
Default temporary tablespace group TEMP
Tablespace
TEMP1
Tablespace
TEMPn
Copyright © 2006, Oracle. All rights reserved.13-23
Temporary Tablespace Group: Benefits
Enables a user to use multiple temporary tablespaces:
• Same user in multiple sessions
• One particular parallel operation
Temporary tablespace group TEMP
Tablespace
TEMP1
Tablespace
TEMP2
Tablespace
TEMP3
SerialParallelHR
HR
Copyright © 2006, Oracle. All rights reserved.13-26
Data Dictionary Changes
SELECT group_name, tablespace_nameFROM DBA_TABLESPACE_GROUPS;
Copyright © 2006, Oracle. All rights reserved.13-27
Monitoring Temporary Tablespace
• Use V$TEMPSEG_USAGE to monitor space usage and workload distribution:
•
• Use V$SORT_SEGMENT to determine space usage percentage:
SELECT session_num, username, segtype, blocks, tablespaceFROM V$TEMPSEG_USAGE;
SELECT (s.tot_used_blocks/f.total_blocks)*100 as pctusedFROM (SELECT SUM(used_blocks) tot_used_blocks FROM V$SORT_SEGMENT WHERE tablespace_name='TEMP') s, (SELECT SUM(blocks) total_blocks FROM DBA_TEMP_FILES WHERE tablespace_name='TEMP') f;
Copyright © 2006, Oracle. All rights reserved.13-28
Practice Overview: Tune PGA Memory
This practice covers the following topics:
• Enable Automatic PGA Memory
• Tune PGA_AGGREGATE_TARGET• Tune Temporary Tablespace Performance