Onitoring AND Uning Racle: Hapter ART
Onitoring AND Uning Racle: Hapter ART
TUNING ORACLE -
CHAPTER 22 PART 1
This material is extracted from the first half of Chapter 22 of Configuring and Tuning
Databases on the Solaris Platform, by Allan N. Packer, (c) 2002, Sun Microsystems
Press. The second half of the chapter will appear in the August edition of Sun Blue-
Prints Online. Chapter 21, Drill-Down Monitoring of Database Servers, was presented
in the June 2002 edition of Sun BluePrints Online.
1
2 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
Before Oracle7.3, the sqldba command was used as shown in the follow-
ing example based on Oracle7.1.3.
1.oracle8 svrmgrl
The same effect can be achieved with a single command, as shown in the
following example based on Oracle9.0.1.
M an a gi n g O r ac l e Be h a v io r 3
Some sites also use a config.ora file, referenced from init.ora with the
ifile parameter, to store static parameters such as db_name and
db_block_size.
File created.
The default scope is both if the database was started with an spfile, and
memory if it was not.
A parameter can be returned to its system default value with the following
statement:
You can create an init.ora file from an spfile with the following com-
mand:
create pfile=’$ORACLE_HOME/dbs/backup_initaccts.ora
from spfile=’$ORACLE_HOME/dbs/spfileaccts.ora’
The file names can be eliminated if default names are used for init.ora
and spfile.
Finally, the current active parameters can be viewed with the show
parameters statement or by querying the v$parameter view (or the
v$parameter2 view). The v$spparameter view displays the current con-
tents of the spfile, or NULL values if the spfile is not in use.
The isdefault column shows whether the current value for this parame-
ter is the default (true or false). Note that similar information can be
6 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
obtained from Oracle7, although that release only provides the x$ksppi view,
and not the x$ksppcv view.
On the book website (http://www.solarisdatabases.com) I have included a
script called _params that simplifies this process for Oracle8 and later
releases. If run with no parameters, it displays all hidden parameters. If a
string is passed to the script, it displays all hidden parameters matching the
string.
v$ Views
Oracle’s internal views have names starting with v$. Although they appear to
be tables, they are actually internal memory structures that are not persis-
tent—that is, they only exist while the instance is active.
M an a gi n g O r ac l e Be h a v io r 7
SQL> @?/rdbms/admin/spreport
Table created.
9 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (ORDER BY)
2 1 TABLE ACCESS (FULL) OF ’TPCD’
Statistics
----------------------------------------------------------
203 recursive calls
4 db block gets
58 consistent gets
17 physical reads
60 redo size
894 bytes sent via SQL*Net to client
715 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
9 rows processed
10 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
Explain plans can also be generated with the utlxplan script. This
method, which also works with earlier versions of Oracle, is illustrated below.
Once again, if the plan_table has not already been created, you will need to
run the utlxplan.sql script, as shown.
SQL> @$ORACLE_HOME/rdbms/admin/utlxplan
Table created.
Explained.
SQL> select
2 LPAD(’ ’,2*Level)||
3 Operation||’ ’||Options||’ ’||
4 decode(Object_Owner,NULL,’’,
5 Object_Owner||’. ’||Object_Name)||’ ’||
6 decode(Optimizer,NULL,’’,Optimizer)
7 Q_Plan
8 from PLAN_TABLE
9 connect by prior ID = Parent_ID and Statement_ID =’TEST’
10 start with ID = 0 and Statement_ID = ’TEST’;
Q_PLAN
------------------------------------------------------------
SELECT STATEMENT RULE
SORT ORDER BY
NESTED LOOPS
TABLE ACCESS FULL GL. GL_JE_HEADERS ANALYZED
TABLE ACCESS BY ROWID GL. GL_JE_LINES ANALYZED
INDEX UNIQUE SCAN GL. GL_JE_LINES_U1 ANALYZED
6 rows selected.
Note that the first statement, which runs the utlxplan script, only needs
to be run once (it creates the PLAN_TABLE table).
As of Oracle 7.2, the select statement above can be enhanced as follows:
select
LPAD(’ ’,2*Level)||
M an a gi n g O r ac l e Be h a v io r 11
Figure 2 shows the formula for calculating the cache hit rate for the
Oracle8.1.5 and Oracle8.1.6 releases.
For Oracle8.1.7 and Oracle9i, use the formula shown in Figure 3 to calcu-
late the buffer cache hit rate.
1 – ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
physicalreads – physicalreadsdirect – physicalreadsdirectLOB × 100
( dbblockgets + consistentgets – physicalreadsdirect – physicalreadsdirectLOB )
11 rows selected.
User Connections
The next section of the report deals with database connections.
SQL> column “Statistic” format a27 trunc;
SQL> column “Per Transaction” heading “Per Transact”;
SQL> column ((start_users+end_users)/2) heading “((START_USER”
SQL> set numwidth 12;
SQL> Rem The total is the total value of the statistic between the time
SQL> Rem bstat was run and the time estat was run. Note that the estat
SQL> Rem script logs on to the instance so the per_logon statistics will
SQL> Rem always be based on at least one logon.
SQL> select ‘Users connected at ‘,to_char(start_time, ‘dd-mon-yy
hh24:mi:ss’),’:’,start_users from stats$dates;
‘AVG#OFCONNECTIONS:’ ((START_USER
--------------------- ------------
avg # of connections: 41
M o n i t or i n g O r ac le w i t h u t l bs t a t / u t l e s t at 15
The number of connections at the start and end of the monitoring period
and the average number of connections all help track user connectivity. Note
that connections do not necessarily equate to users, though, since some users
may have more than one connection and administrative scripts (including the
one used to create this report) also count as connections. Conversely, transac-
tion monitors allow multiple users to share a single connection.
The duration of the monitoring period is also shown at the end of the
report. In this case it was almost exactly 30 minutes.
Database Statistics
The statistics below include some of the most important measures to be moni-
tored. If you examine the SQL command that generated these results, you
will notice that only statistics with non-zero values are reported. Conse-
quently, if you run utlbstat/utlestat again later, you might find that new
rows appear in this section of the report and other rows may have disap-
peared.
Statistic Per
Total Transact Per Logon Per Second
----------------------- --------- -------- --------- ----------
CR blocks created 11909 .04 290.46 6.64
Cached Commit SCN reference 158232 .49 3859.32 88.2
DBWR buffers scanned 590396 1.82 14399.9 329.09
DBWR checkpoint buffers wri 704570 2.18 17184.63 392.74
DBWR checkpoints 2 0 .05 0
DBWR free buffers found 402083 1.24 9806.9 224.13
DBWR lru scans 22320 .07 544.39 12.44
DBWR make free requests 22320 .07 544.39 12.44
DBWR summed scan depth 590396 1.82 14399.9 329.09
DBWR transaction table writ 68 0 1.66 .04
DBWR undo block writes 32991 .1 804.66 18.39
16 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
Note that four sets of values are reported for each statistic:
• Total. This value shows the total number of events of this type during
the monitoring interval.
• Per Transaction. This column is normalized according to the number
of user commits (you will notice a value of 1 for that row). Note that
the rate of user commits can provide an alternate measure of applica-
tion workload in the absence of higher-level information about business
transactions (such as the number of invoices processed during a speci-
fied period of time).
• Per Logon. Normalizing the statistic according to the number of logons
(user connections) can help in predicting the impact of changing the
number of users and user connections. Bear in mind, though, that
logged-on connections may not all be active.
18 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
• Per Second. This value helps put the totals in perspective. For exam-
ple, the I/O capability of a disk is usually expressed in I/Os per second,
so knowing that 935,315 physical writes were completed is not as useful
as knowing that on average 521 physical writes were completed per sec-
ond. Early versions of Oracle did not include this useful column.
help resolve a problem of this type. In this case, dirty buffers have been
found 24 times a second, or on average for one in eight transactions, sug-
gesting that the number of Database Writers could be usefully
increased.
• redo log space requests. This statistic measures the number of
times shadow processes stalled waiting for log file space. A common
myth is that the statistic reports the number of times a process stalls
during commits because there was not enough room in the log buffer.
Stalls can occur during checkpoints.
• sorts (disk) and sorts (memory). The first of these statistics mea-
sures the number of sorts that spill to the temporary tablespace because
they could not fit in the memory allocated by the sort_area_size
parameter in init.ora. The second statistic shows the number of sorts
that were able to complete in memory without resorting to the tempo-
rary tablespace. The report above shows 857 sorts to disk over a 30-
minute period compared to 71,791 sorts in memory. So just over 1% of
all sorts spilled to disk, at a rate of less than one per minute. There is
little reason to increase sort_area_size in this case.
• table scans (short tables) and table scans (long tables). The
first of these statistics shows the number of table scans carried out on
short tables (less than or equal to 5 blocks in length) or on tables that
have been flagged as cached.
Tables can be specified as cached when the table is created, or later with
the alter table command from sqlplus (for example, alter table
customer cache;). Normally, blocks read during a full table scan are
marked as least recently used, and the space they consume is quickly
reclaimed. By contrast, blocks read from cached tables during a table
scan are treated as most recently used blocks. Caching small, heavily
accessed tables can improve performance in some cases.
The second statistic shows the number of table scans on larger tables
(none appeared in the report). Large table scans should be avoided in
OLTP environments since they impact overall system performance and
lower the buffer cache hit rate. Creating appropriate indexes or modify-
ing the application can overcome the problem.
11 rows selected.
SQL> Rem System wide wait events for background processes (PMON,SMON,etc)
SQL> select n1.event “Event Name”,
2 n1.event_count “Count”,
3 n1.time_waited “Total Time”,
4 round(n1.time_waited/n1.event_count, 2) “Avg Time”
5 from stats$bck_event n1
6 where n1.event_count > 0
7 order by n1.time_waited desc;
Event Name Count Total Time Avg Time
-------------------------------- ------------- ------------- ------------
rdbms ipc message 331631 779378 2.35
db file parallel write 229188 603152 2.63
pmon timer 597 175435 293.86
smon timer 5 150002 30000.4
log file parallel write 186846 80079 .43
db file scattered read 377 2168 5.75
control file parallel write 613 1021 1.67
latch free 155 248 1.6
LGWR wait for redo copy 747 142 .19
control file sequential read 96 101 1.05
async disk IO 100 63 .63
db file sequential read 7 10 1.43
log file single write 4 4 1
direct path read 94 2 .02
log file sequential read 2 1 .5
direct path write 94 0 0
16 rows selected.
M o n i t or i n g O r ac le w i t h u t l bs t a t / u t l e s t at 21
The SQL*Net message from client wait event simply means that the
shadow process is waiting for the client to do something. Consequently, sub-
stantial wait times for this event do not usually indicate a problem (unless
the waits are due to network delays). The converse event, SQL*Net message
to client, shows the delay when shadow processes send messages to cli-
ents; large delays could indicate network problems.
Wait events that should be monitored include those in the following list:
• free buffer waits. A lot of time spent waiting for free buffers sug-
gests that the Database Writers are not flushing dirty buffers fast
enough to keep up with demand. This event does not appear in the
report above, but if it should appear as a major wait event, try increas-
ing the db_writer_processes parameter in init.ora.
• buffer busy waits. Buffer busy waits occur when shadow processes
were unable to access a buffer because it was in use by another process.
The report above shows a tiny number of waits of this type.
If buffer busy waits are one of the top wait events in terms of percent-
age of time waited, check the v$waitstat view to find out what type of
blocks are affected (this information is also presented later in
report.txt, in “Buffer Busy Wait Statistics” on page 27).
You can also check the v$session_wait view to find out the file ID (the
P1 column) and the block ID (the P2 column) of the affected block. The
file ID can be used to query the dba_extents view (you will need to add
a where file_id = n clause, where n is the file ID from the
v$session_wait view) to get the details of the segment that the block
ID falls within.
Each data block supports a limited number of concurrent accesses for
update or delete operations; a table with a large number of rows per
block and high concurrency can experience frequent buffer busy wait
events as a result. The INITRANS parameter determines the number of
concurrent accesses (the default is 1 for tables and 2 for indexes). If the
segment identified in v$session_wait belongs to a table or index, you
could increase the INITRANS storage parameter. The INITRANS param-
eter can only be set during table or index creation, so it may be neces-
sary to drop and recreate the table or index.
For tables subject to high insert concurrency, increase the FREELISTS
storage parameter to improve performance if the buffer busy wait
events are related to inserts. The FREELISTS parameter also must be
specified at create time.
• enqueues. Although this wait event appears in the report above, the
number of events and wait time do not suggest a problem. If enqueue
waits represent a high proportion of the time spent waiting, you can try
to identify the enqueue waited for. Oracle9i provides a view—
v$enqueue_stat—for this purpose; see statspack for more informa-
tion before Oracle9i. Enqueue waits are a symptom of some other prob-
lem.
22 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1
39 rows selected.
No-Wait Latches
The remainder of this section of the report deals with no-wait latches. It is
followed by suggestions on latch monitoring.
SQL> set numwidth 16
SQL> Rem Statistics on no_wait gets of latches. A no_wait get does not
SQL> Rem wait for the latch to become free, it immediately times out.
SQL> select name latch_name,
2 immed_gets nowait_gets,
3 immed_miss nowait_misses,
4 round((immed_gets/(immed_gets+immed_miss)), 3)
5 nowait_hit_ratio
6 from stats$latches
7 where immed_gets + immed_miss != 0
8 order by name;
The hit_ratio should be close to 1. The following list indicates the main
latches to monitor:
• cache buffers chains. When searching for a block in the cache, a
shadow process uses a hashing algorithm to find the appropriate hash
bucket and then follows a hash chain to scan for the block. Fewer hash
buckets means longer hash chains, more searching, and higher conten-
tion on the cache buffers chains latch. Inefficient SQL statements,
such as heavily accessed statements using indexes that are not highly
selective, can cause high contention for this latch.
Identify the scale of any potential problem with the following SQL (for
Oracle8 and later releases) as sysdba:
select count(*) from x$bh;
select dbarfil “File”, dbablk “Block”, count(*)
from x$bh group by dbafil, dbablk
having count(*) > 1;
• cache buffers lru chains. This latch protects the LRU chain. High
contention could indicate that the Database Writers are not operating
efficiently, for example, due to a slow or overloaded I/O subsystem.
• library cache. A number of factors contribute to high library cache
latch contention. Sometimes you can alleviate the contention simply by
increasing the size of the shared pool (the shared_pool_size parame-
ter in init.ora). Other changes that might be necessary to relieve
library cache contention include those in the following list:
• Keep large SQL statements into the shared pool (with the
dbms_shared_pool.keep procedure).
• Use bind variables to reduce SQL statement parsing. For example,
the following two statements are parsed and stored independently
in the shared pool, even though they are almost identical:
select cust_name from customer
where cust_id = 12345;
select cust_name from customer
where cust_id = 23456;
Use of bind variables reduces latch contention and also reduces the
pressure on free space in the shared pool.
• Fully qualify object names. For example, use:
select * from accts.customer;
M o n i t or i n g O r ac le w i t h u t l bs t a t / u t l e s t at 25
rather than:
select * from customer;
• Flush the shared pool if fragmentation occurs (run the alter
system flush shared_pool command as sysdba). Fragmenta-
tion problems are typically accompanied by the ORA-4031 error
message: More shared memory is needed than was allocated
in the shared pool. Note that flushing the shared pool provides
short-term relief at the cost of a short-term performance hit but
does not solve the problem. The previous suggestions should pro-
vide longer-term solutions.
• redo copy. If the hit ratio is low for the redo copy latch, it may be
possible to reduce the contention by increasing the number of redo
copy latches with the hidden _log_simultaneous_copies parame-
ter in init.ora. Normally this parameter is based on the number of
CPUs on the system. Do not change this parameter in Oracle9i. For
more information on hidden parameters, including caveats, refer to
“Viewing and Changing Hidden Parameters” on page 5.
The second half of Chapter 22 will appear in the August edition of Sun BluePrints
Online. The chapter is extracted from Configuring and Tuning Databases on the
Solaris Platform, by Allan N. Packer, (c) 2002, Sun Microsystems Press.
26 M on it o r in g an d Tu n in g O r ac l e - Ch ap t er 2 2 P ar t 1