05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

126<br />

CHAPTER 4 ■ MEMORY STRUCTURES<br />

or a.name like '%direct temp%')<br />

<strong>and</strong> b.sid = c.sid<br />

<strong>and</strong> c.username is not null<br />

group by 'total: ' || a.name<br />

) curr_stats<br />

on (sess_stats.name = curr_stats.name)<br />

when matched then<br />

update set diff = curr_stats.value - sess_stats.value,<br />

value = curr_stats.value<br />

when not matched then<br />

insert ( name, value, diff )<br />

values<br />

( curr_stats.name, curr_stats.value, null )<br />

/<br />

I simply added the UNION ALL section to capture the total PGA/UGA <strong>and</strong> sort writes by<br />

summing over all sessions, in addition to the statistics for a single session. I then ran the following<br />

SQL*Plus script in that particular session. The table BIG_TABLE had been created<br />

beforeh<strong>and</strong> with 50,000 rows in it. I dropped the primary key from this table, so all that<br />

remained was the table itself (ensuring that a sort process would have to be performed):<br />

set autotrace traceonly statistics;<br />

select * from big_table order by 1, 2, 3, 4;<br />

set autotrace off<br />

■Note The BIG_TABLE table is created as a copy of ALL_OBJECTS with a primary key, <strong>and</strong> it can have as<br />

many or as few rows as you like. The big_table.sql script is documented in the “Setting Up” section at<br />

the beginning of this book.<br />

Now, I ran that small query script against a database with a PGA_AGGREGATE_TARGET of<br />

256MB, meaning I wanted <strong>Oracle</strong> to use up to about 256MB of PGA memory for sorting. I set<br />

up another script to be run in other sessions to generate a large sorting load on the machine.<br />

This script loops <strong>and</strong> uses a built-in package, DBMS_ALERT, to see if it should continue processing.<br />

If it should, it runs the same big query, sorting the entire BIG_TABLE table. When the<br />

simulation was over, a session could signal all of the sorting processes, the load generators,<br />

to “stop” <strong>and</strong> exit. The script used to perform the sort is as follows:<br />

declare<br />

l_msg long;<br />

l_status number;<br />

begin<br />

dbms_alert.register( 'WAITING' );<br />

for i in 1 .. 999999 loop<br />

dbms_application_info.set_client_info( i );<br />

dbms_alert.waitone( 'WAITING', l_msg, l_status, 0 );

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!