|
Database Performance TuningHere are my notes on tuning Oracle and MS-SQL for the Oracle and MSDBA exams. Basically, it's fastest is when:
To keep a database fast (proactively rather than reactively):
|
Related Topics:
|
Create Tablespace Extent Management Local, Not `DictionaryWhen a tablespace is created, several settings impact performance. When a tablespace is created with EXTENT MANAGEMENT DICTIONARY, DML commands run slower because the location of free and used blocks are stored in the data dictionary files in the SYSTEM tablespace. Since the SYSTEM bitmap file is shared, contention to access these files may occur. Different extent sizes make fragmentation more pronounced between blocks within the free list. Extra work by SMON is needed for coalescence of fragmented dellocated space (when multiple adjacent free extents are combined into a single contiguous free extent). This can be trigged with request:
When a tablespace is created with EXTENT MANAGEMENT LOCAL, DML commands run faster because the location of free and used blocks are stored in the datafile as a bitmap of data blocks at the beginning of each group of consecutive used blocks resides in a small record in the datafile header of that tablespace. This allows all extents to have the same size, so no fragmentation occurs. Thus, LOCAL is the default starting with 10g. BIGFILE tablespaces must select LOCAL. In fact according to Powell & McCullough-Dieter (2007), Oracle plans to eliminate DICTIONARY management in future releases. Coalescence occurs automatically for locally-managed tablespaces. One more thing. Every change to a system table causes undo and redo records to be created, which adds more operations and processing time. Changes to locally-managed bitmaps does not result in rollback information being generated. | Locally vs. Dictionary Managed Tablespaces (2003). Underground Oracle FAQ's retrieved November 10, 2007 Oracle 10g database administrator: Implementation and administration (1st ed.). (Boston, MA: Course Technology/Thomson Learning, 2007) by Powell, G., & McCullough-Dieter, C. |
Activity Stats For Capacity Planning
Here are measures of activity to use in a db capacity model: | Most Useful Database Instance Performance Ratios when Designing Management Applications Based on Oracle MIBs A More Complex Statspack Example Oracle 10g Statistics Descriptions How to choose the best Partitioning type (range, list, hash, range/list, and range/hash), and partionining key for the type of column. Index Tuning using the SQLAccess Advisor which recommends a set of indexes (and implementation script) based on a workload (the current contents of the SQL Cache, a user defined set of SQL statements, or a SQL Tuning set). It's invoked from Advisor Central in Oracle Enterprise Manager or through the DBMS_ADVISOR package APIs.
|
Instanteous StatsThese statistics reflect transitory conditions that change from moment to moment: "Opened cursors current" - The total number of current open cursors (user sessions).
|
Bottleneck Wait StatsFrom V$SYSSTAT: John Kanagaraj's “BACK PORTING ADDM, AWR, ASH AND METRICS TO ORACLE 9I & 8I” paper at IOUG 2006 Wait Event TotalWaits TotTmOuts TimeWaitd MaxWait ---------- ----------- ----------- ----------- ----------- db file sequential read 21,885 0 5,560 0 db file scattered read 9,926 0 9,532 0 db file parallel write 58 0 0 0 latch free 1,345 1,293 2,435 0 buffer busy waits 589 0 508 0 log file parallel write 284 0 209 0 file open 173 0 5 0 log file sync 107 0 85 0 control file parallel write 10 0 9 0 LGWR wait for redo copy 3 0 0 0 SQL*Net more data to client 274 0 5 0 SQL*Net more data from client 30 0 34 0 SQL*Net break/reset to client 6 0 0 0 Enqueue Log File Switch Wait Parse time CPU Free Buffer
|
Efficiency StatsSQL Dictionary Cache Hit Ratio Dictonary Cache within the Shared SQL Pool of the SGA (System Global Area) of memory Measured init.ora parameter SHARED_POOL_SIZE |
Statspack scripts
From Burlseon's StatsPack Analyzer
|
Cache I/OA "current" read is ???
|
Statistics
To identify the best possible execution path for SQL statements, the cost-based optimizer (CBO) (introduced in Oracle 7) augments bitmap indexes, function-based indexes, hash joins, and index-organized tables with statistics to select the best access plan based on the cost of various alternatives:
CBO uses a SQL profile for each query use sampling to collect additional information; partial execution techniques to verify and adjust cost estimates; and execution history information for the SQL statement to modify parameter settings. While the Oracle9i CBO used an I/O cost model primarily based on single block reads, Oracle Database 10g added system statistics that include system CPU for the Oracle workload (especially important for operations such as bitmap merge, sort, or hash joins that may not require any I/O). Statistics can get old and dated, so regularly schedule re-analyze tables and indexes. Statistics can be gathered manually several ways:
DBMS_STATS is the recommended over snapshot comparisons using STATSPACK or OEM Database Control. Statistics gathered by DBMS_STATS utility improves the execution speed of SQL because it provides up to date and high quality statistics the Cost Based optimizer (CBO) needs to make the best decision for the best and fastest path for a SQL query.
ANALYZE INDEX TOTAL_PAIDX VALIDATE STRUCTURE; SELECT NAME, BR_ROWS, BR_BLKS, LF_ROWS, DEL_LF_ROWS FROM INDEX_STATS;
Watch how CBO decides for an execution plan by setting diagnostic event 10053 triggered for a hard parse (not for a soft parse). alter session set events '10053 trace name context forever, level 1' A look under the Hood of CBO: The 10053 Event by Wolfgang Breitling. Dated April 27, 2004. Referenced November 11, 2007. |
ToolsThe Oracle database software comes standard with profiling tools SQL_TRACE output the SQL that the application executed TKPROF outputs how that SQL performed.
Orca (from Blair Zajac Marina del Rey, CA)
creates graph images from data collected by Oracle's Statspack (since Oracle 8.1.6)
using RRDtool to graph, (open source) Perl DBI and DBD::Oracle modules.
Unix Kernel Installation SettingsBoot Sun Solaris with these in effect for database creation to succeed: set shmsys:shminfo_shmmax=4294967295 set shmsys:shminfo_shmmin=1 set shmsys:shminfo_shmseg=10 set shmsys:shminfo_shmmni=100 set semsys:seminfo_semmns=1000 set semsys:seminfo_semmni=100 set semsys:seminfo_semmsl=250 Enough File System InodesOracle 9i includes more than 100,000 files. Copy the contents of the CDROM to a hard drive using this example for Oracle 9i: $ cd /cdrom/orcl901_1 $ mkdir -p /u01/app/oracle/admin/cdrom/9.0.1/Disk1 $ cp -pr . /u01/app/oracle/admin/cdrom/9.0.1/Disk1 Database Caching Effects
There are several parts to the response time of a database query: The response time of a SQL query which has been cached in a rather quiescent system is the "best case" performance metric because the database server does not have to create the retrieval plan nor make any disk I/O (since they are fetched from memory in the database server). To obtain these metrics, run the same request twice in rapid succession, immediately after flushing database buffers.
Efficient SQL
Using analytic functions can be more efficiently within Oracle than pulling raw data and performing the work at a web server. |
Download files from this publisher site "gives a step by step process to resolve different scenarios ... brought the book to life." The Art and Science of Oracle Performance Tuning (Apress, 2004) by Christopher Lawson, of The Oracle Magician, organizes his sage tips according to analogous job roles of a DBA: 1) Physician 2) Detective 3) Pathologist 4) Artist, and 5) Magician.
High-performance Oracle : Proven Methods for Achieving Optimum Performance and Availability (Indianapolis John Wiley, 2002) by Geoff Ingram Presents tips and techniques on Sun Solaris UNIX machines using NFS and for using Microsoft SMS (Systems Management Server)
Oracle Performance Tuning Nutshell Handbook (Cambridge, Mass. O'Reilly, 1996) by Mark Gurry & Peter Corrigan
OCP: Oracle9i Performance Tuning Study Guide (San Francisco, CA Sybex Books, 2002) by Joseph C. Johnson
OCP: Oracle8i DBA Performance Tuning and Network Administration Study Guide (San Francisco, Calif., London Sybex Books, 2000) by Joseph C. Johnson & Matthew Weishan
Oracle9i Performance Tuning Tips & Techniques (New York McGraw-Hill Professional, 2003) by Richard J. Niemiec
Database Performance Tuning and Optimization: Using Oracle (New York Springer-Verlag New York, 2003) by Sitansu S. Mittra |
How to Analyze Problem SQL Requests For That Take Too Long
The v$sqlarea view displays the text of SQL statements in the shared SQL area, plus the number of users accessing the statements, disk blocks and memory blocks accessed while executing the statement, and other information.
For 9i and 10g set the 10046 event
"Execute" is when SQL code statements are executed in various forms and by various routes, decided by the Optimizer. "Fetch" is the return of results passed back to the calling process. A large difference between "cpu" and "elasped" time may indicate a) a lock contending with another transaction or b) interference with a trigger or constraint. The cache hit ratio is calculated from this number of physical reads vs. logical reads. Large "disk" values may indicate a full table scan from inefficient index schema.
More on this at: oracle-base |
Resolving Locks
|
Doing ExperimentsSeveral features of Oracle are not active by default.
Parallel ExecutionFor SQL queries which consume a lot of CPU, try parallel execution on multiple CPUs. This feature can be specified two ways. One way is specify a SQL hint clauseSELECT /*+ PARALLEL(CLASSMATE.CLIENT, 2) */ * FROM CLASSMATE.CLIENT; A table can be setup to always process the query in parallel mode: { CREATE | ALTER } TABLE ... [ NOPARALLEL | PARALLEL [n] ];
Real Application TestingOracle 11g's "Real Application Testing" option features two levels of detail:
These features, when combined with a 11g flashback of entire databases to a specific point in time, provide the "external stimuli" needed to conduct precise experiments on test machines. The optimal configuration setting becomes apparent from the variance observed in AWR reports before and after replay run under various conditions (different platform environments, software versions, or configuration settings). Note, however, that the initial 11g release does not provide a way to capture workload within 10g. Experiments on different Oracle configuration settings include:
|
ResourcesIf you have an active support contract, check Oracle’s Metalink Web site for late-breaking news on installation issues. Afyouni. (2004). Oracle9i Performance Tuning; Optimizing Database Productivity.(1st. ed.) O'Reilly Publications. ISBN: 0-619-16004-7 soft. Jonathan P Lewis's articles on Monitoring and Tuning Free Oratips journal from Klee Associates |
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |