Professional Documents
Culture Documents
Practice 25 - Tuning The PGA
Practice 25 - Tuning The PGA
Practice 25
Practice Target
In this practice, you will perform the following:
• Obtain information about PGA performance
Caution: Do not proceed with performing the practice without taking snapshot first.
2. Start Putty and connect to srv1 as oracle. In the rest of this practice, this session will be
referred to as admin window.
Note: Unless stated otherwise, all the steps in this practice should be run in the admin window.
Note:
In the following steps, you will create multiple script files. If you want to save your time and create
all those scripts in one go, find the attached file pga_practice_scripts.txt file. Copy/paste its
contents into the Putty window.
The script displays the private work area statistics at the system level.
cat > display_wa_exec.sql <<EOL
set linesize 180
col NAME for a40
col VALUE for 999,999,999
EOL
SELECT NAME,
DECODE(UNIT,'bytes',TO_CHAR(ROUND(VALUE/1024/1024,2)),VALUE) VALUE,
DECODE(UNIT,'bytes','MB',UNIT) UNIT
FROM V\$PGASTAT;
EOL
EOL
EOL
EOL
SELECT
Q.PARSING_SCHEMA_NAME USERNAME,
SUBSTR(Q.SQL_TEXT,1,20) SQL_TEXT,
W.OPERATION_TYPE,
TRUNC(W.ESTIMATED_OPTIMAL_SIZE/1024,2) EST_OPTIMAL_SIZE,
TRUNC(LAST_MEMORY_USED/1024,2) MEM_USED,
TRUNC(MAX_TEMPSEG_SIZE/1024,2) MAX_TEMP_SIZE
FROM V\$SQL_WORKAREA W, V\$SQL Q
WHERE W.ADDRESS = Q.ADDRESS
AND Q.PARSING_SCHEMA_NAME NOT IN ('SYS','ORACLE_OCM','GSMADMIN_INTERNAL')
ORDER BY LAST_MEMORY_USED DESC
FETCH FIRST 10 ROWS ONLY;
EOL
EOL
10. In the hosting PC, open a command prompt window and start Swingbench.
D:
cd D:\swingbench\winbin
set PATH=D:\oracle\product\12.1.0\client_1\jdk\jre\bin;%PATH%
swingbench.bat
11. In Swingbench, open the warehouse.xml configuration file then Start Benchmark button.
12. In the Putty window, invoke SQL*Plus and login to ORADB as sysdba.
sqlplus / as sysdba
14. Display the instance-level statistics on the cursor work areas and sort operations.
In a healthy system, we should not see 'workarea executions – multipass' operations.
'sorts (disk)' should not have high value in an OLTP environment.
@ display_wa_exec.sql
16. Display the work area execution statistics grouped by size ranges (buckets).
Most of the executions were in two size ranges.
Note: The statistics are gathered since instance startup.
@ display_wa_histo.sql
17. Display the active work area PGA statistics for each cursor.
Observe the following from the output:
o 'Number of Passes' is zero for all the sessions. Which is a sign of a healthy PGA condition.
o No session has wanted to save anything in the temporary tablespace.
o 'V$SQL_WORKAREA_ACTIVE' displays statistics about active work areas only. When the
statement of cursor finishes its execution, it disappears from the view.
@ display_active_wa.sql
18. Display the active work area PGA statistics aggregated by the operation type.
Most of the work area sizes are needed for sort operations.
@ display_active_wa_agg.sql
19. Display the work area PGA statistics for each cursor.
V$SQL_WORKAREA view contains statistics about the cursors that finished their executions.
Note: The script displays the top 10 cursors only.
@ display_wa_stats.sql
20. Start another Putty session and connect to srv1 as oracle. Invoke SQL*Plus and login to ORADB
as soe. In the rest of this practice, this session will be referred to as the client window.
sqlplus soe/soe
22. In the client window, run the following query. Use a hint to distinguish the query from the other
statements submitted to the database.
The query retrieves and orders only 100 rows.
set linesize 180
SELECT /*+ SQLID: 1 */
ORDER_ID, ORDER_TOTAL
FROM ORDERS
WHERE ORDER_ID BETWEEN 10000 AND 10100
ORDER BY 2;
23. In the admin window, display the work area statistics on the executed query.
All the workarea executions were optimal, no sorts in the disk.
@ display_sess_stats.sql
24. In the client window, run the following query. The query retrieves and orders 39000 rows.
SELECT /*+ SQLID: 2 */
ORDER_ID, ORDER_TOTAL
FROM ORDERS
WHERE ORDER_ID BETWEEN 10000 AND 400000
ORDER BY 2;
25. In the admin window, display the work area statistics on the executed query.
All the work area executions were optimal, no sorts in the disk.
/
27. In the client window, reduce the sort area size of the session to a small size (160204 bytes for
example).
To make the changes of the work area sort size take effect, we must set the
WORKAREA_SIZE_POLICY to MANUAL.
28. In the client window, run the following query. The query retrieves the same rows retrieved by
the last query. Only the hint is different.
SELECT /*+ SQLID: 3 */
ORDER_ID, ORDER_TOTAL
FROM ORDERS
WHERE ORDER_ID BETWEEN 10000 AND 400000
ORDER BY 2;
29. In the admin window, display the work area statistics on the executed query.
'sorts (disk)' is incremented.
@ display_sess_stats.sql
36. Run the following query to obtain details from the PGA memory advisory. Determine from the
output the optimal PGA size.
Clean up
37. Stop the Swingbench sessions.
40. Restore srv1 from the snapshot taken in the beginning of the practice
42. (optional) Delete the generated AWR report files from the staging folder
Summary
• V$SQL_WORKAREA shows statistics about work areas of SQL cursors that finished their executions.
• Oracle database may allocate more size for the PGA than the size set by the
PGA_AGGREGATE_TARGET, if need be.