Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 4 ■ MEMORY STRUCTURES 117 sort is done. The SORT_AREA_SIZE-SORT_AREA_RETAINED_SIZE is generally allocated out of your PGA, and the SORT_AREA_RETAINED_SIZE will be in your UGA. You can discover your current usage of PGA and UGA memory and monitor its size by querying special Oracle V$ views, also referred to as dynamic performance views. For example, let’s run a small test whereby in one session we’ll sort lots of data and, from a second session, we’ll monitor the UGA/PGA memory usage in that first session. To do this in a predicable manner, we’ll make a copy of the ALL_OBJECTS table, with about 45,000 rows in this case, without any indexes (so we know a sort has to happen): ops$tkyte@ORA10G> create table t as select * from all_objects; Table created. ops$tkyte@ORA10G> exec dbms_stats.gather_table_stats( user, 'T' ); PL/SQL procedure successfully completed. To remove any side effects from the initial hard parsing of queries, we’ll run the following script, but for now ignore its output. We’ll run the script again in a fresh session so as to see the effects on memory usage in a controlled environment. We’ll use the sort area sizes of 64KB, 1MB, and 1GB in turn: create table t as select * from all_objects; exec dbms_stats.gather_table_stats( user, 'T' ); alter session set workarea_size_policy=manual; alter session set sort_area_size = 65536; set termout off select * from t order by 1, 2, 3, 4; set termout on alter session set sort_area_size=1048576; set termout off select * from t order by 1, 2, 3, 4; set termout on alter session set sort_area_size=1073741820; set termout off select * from t order by 1, 2, 3, 4; set termout on ■Note When we process SQL in the database, we must first “parse” the SQL statement. There are two types of parses available. The first is a hard parse, which is what happens the first time a query is parsed by the database instance and includes query plan generation and optimization. The second is a soft parse, which can skip many of the steps a hard parse must do. We hard parse the previous queries so as to not measure the work performed by that operation in the following section. Now, I would suggest logging out of that SQL*Plus session and logging back in before continuing, in order to get a consistent environment, or one in which no work has been done yet.
118 CHAPTER 4 ■ MEMORY STRUCTURES To ensure we’re using manual memory management, we’ll set it specifically and specify our rather small sort area size of 64KB. Also, we’ll identify our session ID (SID) so we can monitor the memory usage for that session. ops$tkyte@ORA10G> alter session set workarea_size_policy=manual; Session altered. ops$tkyte@ORA10G> select sid from v$mystat where rownum = 1; SID ---------- 151 Now, we need to measure SID 151’s memory from a second separate session. If we used the same session, then our query to see how much memory we are using for sorting might itself influence the very numbers we are looking at. To measure the memory from this second session, we’ll use a small SQL*Plus script I developed for this. It is actually a pair of scripts. The one we want to watch that resets a small table and sets a SQL*Plus variable to the SID is called reset_stat.sql: drop table sess_stats; create table sess_stats ( name varchar2(64), value number, diff number ); variable sid number exec :sid := &1 ■Note Before using this script (or any script, for that matter), make sure you understand what the script does. This script is dropping and re-creating a table called SESS_STATS. If your schema already has such a table, you’ll probably want to use a different name! The other script is called watch_stat.sql, and for this case study, it uses the MERGE SQL statement so we can initially INSERT the statistic values for a session and then later come back and update them—without needing a separate INSERT/UPDATE script: merge into sess_stats using ( select a.name, b.value from v$statname a, v$sesstat b where a.statistic# = b.statistic# and b.sid = :sid and (a.name like '%ga %' or a.name like '%direct temp%') ) curr_stats
- Page 112 and 113: CHAPTER 3 ■ FILES 67 Without a pa
- Page 114 and 115: CHAPTER 3 ■ FILES 69 and even dat
- Page 116 and 117: CHAPTER 3 ■ FILES 71 all operatio
- Page 118 and 119: CHAPTER 3 ■ FILES 73 *.cluster_da
- Page 120 and 121: CHAPTER 3 ■ FILES 75 ops$tkyte@OR
- Page 122 and 123: CHAPTER 3 ■ FILES 77 • To maint
- Page 124 and 125: CHAPTER 3 ■ FILES 79 • Resource
- Page 126 and 127: CHAPTER 3 ■ FILES 81 3 l_dummy nu
- Page 128 and 129: CHAPTER 3 ■ FILES 83 Trace Files
- Page 130 and 131: CHAPTER 3 ■ FILES 85 _qerixAlloca
- Page 132 and 133: CHAPTER 3 ■ FILES 87 6 ( 7 TYPE O
- Page 134 and 135: CHAPTER 3 ■ FILES 89 A Brief Revi
- Page 136 and 137: CHAPTER 3 ■ FILES 91 Redundant Ar
- Page 138 and 139: CHAPTER 3 ■ FILES 93 (data from m
- Page 140 and 141: CHAPTER 3 ■ FILES 95 dictionary t
- Page 142 and 143: CHAPTER 3 ■ FILES 97 ■Note df i
- Page 144 and 145: CHAPTER 3 ■ FILES 99 “accidenta
- Page 146 and 147: CHAPTER 3 ■ FILES 101 So, at the
- Page 148 and 149: CHAPTER 3 ■ FILES 103 Password Fi
- Page 150 and 151: CHAPTER 3 ■ FILES 105 USER is "SY
- Page 152 and 153: CHAPTER 3 ■ FILES 107 Flashback L
- Page 154 and 155: CHAPTER 3 ■ FILES 109 of the requ
- Page 156 and 157: CHAPTER 3 ■ FILES 111 IMPDP, howe
- Page 158 and 159: CHAPTER 3 ■ FILES 113 tkyte@ORA10
- Page 160 and 161: CHAPTER 4 ■ ■ ■ Memory Struct
- Page 164 and 165: CHAPTER 4 ■ MEMORY STRUCTURES 119
- Page 166 and 167: CHAPTER 4 ■ MEMORY STRUCTURES 121
- Page 168 and 169: CHAPTER 4 ■ MEMORY STRUCTURES 123
- Page 170 and 171: CHAPTER 4 ■ MEMORY STRUCTURES 125
- Page 172 and 173: CHAPTER 4 ■ MEMORY STRUCTURES 127
- Page 174 and 175: CHAPTER 4 ■ MEMORY STRUCTURES 129
- Page 176 and 177: CHAPTER 4 ■ MEMORY STRUCTURES 131
- Page 178 and 179: CHAPTER 4 ■ MEMORY STRUCTURES 133
- Page 180 and 181: CHAPTER 4 ■ MEMORY STRUCTURES 135
- Page 182 and 183: CHAPTER 4 ■ MEMORY STRUCTURES 137
- Page 184 and 185: CHAPTER 4 ■ MEMORY STRUCTURES 139
- Page 186 and 187: CHAPTER 4 ■ MEMORY STRUCTURES 141
- Page 188 and 189: CHAPTER 4 ■ MEMORY STRUCTURES 143
- Page 190 and 191: CHAPTER 4 ■ MEMORY STRUCTURES 145
- Page 192 and 193: CHAPTER 4 ■ MEMORY STRUCTURES 147
- Page 194 and 195: CHAPTER 4 ■ MEMORY STRUCTURES 149
- Page 196 and 197: CHAPTER 4 ■ MEMORY STRUCTURES 151
- Page 198 and 199: CHAPTER 4 ■ MEMORY STRUCTURES 153
- Page 200 and 201: CHAPTER 5 ■ ■ ■ Oracle Proces
- Page 202 and 203: CHAPTER 5 ■ ORACLE PROCESSES 157
- Page 204 and 205: CHAPTER 5 ■ ORACLE PROCESSES 159
- Page 206 and 207: CHAPTER 5 ■ ORACLE PROCESSES 161
- Page 208 and 209: CHAPTER 5 ■ ORACLE PROCESSES 163
- Page 210 and 211: CHAPTER 5 ■ ORACLE PROCESSES 165
CHAPTER 4 ■ MEMORY STRUCTURES 117<br />
sort is done. The SORT_AREA_SIZE-SORT_AREA_RETAINED_SIZE is generally allocated out of your<br />
PGA, <strong>and</strong> the SORT_AREA_RETAINED_SIZE will be in your UGA. You can discover your current<br />
usage of PGA <strong>and</strong> UGA memory <strong>and</strong> monitor its size by querying special <strong>Oracle</strong> V$ views, also<br />
referred to as dynamic performance views.<br />
For example, let’s run a small test whereby in one session we’ll sort lots of data <strong>and</strong>, from a<br />
second session, we’ll monitor the UGA/PGA memory usage in that first session. To do this in a<br />
predicable manner, we’ll make a copy of the ALL_OBJECTS table, with about 45,000 rows in this<br />
case, without any indexes (so we know a sort has to happen):<br />
ops$tkyte@ORA10G> create table t as select * from all_objects;<br />
Table created.<br />
ops$tkyte@ORA10G> exec dbms_stats.gather_table_stats( user, 'T' );<br />
PL/SQL procedure successfully completed.<br />
To remove any side effects from the initial hard parsing of queries, we’ll run the following<br />
script, but for now ignore its output. We’ll run the script again in a fresh session so as to see<br />
the effects on memory usage in a controlled environment. We’ll use the sort area sizes of 64KB,<br />
1MB, <strong>and</strong> 1GB in turn:<br />
create table t as select * from all_objects;<br />
exec dbms_stats.gather_table_stats( user, 'T' );<br />
alter session set workarea_size_policy=manual;<br />
alter session set sort_area_size = 65536;<br />
set termout off<br />
select * from t order by 1, 2, 3, 4;<br />
set termout on<br />
alter session set sort_area_size=1048576;<br />
set termout off<br />
select * from t order by 1, 2, 3, 4;<br />
set termout on<br />
alter session set sort_area_size=1073741820;<br />
set termout off<br />
select * from t order by 1, 2, 3, 4;<br />
set termout on<br />
■Note When we process SQL in the database, we must first “parse” the SQL statement. There are two<br />
types of parses available. The first is a hard parse, which is what happens the first time a query is parsed<br />
by the database instance <strong>and</strong> includes query plan generation <strong>and</strong> optimization. The second is a soft parse,<br />
which can skip many of the steps a hard parse must do. We hard parse the previous queries so as to not<br />
measure the work performed by that operation in the following section.<br />
Now, I would suggest logging out of that SQL*Plus session <strong>and</strong> logging back in before continuing,<br />
in order to get a consistent environment, or one in which no work has been done yet.