View
221
Download
0
Tags:
Embed Size (px)
Citation preview
Harvard University
Oracle Database Administration
Session 12
Performance
Harvard University
Performance
Wholistic view System level Database level Application level
Harvard University
Performance Tuning
Trade-offs Between Response Time and Throughput
Goals for tuning vary, depending on the needs of the application
OLTP applications define performance in terms of throughput
Decision Support Systems define performance in terms of response time
Harvard University
Performance Definition
Response time = service time + wait time We can increase performance two ways:
– by reducing service time – by reducing wait time.
Harvard University
Performance Definition
System throughput equals the amount of work accomplished in a given amount of time
Two techniques of increasing throughput exist– Get more work done with the same resources
(reduce service time)– Get the work done quicker by reducing overall
response time (reduce wait time)
Harvard University
Performance Definition
The service time for a task may stay the same, but wait time increases as contention increases
If many users are waiting for a service that takes 1 second, then the tenth user must wait 9 seconds for a service that takes 1 second
Harvard University
Critical Resources
Resources such as CPUs, memory, I/O capacity, and network bandwidth are key to reducing service time
Adding resources can give higher throughput and swifter response times
Harvard University
Areas of Interest System
– Memory– CPU– Disk
Database– Layout– Init.ora
Application– Sql– Most resource expensive sql statements
Harvard University
Areas of Interest
Network– Sql*net– Network structure
Harvard University
Percentage Gain
Application 75% to 90% gain Database 10% to 15% gain System 5% to 10% gain Network Less than 5% gain
Harvard University
The Role of the DBA
The DBA mostly works on database tuning
Enabling the developers improve their code
Improving Application Architecture
Harvard University
System Tools Top Vmstat Sar Mpstat
Harvard University
System Tools
dmesg – message file. Can be used to get information on the CPU, the memory, etc.
prtconf – system configuration psrinfo – Info about the processors sysdef – current system definition
Harvard University
System Tools
Prtdiag - System Configuration Prstat – Similar to TOP Netstat – Network Configuration
Most commands located in /usr/sbin on a Solaris system
Harvard University
Top
Overall view of the system Use of Averages
AIX– Topas– nmon
Harvard University
Sar - System Activity Reporter
Sar examples– Sar -d 2 5 disk usage– Sar –g 2 5 paging– Sar –q 2 5 queue length
man sar
Harvard University
SAR
sar [ -aAbcdgkmpqruvwy ] [ -o filename ] t [ n ]
n intervals of t seconds, where t should be 5 or greater
-o filename, this option puts the output in a file, for latter use
Harvard University
Vmstat - Virtual Memory Statistics
Virtual memory is all physical memory and allocated swap space
vmstat looks at the system and reports statistics kept about a process, virtual memory, disk and CPU activity.
Without options, vmstat displays a one-line summary of the virtual memory activity since the system was booted.
Harvard University
Vmstat
vmstat [ -cisS ] [ disks ] [ interval [ count ] ] Vmstat 5 5 Vmstat –S to get swapping information
Harvard University
Mpstat - Reports Processor Statistics
Mpstat 5 5 mpstat reports processor statistics in tabular
form Each row of the table represents the activity
of one processor
Harvard University
Block Size
Use the largest block size possible for a DDS or data warehouse
For a mixed workload use a smaller block size, like 8K
Larger block sizes can cause block level contention
Harvard University
Fragmentation
Use locally managed tablespaces Set pctincrease to a non zero value, if using
DMT. This will force SMON to coalesce the tablespace.
Otherwise use– Alter tablespace ‘name’ coalesce
Harvard University
Indexes Reduce index fragmentation by setting correct
storage parameters. Use LMT. Rebuild Indexes Alter index <index name> rebuild The rebuild option avoids the need to first
drop and re-create the index Unrecoverable option
Harvard University
Index Usage
Alter index index_name monitoring usage Alter index index_name nonmonitoring usage Query v$object_usage to view results
Harvard University
Chained Rows Once the statistics has been collected for the
schema Select the table name and chained row
count for any and all tables of that schema Rebuild the table to remove the chained rows
using export and import Some tools, like TOAD can remove the
chained rows on the fly.
Harvard University
Monitor DBWR and LGWR Select event, total_waits, time_waited
from v$system_event
where event like '%file%'
order by total_waits desc;
Db file sequential read event refers to when a foreground process is waiting for a sequential read from the database. It is higher if we have many table scans
Harvard University
Monitor DBWR and LGWR
Log file parallel writes refer to when the redo entries in the log buffer get written to the redo log file
Redo file sync reports the wait time of the LGWR writing redo entries for a given user session. When a user session commits a transaction, the redo information for the session is flushed to the redo log file
Harvard University
Database Tools
Estat/bstat Statpack ADDM AWR Sql trace Tkprof
Harvard University
Statspack
STATSPACK is a performance diagnosis tool Available since Oracle8i. It is the successor to BSTAT/ESTAT's STATSPACK
– instance-wide performance problems – supports application tuning activities by providing data
which identifies high-load SQL statements– it is used both proactively to monitor the changing load on
a system and reactively to investigate a performance problem
Harvard University
Statspack - Setup
For Oracle10g– Connect / as sysdba– @?/rdbms/admin/spcreate
spreport.sql to generate a report More next week on statspack and it’s
successor AWR
Harvard University
Statspack Installation
Scripts located in– /u01/app/oracle/10.2.0/rdbms/admin– connect / as sysdba– Create a perfstat tablespace– Create a perfstat user– sqlplus perfstat/perfstat@<SID>
Test Exit
Harvard University
Statspack Installation
Before Installation– Run catdbsyn.sql as sys– Run dbmspool.sql as sys
Sqlplus /nolog Connect / as sysdba At SQL prompt run @?/rdbms/admin/spcreate
Harvard University
Statspack Levels Statspack level
– Level 0 general statistics– Level 5 (default) high SQL– Level 6 sql plans– Level 7 segment level satistics– Level 10 child latches – All include data from lower levels
Harvard University
Statspack Snaps
To captute a snapshot run statspack.snap. Run at default level Run statspack.snap(i_snap_level => 7) to run
as a different level. To make this level permanent for all snaps
use statspack.snap(i_snap_level => 7, i_modify_parameter => ‘true’)
Harvard University
Statspack Report
SQL>sqlplus perfstat/perfstat SQL> @spreport.sql DB Id DB Name Inst Num Instance ----------- ---------- -------- ---------- Completed Snapshots Instance DB Name SnapId Snap Started
Snap Level
<SID> <SID> 1 17 Jan 2002 14:07:26 5
2 17 Jan 2002 14:11:55 5
Harvard University
Statspack Report
Parse ratio Top Waits Object statistics CPU usage High sql
– Hash Value
Harvard University
Statspack Report
SQL>sqlplus perfstat/perfstat SQL>sprepsql.sql You are requested for the hash value from the
first report Displays the sql text and the execution plan
and its relative cost Values lower than 100 are good.
Harvard University
Statspack Information
www.oraperf.com YAPP Yet another performance profiler www.akadia.com/services/ora_statspack_surv
ival_guide.html
www.rmoug.org/TD2004_Pres_Sum.htm#db_admin
Sysytemwide tuning using UTLSTAT Reports in Oracle 7/8 (metalink Note: 62161.1)
Harvard University
Automatic Workload Repository
AWR collects and processes performance metrics automatically
This is available with the creation of the database
Snapshots are taken every hour and maintained for 14 days by default
Procedures exist to make adjustments to these defaults
Harvard University
Automatic Workload Repository
AWR can be integrated with Oracle Enterprise manager (OEM)
Reports can be run using Oracle provided scripts
Harvard University
DBMS_STATS
DBMS_STATS - Gathers, Views, Modifies and Delete optimizer statistics for database objects
To gather stats for the current schema
EXEC DBMS_STATS.gather_schema_stats()
The above will COMPUTE global and partition-level statistics.
Harvard University
System Statistics
The gathered systems statistics are:– single block readtime in ms– multiblock readtime in ms– cpu speed in mhz– average multiblock_read_count in number of
blocks
Harvard University
System Statistics
begin DBMS_STATS.CREATE_STAT_TABLE('SYS','GATHERED_STATS');
DBMS_STATS.GATHER_SYSTEM_STATS( gathering_mode =>'INTERVAL', interval => &interval, stattab => 'GATHERED_STATS', statid => 'SYSTEM_DAY_STAT', statown => 'SYS' ); exception WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-20001,'Script Failed' || sqlerrm); end; /
Harvard University
System Statistics Example
Status COMPLETED
cpu in mhz : 156 single block readtime in ms : 1.15 multiblock readtime in ms : 2.386 average multiblock readcount : 7
Harvard University
Fixed Statistics
execute DBMS_STATS.GATHER_FIXED_OBJECTS_STATS (stattab => 'GATHERED_STATS', statid => 'FIXEDOBJ_STAT', statown => 'SYS');
Harvard University
SQL Trace The diagnostic tool 'sql trace' provides
performance information about individual SQL statements and generates the following statistics for each statement:
– parse, execute, and fetch counts– CPU and elapsed times – physical reads and logical – reads number of rows processed – misses on the library cache
Harvard University
SQL Trace
This information is input to a trace (.trc) file Sql trace can be enabled/disabled for a
session or an instance.
Harvard University
SQL Trace
SQL_TRACE– Enable/Disable SQL Trace for the instance.– TRUE Enable statistics to be collected
for all sessions.– FALSE Disable statistics to be collected
for all sessions.
Harvard University
SQL Trace
TIMED_STATISTICS Enable/Disable the collection of timed statistics, such as CPU and elapsed times.– TRUE Enable timing (usually recommended)– FALSE Default value.
Harvard University
SQL Trace MAX_DUMP_FILE_SIZE Specifies the
maximum size of trace files operating system blocks.
– The default value for this is 500M but if your trace file is truncated then increase this value
USER_DUMP_DEST Specifies the destination for the trace file.
– The default value for this parameter is the default destination for system dumps on your operating
system
Harvard University
SQL Trace
The SQL Trace facility can either be enabled/disabled for an individual session or the instance.
To enable the SQL trace facility for your session issue the following SQL statement:
– ALTER SESSION SET SQL_TRACE = TRUE;
To disable the SQL trace facility for your session issue the following SQL statement:
– ALTER SESSION SET SQL_TRACE = FALSE;
Harvard University
SQL Trace
The TKPROF facility accepts as input the SQL trace file and produces a formatted output file.
TKPROF trace_file.trc output_file
Harvard University
Top Parameters db_cache_size Shared_pool_size Sort_area_size compatible=11.0.1 memory_target pga_aggregate_target sga_target workarea_size_policy = auto db_writer_processes db_file_multiblock_read_count Undo_retention
Harvard University
Performance Notes
Set performance targets– set a goal such as "achieving a response time of
less than three seconds for 90% of transactions“
You will waste time tuning your system, if you alter initialization parameters or SQL statements without a specific goal
Harvard University
Performance Notes
Tuning is usually a series of trade-offs Identify the bottleneck that prevents you from
achieving your goal Tune the bottleneck Application developers and database
administrators must be careful to set appropriate performance expectations for users
Harvard University
Performance Notes
Keep in mind that in performing complicated operations, response times may be slower than when performing simpler operations
Achieving performance goals should not override your ability to recover data
Harvard University
Performance Notes
Ongoing performance monitoring enables you to maintain a well-tuned system
Make useful comparisons by keeping a history of the application’s performance over time
A detailed performance history can begin to predict the resource requirements for future load levels
Harvard University
Performance Notes
Tune during the design phase, rather than waiting to tune after implementing your system (application)
The cost of tuning is much higher after the application is in production
The performance of well-designed systems can degrade with use
Harvard University
Performance Notes
Ongoing tuning is an important part of proper system maintenance
Harvard University
Beware of Ratios ‘Ensure’ that the buffer cache hit rate is
greater than 90% This can vary, depending on the type of
application, ie OLTP or Data Warehouse
Harvard University
Reading
Oracle Performance Tuning 101- Oracle Press
Oracle performance Tuning – Tips and Techniques – Oracle Press