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.

118<br />

CHAPTER 4 ■ MEMORY STRUCTURES<br />

To ensure we’re using manual memory management, we’ll set it specifically <strong>and</strong> specify our<br />

rather small sort area size of 64KB. Also, we’ll identify our session ID (SID) so we can monitor<br />

the memory usage for that session.<br />

ops$tkyte@ORA10G> alter session set workarea_size_policy=manual;<br />

Session altered.<br />

ops$tkyte@ORA10G> select sid from v$mystat where rownum = 1;<br />

SID<br />

----------<br />

151<br />

Now, we need to measure SID 151’s memory from a second separate session. If we used<br />

the same session, then our query to see how much memory we are using for sorting might<br />

itself influence the very numbers we are looking at. To measure the memory from this second<br />

session, we’ll use a small SQL*Plus script I developed for this. It is actually a pair of scripts. The<br />

one we want to watch that resets a small table <strong>and</strong> sets a SQL*Plus variable to the SID is called<br />

reset_stat.sql:<br />

drop table sess_stats;<br />

create table sess_stats<br />

( name varchar2(64), value number, diff number );<br />

variable sid number<br />

exec :sid := &1<br />

■Note Before using this script (or any script, for that matter), make sure you underst<strong>and</strong> what the script<br />

does. This script is dropping <strong>and</strong> re-creating a table called SESS_STATS. If your schema already has such a<br />

table, you’ll probably want to use a different name!<br />

The other script is called watch_stat.sql, <strong>and</strong> for this case study, it uses the MERGE SQL<br />

statement so we can initially INSERT the statistic values for a session <strong>and</strong> then later come back<br />

<strong>and</strong> update them—without needing a separate INSERT/UPDATE script:<br />

merge into sess_stats<br />

using<br />

(<br />

select a.name, b.value<br />

from v$statname a, v$sesstat b<br />

where a.statistic# = b.statistic#<br />

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

<strong>and</strong> (a.name like '%ga %'<br />

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

) curr_stats

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

Saved successfully!

Ooh no, something went wrong!