Oracle Performance Tuning Intro
At higher end level for already running/existing database can be tuned as:
- SQL Tuning and
- Instance Tuning
"Performance Planing" is a way where tuning of database for newly Creating/Designing a database.
When a database is to be tuned
- Proactive Tuning = Proactive Monitoring+Bottleneck Eliminations: This is done before any performance issues occur, To avoid performance problems prior.
- Reactive Tuning: This is done when any performance issues occur, To resolve performance problems occurred.
Oracle Architecture in terms of Performance Tuning
In oracle architecture what components and where performance tuning can be done:
- Operating system Dependencies and Networking - Tuning: memory, CPU, swap size, I/O bandwidth,
- If oracle process is running on swap size then its shows performance issues,
- monitor - memory usage on system, CPU usage on system, swap size usage on system, load average on system
- Background process involved in Tuning
- Storage and Memory(SGA,PGA,UGA) Dependencies in tuning
- Explain Plan Of SQL Statements
- Tracing SQL Execution
- Tkprof For Trace analysis
- AUTO TRACE in SQL
- V$ Dynamic Performance Views used
- OEM
- AWR, ADDM, ASH Reports
- SQL Tuning Advisors and Baselines, Tuning Sets.
- OS Monitoring.
- Execution/ Explain plans
- SQL Tuning sets and Base lines, Hashes
- Tuning table access
- Tuning JOINS
- Sorting and grouping activities
- PL-SQL tuning notes
- Parallelism in SQL
- Optimizer and controlling it.
- Monitoring instance usage
EXPLAIN PLAN:
TRACING:
End to End oracle application tracing:
- Tracing using Client Identifier
- Tracing using service module and action
- Tracing at session level
- Tracing entire database or instance
- Specific SQL tracing
Set a trace file identifier to identify the trace files generated using the below we can set it
SQL> alter session set tracefile_identifier=name
Tracing Using Client Identifier
The CLIENT_ID_TRACE_ENABLE procedure used to enable tracing globally for the database for a given client identifier, refer below example:
SQL> EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(client_id => 'OE.OE', waits => TRUE, binds => FALSE);
SQL> EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE(client_id => 'OE.OE');
Tracing for Service, Module, and Action
The SERV_MOD_ACT_TRACE_ENABLE procedure enables SQL tracing for a given combination of service name, module, and action globally for a database, unless an instance name is specified in the procedure, module name may or may not be included, refer below example:
SQL> EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name => 'ACCTG', waits => TRUE, binds => FALSE, instance_name => 'inst1');
Disable tracing for a service or action or module:
SQL> EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name => 'ACCTG',
instance_name => 'inst1');
Tracing at Session level
The SESSION_TRACE_ENABLE procedure enables the trace for a given database session identifier (SID),
on the local instance, to enable we need the SID, Serial number to get the these values use below query
SQL> select sid, serial#, username from v$session;
Enable tracing for a specific session:
SQL> EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id => 27, serial_num => 60,
waits => TRUE, binds => FALSE);
SQL> EXECUTE DBMS_SESSION.SESSION_TRACE_ENABLE(waits => TRUE, binds => FALSE); --- Enabling trace for self session
Disable tracing for a specific session:
SQL> EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE(session_id => 27, serial_num =>
60);
SQL> EXECUTE DBMS_SESSION.SESSION_TRACE_DISABLE(); --- Disabling trace for the invoked session
Tracing for Entire Instance or Database
The DATABASE_TRACE_ENABLE procedure enables SQL tracing for a given instance or an entire database. Tracing is enabled for all current and future sessions. For example:
Enable tracing for an instance
SQL> EXECUTE DBMS_MONITOR.DATABASE_TRACE_ENABLE(waits => TRUE, binds => FALSE,
instance_name => 'inst1'); --- Overrides all other session level traces.
Disable tracing for an instance
SQL> EXECUTE DBMS_MONITOR.DATABASE_TRACE_DISABLE(instance_name => 'inst1');
Starting a trace using login trigger:
If charan user logs into the database then this trigger will be triggered and PL-SQL block which enables session tracing will be executed
AFTER LOGON ON DATABASE
BEGIN
IF USER =
'CHARAN' THEN
EXECUTE IMMEDIATE 'alter session set
tracefile_identifier=CHARAN'; DBMS_SESSION.session_trace_enable
(waits => TRUE,
binds => FALSE,
plan_stat => 'all_executions'
);
END IF;
END;
Viewing Enabled Traces for End-to-End Tracing
AUTOTRACE:
Its options its just like along with the query we will get the output & explain plan & statics and also no of rows based on the options we set
- set autotrace on: will enable the auto trace and when a query is fired we will get the output & explain plan & statics and also no of rows
- set autotrace on statistics: will enable the autotrace but when a query fired we will get the output and statics
- set autotrace on explain: will enable the autotrace but when a query fired we will get the output and explain plan.
- set autotrace traceonly: will enable the autotrace but when a query fired we will get the no of rows & explain plan & statics
- set autotrace off: will disable the auto trace and when a query is fired we will get the output only
V$ VIEWS:
AWR, ADDM, ASH REPORTS:
This data is both in memory and stored in the database, The statistics collected and processed by AWR includes:
- Object statistics that determine both access and usage statistics of database segments
- Time model statistics based on time usage for activities, displayed in the V$SYS_TIME_MODEL and V$SESS_TIME_MODEL views
- Some of the system and session statistics collected in the V$SYSSTAT and V$SESSTAT views
- SQL statements that are producing the highest load on the system, based on criteria such as elapsed time and CPU time
- ASH statistics, representing the history of recent sessions activity
Retension period is 8 days by default for awr snapshots
To generate AWR report: SQL> @?/rdbms/admin/awrrptADDM (Automatics Database Diagnostics Monitor):
Based on the snapshot it will recommend what action need to be taken
To generate ADDM report: SQL> @?/rdbms/admin/addmrpt
We need to give the time between which the session details all will be captured between that time slots.
To generate ASH report: SQL> @?/rdbms/admin/ashrpt
SQL TUNING ADVISOR AND BASELINES:
To get the report of a sql: SQL> @?/rdbms/admin/sqltrpt the plsql block asks for sql-id get sql-id before running this plsql block.
DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'sql tuning advisor', operation => NULL, window_name => NULL);
/
To disable automatic SQL tuning, use the DISABLE procedure in the DBMS_AUTO_TASK_ADMIN package:
BEGIN
END;
/
OS MONITORING:
Comments
Post a Comment