61
Harvard University Oracle Database Administration Session 12 Performance

Harvard University Oracle Database Administration Session 12 Performance

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Oracle Database Administration

Session 12

Performance

Page 2: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Performance

Wholistic view System level Database level Application level

Page 3: Harvard University Oracle Database Administration Session 12 Performance

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

Page 4: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Performance Definition

Response time = service time + wait time We can increase performance two ways:

– by reducing service time – by reducing wait time.

Page 5: Harvard University Oracle Database Administration Session 12 Performance

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)

Page 6: Harvard University Oracle Database Administration Session 12 Performance

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

Page 7: Harvard University Oracle Database Administration Session 12 Performance

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

Page 8: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Areas of Interest System

– Memory– CPU– Disk

Database– Layout– Init.ora

Application– Sql– Most resource expensive sql statements

Page 9: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Areas of Interest

Network– Sql*net– Network structure

Page 10: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Percentage Gain

Application 75% to 90% gain Database 10% to 15% gain System 5% to 10% gain Network Less than 5% gain

Page 11: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

The Role of the DBA

The DBA mostly works on database tuning

Enabling the developers improve their code

Improving Application Architecture

Page 12: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

System Tools Top Vmstat Sar Mpstat

Page 13: Harvard University Oracle Database Administration Session 12 Performance

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

Page 14: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

System Tools

Prtdiag - System Configuration Prstat – Similar to TOP Netstat – Network Configuration

Most commands located in /usr/sbin on a Solaris system

Page 15: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Top

Overall view of the system Use of Averages

AIX– Topas– nmon

Page 16: Harvard University Oracle Database Administration Session 12 Performance

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

Page 17: Harvard University Oracle Database Administration Session 12 Performance

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

Page 18: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 19: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Vmstat

vmstat [ -cisS ] [ disks ] [ interval [ count ] ] Vmstat 5 5 Vmstat –S to get swapping information

Page 20: Harvard University Oracle Database Administration Session 12 Performance

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

Page 21: Harvard University Oracle Database Administration Session 12 Performance

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

Page 22: Harvard University Oracle Database Administration Session 12 Performance

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

Page 23: Harvard University Oracle Database Administration Session 12 Performance

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

Page 24: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Index Usage

Alter index index_name monitoring usage Alter index index_name nonmonitoring usage Query v$object_usage to view results

Page 25: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 26: Harvard University Oracle Database Administration Session 12 Performance

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

Page 27: Harvard University Oracle Database Administration Session 12 Performance

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

Page 28: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Database Tools

Estat/bstat Statpack ADDM AWR Sql trace Tkprof

Page 29: Harvard University Oracle Database Administration Session 12 Performance

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

Page 30: Harvard University Oracle Database Administration Session 12 Performance

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

Page 31: Harvard University Oracle Database Administration Session 12 Performance

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

Page 32: Harvard University Oracle Database Administration Session 12 Performance

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

Page 33: Harvard University Oracle Database Administration Session 12 Performance

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

Page 34: Harvard University Oracle Database Administration Session 12 Performance

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’)

Page 35: Harvard University Oracle Database Administration Session 12 Performance

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

Page 36: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Statspack Report

Parse ratio Top Waits Object statistics CPU usage High sql

– Hash Value

Page 37: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 38: Harvard University Oracle Database Administration Session 12 Performance

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)

Page 39: Harvard University Oracle Database Administration Session 12 Performance

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

Page 40: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Automatic Workload Repository

AWR can be integrated with Oracle Enterprise manager (OEM)

Reports can be run using Oracle provided scripts

Page 41: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 42: Harvard University Oracle Database Administration Session 12 Performance

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

Page 43: Harvard University Oracle Database Administration Session 12 Performance

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; /

Page 44: Harvard University Oracle Database Administration Session 12 Performance

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

Page 45: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Fixed Statistics

execute DBMS_STATS.GATHER_FIXED_OBJECTS_STATS (stattab => 'GATHERED_STATS', statid => 'FIXEDOBJ_STAT', statown => 'SYS');

Page 46: Harvard University Oracle Database Administration Session 12 Performance

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

Page 47: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 48: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 49: Harvard University Oracle Database Administration Session 12 Performance

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.

Page 50: Harvard University Oracle Database Administration Session 12 Performance

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

Page 51: Harvard University Oracle Database Administration Session 12 Performance

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;

Page 52: Harvard University Oracle Database Administration Session 12 Performance

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

Page 53: Harvard University Oracle Database Administration Session 12 Performance

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

Page 54: Harvard University Oracle Database Administration Session 12 Performance

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

Page 55: Harvard University Oracle Database Administration Session 12 Performance

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

Page 56: Harvard University Oracle Database Administration Session 12 Performance

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

Page 57: Harvard University Oracle Database Administration Session 12 Performance

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

Page 58: Harvard University Oracle Database Administration Session 12 Performance

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

Page 59: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Performance Notes

Ongoing tuning is an important part of proper system maintenance

Page 60: Harvard University Oracle Database Administration Session 12 Performance

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

Page 61: Harvard University Oracle Database Administration Session 12 Performance

Harvard University

Reading

Oracle Performance Tuning 101- Oracle Press

Oracle performance Tuning – Tips and Techniques – Oracle Press