05.11.2015 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

134<br />

CHAPTER 4 ■ MEMORY STRUCTURES<br />

a 50MB sort area size might be reasonable for the single user logged in. However, at<br />

12:00 pm with 500 users, 50MB might not be appropriate. This is where the WORKAREA_SIZE_<br />

POLICY = AUTO setting <strong>and</strong> the corresponding PGA_AGGREGATE_TARGET come in h<strong>and</strong>y. Setting the<br />

PGA_AGGREGATE_TARGET, the amount of memory you would like <strong>Oracle</strong> to feel free to use to sort<br />

<strong>and</strong> hash, is conceptually easier than trying to figure out the perfect SORT|HASH_AREA_SIZE,<br />

especially since there isn’t a perfect value for these parameters; the perfect value varies by<br />

workload.<br />

Historically, the DBA configured the amount of memory used by <strong>Oracle</strong> by setting the<br />

size of the SGA (the buffer cache; the log buffer; <strong>and</strong> the Shared, Large, <strong>and</strong> Java pools). The<br />

remaining memory on the machine would then be used by the dedicated or shared servers in<br />

the PGA region. The DBA had little control over how much of this memory would or would not<br />

be used. She could set the SORT_AREA_SIZE, but if there were 10 concurrent sorts, then <strong>Oracle</strong><br />

could use as much as 10 * SORT_AREA_SIZE bytes of RAM. If there were 100 concurrent sorts,<br />

then <strong>Oracle</strong> would use 100 * SORT_AREA_SIZE bytes; for 1,000 concurrent sorts, 1,000 *<br />

SORT_AREA_SIZE; <strong>and</strong> so on. Couple that with the fact that other things go into the PGA, <strong>and</strong><br />

you really don’t have good control over the maximal use of PGA memory on the system.<br />

What you would like to have happen is for this memory to be used differently as the<br />

memory dem<strong>and</strong>s on the system grow <strong>and</strong> shrink. The more users, the less RAM each should<br />

use. The fewer users, the more RAM each should use. Setting WORKAREA_SIZE_POLICY = AUTO is<br />

just such a way to achieve this. The DBA specifies a single size now, the PGA_AGGREGATE_TARGET<br />

or the maximum amount of PGA memory that the database should strive to use. <strong>Oracle</strong> will<br />

distribute this memory over the active sessions as it sees fit. Further, with <strong>Oracle</strong>9i Release 2<br />

<strong>and</strong> up, there is even PGA advisory (part of Statspack, available via a V$ dynamic performance<br />

view <strong>and</strong> visible in Enterprise Manager), much like the buffer cache advisor. It will tell you<br />

over time what the optimal PGA_AGGREGATE_TARGET for your system is to minimize physical I/O<br />

to your temporary tablespaces. You can use this information to either dynamically change the<br />

PGA size online (if you have sufficient RAM) or decide whether you might need more RAM on<br />

your server to achieve optimal performance.<br />

Are there times, however, when you won’t want to use it? Absolutely, <strong>and</strong> fortunately they<br />

seem to be the exception <strong>and</strong> not the rule. The automatic memory management was designed<br />

to be multiuser “fair.” In anticipation of additional users joining the system, the automatic<br />

memory management will limit the amount of memory allocated as a percentage of the<br />

PGA_AGGREGATE_TARGET. But what happens when you don’t want to be fair, when you know<br />

that you should get all of the memory available? Well, that would be the time to use the ALTER<br />

SESSION comm<strong>and</strong> to disable automatic memory management in your session (leaving it in<br />

place for all others) <strong>and</strong> to manually set your SORT|HASH_AREA_SIZE as needed. For example,<br />

that large batch process that takes place at 2:00 am <strong>and</strong> does tremendously large hash joins,<br />

some index builds, <strong>and</strong> the like? It should be permitted to use all of the resources on the<br />

machine. It does not want to be “fair” about memory use—it wants it all, as it knows it is the<br />

only thing happening in the database right now. That batch job can certainly issue the ALTER<br />

SESSION comm<strong>and</strong>s <strong>and</strong> make use of all resources available.<br />

So, in short, I prefer to use automatic PGA memory management for end user sessions—<br />

for the applications that run day to day against my database. Manual memory management<br />

makes sense for large batch jobs that run during time periods when they are the only activities<br />

in the database.

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

Saved successfully!

Ooh no, something went wrong!