Optimize Sort Operations

Introduction As a DBA, you are responsible to optimize sort operations of your organization’s database in case of performance problems. Your job’s responsibilities dictate that you should be aware of the following basic fundamental subjects: Monitoring a sort statement operation Optimizing a sort statement operation Using the V$SYSSTAT view SORTS (DISK) SORTS (MEMORY) Calculating the sort Ratio SORT_AREA_SIZE PGA_AGGREGATE_TARGET Increasing the SORT_AREA_SIZE parameter Hands-on In this exercise, you will learn how to monitor and optimize sort operations. Now, connect to SQLPlus as the SYSTEM/MANAGER user. SQL> CONNECT system/manager AS SYSDBA Sorting process The Oracle Server Processes will sort as much as they can in the memory sort area before using any disk sort space. Sort performed destination (Memory vs. Disk) Now, query the V$SYSSTAT view to track the number of in-memory and to-disk sorts, as well as the total number of rows sorted. SQL> SELECT name, value FROM v$sysstat WHERE name like 'sorts%' / Notice that the sorts (disk) number must be very low, and the sorts (memory) number can be as high as possible. The ‘sorts (memory)’ value is a number of times that Oracle tables were sorted in the memory. The ‘sorts (disk)’ value is a number of times that Oracle tables were sorted on the disk using the TEMPORARY tablespace. Sort HIT Ratio (Memory vs. Disk) Now, determine the sort ratio of the in-memory vs. to-disk sorts. SQL> SELECT 100*(a.value-b.value)/(a.value) AS "Sort Ratio" FROM v$sysstat a, v$sysstat b WHERE a.name = 'sorts (memory)' AND b.name ='sorts (disk)' / Notice that the sort ratio should be greater than 95%. If you are not using the automatic PGA memory and the number is less than 95 percent, you should greatly consider increasing the value

If you are using the automatic PGA memory and the number is less than 95 percent. the database needs to be restarted.of the SORT_AREA_SIZE parameter. SQL> CONNECT system/manager AS SYSDBA SQL> STARTUP . Increase sort area in memory Try to increase the SORT_AREA_SIZE parameter to 819200 bytes. SQL> ALTER SYSTEM SET sort_area_size=819200 SCOPE=spfile / In order for the change to take effect. SQL> SHUTDOWN IMMEDIATE. you should greatly consider increasing the value of the PGA_AGGREGATE_TARGET parameter. Shutdown and startup the database in order to see the changes.

Sign up to vote on this title
UsefulNot useful