Professional Documents
Culture Documents
Monitoring and Improving Performance
Monitoring and Improving Performance
Memory
Memory
allocation
allocation
issues
issues
Input/output
Input/output Resource
Resource
device
device contention
contention
contention
contention
?
Application
DBA Network
Application Network
code bottlenecks
bottlenecks
code
problems
problems
Performance Monitoring
To administer Oracle Database 10g and keep it running smoothly, the database
administrator must regularly monitor performance to locate bottlenecks and correct
problem areas.
There are hundreds of performance measurements the DBA can look at, covering
everything from network performance to disk input/output speed to the time spent
working on individual application operations. These performance measurements are
commonly referred to as database metrics.
• Reactive
• Proactive
– Server-generated alerts
– Automated Database Diagnostic Monitor (ADDM)
Monitoring Methodologies
The Oracle Database 10g supports both proactive and reactive monitoring. Reactive
monitoring is a response to a known or reported problem. You may begin monitoring
performance metrics in reaction to user complaints about response time, instance
failures, or errors found in the alert log.
Reactive monitoring is inevitably necessary sometimes, but your goal should be to
detect and repair problems before they affect system operation. Fixing problems before
they occur, or at least before they are widely noticed, is a proactive approach to system
maintenance.
Oracle Database 10g includes several tools that aid in proactive monitoring. Two of
these are server-generated alerts and the Automated Database Diagnostic Monitor
(ADDM). Proactive monitoring will be covered in the next lesson.
DBA
Object status:
• PL/SQL code objects
• Indexes
Unusable indexes are made valid by rebuilding them to recalculate the pointers.
Rebuilding an unusable index re-creates the index in a new location, then drops the
unusable index. This can either be done using Enterprise Manager or through SQL
commands.
ALTER INDEX HR.emp_empid_pk REBUILD;
ALTER INDEX HR.emp_empid_pk REBUILD ONLINE;
ALTER INDEX HR.email REBUILD TABLESPACE USERS;
If the TABLESPACE clause is left out, the index is rebuilt in the same tablespace where
it already exists. The REBUILD ONLINE clause allows users to continue updating the
index’s table while the rebuild takes place (without the ONLINE keyword users must
wait for the rebuild to finish before performing DML on the affected table).
Optimizer Statistics
Optimizer statistics for tables and indexes are stored in the data dictionary. These
statistics are not intended to provide real-time data. They provide the optimizer a
statistically correct snapshot of data storage and distribution which the optimizer uses to
make decisions on how to access data.
Metrics collected include:
• Size of the table or index in database blocks
• Number of rows
• Average row size and chain count (tables only)
• Height and number of deleted leaf rows (indexes only)
As data is inserted, deleted, and modified these facts change. The performance impact
of maintaining real-time data distribution statistics would be prohibitive, so these
statistics are updated by periodically gathering statistics on tables and indexes.
Optimizer statistics are collected automatically by the pre-configured
GATHER_STATS_JOB, which runs during predefined maintenance windows, once per
day.
Considerations:
• There are some general guidelines that serve as a
starting point in performance tuning
• Your situation may not fit the guideline
• Test any changes under a representative
production environment to see the affects
• There are written volumes and multi-day classes
dedicated to tuning an Oracle database
Tuning Tips
The guidelines that follow are simply that. This is not an attempt to list tuning
parameters that will fix every system's performance problems, but there are some
starting point to consider. As you work with these tips, investigate further in the Oracle
documentation and other resources, and test them on your system, you will be able gain
better understanding of how to tune your database, with your applications, with your
workload, in your environment.
Tuning Tips
The three facets of tuning involve performance planning, instance tuning, and SQL
tuning. Performance planning is the process of establishing the environment: the
hardware, software, operating system, network infrastructure, and so on. Instance tuning
is the actual adjustment of Oracle and operating system parameters to gain better
performance of the Oracle database. SQL tuning involves making your application
submit efficient SQL. This is an application-wide consideration, as well as a statement-
specific one. System-wide, you want to be sure different parts of the application are
leveraging each other's work, and are not competing for resources unnecessarily. We'll
also look at some common actions to take to tune specific SQL statements.
Note: For more information about performance tuning, please refer to the Oracle
Database Performance Tuning Guide.
• Investment Options
• System Architecture
• Scalability
• Application Design Principles
• Workload Testing, Modeling, and Implementation
• Deploying New Applications
Performance Planning
There are many facets to performance planning. You have to consider the investment in
your system architecture: the hardware and software infrastructure needed to meet your
requirements. The number of hard drives and controllers has an impact on speed of data
access. Striping data across many devices is often a way to make performance gains.
This, of course, requires analysis to determine the value for your given environment,
application, and performance requirements.
The ability of an application to scale is also important. This means you are able to
handle more and more users, clients, session, or transactions, without incurring a huge
impact on overall system performance. The most obvious violator against scalability is
serializing operations among users. If all users have to go through a single path one at a
time, then as more users are added, there will definitely be adverse affects on
performance, as more and more users line up to go through that path. Poorly written
SQL also affects scalability, requiring many users to wait for inefficient SQL to
complete, each one competing with the other on a large number of resources they should
not actually be in need of.
Principles of application design can greatly affect performance. Simplicity of design,
use of views and indexes, and data modeling are all very important.
Oracle Database 10g: Administration Workshop I 13-20
Performance Planning (continued)
Any application needs to be tested under a representative production workload. This
requires estimating database size and workload, and generating test data and system
load.
Performance must be considered as new applications, or new versions of applications,
are deployed. Sometimes design decisions are made to maintain compatibility to old
systems during the rollout. A new database should be configured specifically for the
applications it is hosting, based on the production environment.
Instance Tuning
At the start of any tuning activity it is necessary to have specific goals. A goal such as
"Process 500 sales transactions per minute" is easier to work toward than one that says
"Make it go as fast as you can, and we'll know when it's good enough."
You have to allocate Oracle memory suitably for your application to attain optimum
performance. You have a finite amount of memory to work with, and too little allotted
to certain parts of the Oracle database can cause inefficient background activity that you
may not even be aware of without doing some analysis.
Disk I/O is often the bottleneck of a database, and so requires a lot of attention at the
outset of any database implementation.
The operating system configuration can also affect the performance of an Oracle
database. See the Oracle Database Installation Guide for your particular platform for
more information.
SGA
Database
buffer cache
Streams pool Redo log
buffer
Shared pool
Java pool
SGA_TARGET = 8G
What is the optimal allocation?
STATISTICS_LEVEL = TYPICAL
Tuning I/O
A common cause of hot spots on a disk comes from insert-heavy applications, where
there is an index with keys that are very close in value to each other as they are inserted.
Examples of this are dates and sequences, or values that are based on some combination
of those. In these cases, all of the write activity for the index is in the same area of disk
because the key values are close, and get put in the same area of the index structure.
This can often be resolved by using a reverse key index, which reverses the bytes of the
index, causing the storage location in the index to be very different even for integers that
are one value apart.
If your log files are not large enough to handle the redo generated by the database, then
it's possible the system is frequently waiting for a switch to a new redo log. When one
fills, a different one must be activated. During that change in active log file, nothing can
be written to the redo log. If this happens too often, it could be affecting performance. A
typical goal for the redo log switch interval is roughly 20 minutes.
If you segregate redo log files and/or archived redo log files onto separate disks, this
may relieve I/O contention.
Tuning SQL
The SQL Tuning Advisor analyzes individual SQL statements and makes
recommendations for improving their performance.
The Query Optimizer analyzes each SQL statement and determines the most efficient
path to the data. This involves, among other things, determining what index to use, or
even if it is worthwhile to use an index.
Using an index is probably the most common solution to quickly accessing data in a
table. As described in Lesson 6, in their most basic form, indexes store key values
paired with pointers to data rows. This usually enables faster access to the data row,
because indexes are smaller and can be read through much more quickly than large
tables. They are also organized in a way that enables very fast key lookup. So, queries
that search a large table for a key value benefit greatly from an index. It is the Query
Optimizer's job to determine whether the index should be used though. If an index is not
being used, there may very well be a good reason for it.
Tuning Recommendations
The SQL Tuning Advisor is able to provide recommendations for improving the
performance of a SQL statement. In this example, where a statement was searching on
the OBJECT_ID column, it is noted that an index on that column may help.
SQL Statistics
The SQL Tuning Advisor also shows you the statistics a cursor that represents an SQL
statement. By viewing statistics for each of these two cursors, you can see that each of
them cause a hard parse of the statement. This means the statement was not found to be
a match in the Library Cache. This is because of the use of literals instead of bind
variables.
Bind variable
candidates