Understanding Performance Tuning in Oracle
Understanding Performance Tuning in Oracle
net/blog
I am Vijay Mahawar, an Oracle Technologist. I am a member of AIOUG, ODTUG and OTN. I am certified in Oracle and hold OCP in Oracle 11g DBA and OCP in Oracle 11g Advanced Developer Track. I am also OPN Certified Specialist.
I am associated with Oracle Technologies since year 2002. During this time I have held positions of Trainer, Developer, DBA, Analyst and Consultant in Companies like L&T Infotech Ltd., HCL Technologies Ltd., Dell Services and Sapient Consulting Pvt. Ltd.
https://www.mahawar.net/blog
Performance Tuning is optimal utilization of all resources and enabling them to perform to their fullest potential. Performance of the SQL queries of an application often play a big role in the overall performance of the underlying application.
The response time may at times be really irritating for the end users if the application doesn't have fine-tuned SQL queries. Differentiate between symptoms and problem. Most tools and techniques give symptoms and that should not be confused with problems. Developers/DBA both have part to play in keeping the database tuned.
https://www.mahawar.net/blog
Client/Server Architecture
Different Layers: Application Interface Network Application Servers Processes Database Instance CPU Disk
Multi-Tier Architecture
https://www.mahawar.net/blog
https://www.mahawar.net/blog
Tuning Areas
Database Design (if it's not too late)
Description
Try to normalize to the 3NF. Selective denormalization can provide performance improvements. Always keep the "data access path" in mind. Look at data partitioning, data replication, aggregation tables etc. for DSS
P r e c e d e n c e
Majority of all Oracle system performance problems are resolved by coding optimal SQL. Scheduling of batch tasks during non-peak hours. Optimal sizing of database buffers (shared_pool, buffer cache, log buffer, etc) by looking at ADDM report showing frequent reloads.
Memory Tuning
wait events, buffer hit ratios, system swapping and paging, etc. Use of pin for large objects into memory to prevent
Disk I/O Tuning Size Database files and properly place them Look for frequent disk sorts, full table scans, missing
Study database locks, latches and wait events carefully and eliminate where possible. Monitor and tune operating system using OS utilities shown later.
https://www.mahawar.net/blog 6
Developer
DBA
Netstat (Network)
Sar, iostat (Disk) Sar, vmstat (Memory) Sar, vmstat, mpstat, iostat(CPU) SQL_TRACE and TKProf ADDM Statspack (old UTLBSTAT/UTLESTAT) OEM Tuning Pack
https://www.mahawar.net/blog
When an SQL statement is passed to the server the Cost Based Optimizer (CBO) uses database statistics to create an execution plan which it uses to navigate through the data. EXPLAIN the statement to check the execution plan that the CBO has created.
This will help in diagnosis and often reveal that the query is not using the relevant indexes, or indexes to support the query are missing. Three Methods: PLAN_TABLE is metadata table for explain plan. utlxplan.sql script creates this table in oracle.
https://www.mahawar.net/blog 8
1. 2. 3.
https://www.mahawar.net/blog
A hint is an instruction to the optimizer. When writing SQL code, you may know information about the data unknown to the optimizer, usually when statistics are out of date Hints enable you to make decisions normally made by the optimizer, sometimes causing the optimizer to select a plan that it sees as higher cost.
Hints Categories Examples ALL_ROWS, FIRST_ROWS, CHOOSE FULL, HASH, INDEX FACT, NO_FACT, MERGE, NO_MERGE LEADING, USE_NL, USE_HASH, USE_MERGE NOPARALLEL, PARALLEL, NOPARALLEL_INDEX, PARALLEL_INDEX APPEND, CACHE,DYNAMIC_SAMPLING, RESULT_CACHE, ORDERED
USAGE:
Optimization Approaches and Goals Access Paths Query Transformations Join Orders
EXAMPLE:
https://www.mahawar.net/blog
10
Without the bulk bind, PL/SQL sends a SQL statement to the SQL engine for each record that is inserted, updated, or deleted leading to context switches that hurt performance. One method of overcoming this performance bottleneck is an Oracle bulk collect. With Oracle bulk collect, the PL/SQL engine tells the SQL engine to collect many rows at once and place them in a collection and switches back to the PL/SQL engine. Syntax:
FETCH BULK COLLECT <cursor_name> INTO <collection_name> LIMIT <numeric_expression>;
https://www.mahawar.net/blog
11
The FORALL statement issues a series of static or dynamic DML statements using the collection mostly populated using BULK Collect we saw in previous slide. This will allowing the DML to be run for each row in the collection without requiring a context switch each time. Syntax:
FORALL <index_name> IN lower_bound..upper_bound dml_statement SAVE EXCEPTIONS or FORALL <index_name> IN INDICES OF collection BETWEEN lower_bound and upper_bound dml_statement SAVE EXCEPTIONS
SQL%BULK_ROWCOUNT: cursor attribute gives granular information about the rows affected by each iteration of the FORALL statement SAVE EXCEPTIONS and SQL%BULK_EXCEPTION: Optional keywords that cause the FORALL loop to continue even if some DML operations fail.
https://www.mahawar.net/blog
12
OS Tools
sar -d (or iostat) Sar, vmstat, mpstat, iostat
Memory Network
Sar* (vmstat)
Sar* - System Activity Monitor Ping* - Packet IntergNet Groper Tracert* Trace Route (TTL)
https://www.mahawar.net/blog
13
Fig. shows difference between following wait events: db file sequential read - single block read into one SGA buffer db file scattered read multiblock read into many discontinuous SGA buffers direct read - single or multiblock read into the PGA, bypassing the SGA
On a healthy system, physical read waits should be the biggest waits after the idle waits. However, also consider whether there are db file sequential reads on a large data warehouse that should be seeing mostly full table scans with parallel query.
https://www.mahawar.net/blog
14
Type
Books Website
Link/Author
Donald K. Burleson (author)
Oracle Documentation
Reference Comments
Oracle Tuning: The Definitive Reference Content and images were referred.
Website
Website Website Website Webiste
http://ss64.com
http://www.orafaq.com http://www.oracle-base.com http://psoug.org http://www.adp-gmbh.ch
https://www.mahawar.net/blog
15
https://www.mahawar.net/blog
16
https://www.mahawar.net/blog
17