Database Tuning
Database Tuning
Overall, by applying Oracle Database tuning techniques during the design phase, it
is possible to create an application that is optimized for performance and can scale
to meet the needs of a growing user base.
By designing a system to perform well, you can minimize its implementation and
on-going administration cost. Figure bellow illustrates the relative cost of tuning
during the life of an application.
To complement this view, figure bellow shows that the relative benefit of tuning
an application over the course of its life is inversely proportional to the cost
expended.
Sizing the SGA (System Global Area) and PGA (Program Global Area)
correctly: The SGA and PGA are areas of memory that are used by the
Oracle Database to store data such as buffers and shared SQL. Sizing these
areas correctly can help to ensure that the database has enough memory to
perform efficiently.
Adjusting the buffer cache size: The buffer cache is used to store data that
has been read from disk, so adjusting the buffer cache size can help to
improve the performance of queries that access this data frequently.
Adjusting the shared pool size: The shared pool is used to store
information such as parsed SQL statements and execution plans, so adjusting
the shared pool size can help to improve the performance of queries that are
executed frequently.
Enabling Automatic Memory Management (AMM): AMM automatically
adjusts the size of the SGA and PGA based on the current workload, which
can help to ensure that the database has enough memory to perform
efficiently.
By Lec. Pratik Chand, Page 4
Elective-Database Administration – CSIT 7th Semester
Optimizing SQL queries: Optimizing SQL queries can help to ensure that
the database is able to retrieve the data it needs as quickly and efficiently as
possible. This can be done by using indexes, rewriting queries, and using
hints.
Enabling parallel query execution: Enabling parallel query execution
allows the database to divide a query into multiple parts and execute them
simultaneously, which can improve query performance.
Enabling parallel DML and DDL execution: Enabling parallel DML and
DDL execution allows the database to perform insert, update, delete, and
other data modification operations simultaneously, which can improve
performance.
Using RAC (Real Application Clusters): RAC allows multiple instances
of the database to run simultaneously on different servers, which can
improve performance by distributing the workload across multiple servers.
Enabling Database Smart Scan: Database Smart Scan allows the database
to offload the processing of certain types of queries to specialized hardware,
such as storage cells, which can improve query performance.
Properly indexing the database: Indexing the database can greatly improve
the performance of data manipulation operations by allowing the database to
quickly locate the data it needs.
Partitioning large tables: Partitioning large tables can help to improve the
performance of data manipulation operations by allowing the database to
only work with the data that is relevant to the operation.
Enabling parallel DML execution: Enabling parallel DML execution
allows the database to perform insert, update, and delete operations
simultaneously, which can improve performance.
Using bulk operations: Using bulk operations such as bulk insert and bulk
update can improve performance when working with large amounts of data.
Using Materialized Views: Materialized views can be used to improve
performance by pre-computing and storing the results of complex queries, so
that data manipulation operations can be performed on the pre-computed
data.
Using the appropriate data types: Using the appropriate data types for
columns in the database can help to reduce the amount of storage space
required and improve query performance.
Using Triggers and Constraints: Triggers and constraints can be used to
enforce data integrity and business rules, which can help to improve
performance by reducing the need for complex queries.
By Lec. Pratik Chand, Page 6
Elective-Database Administration – CSIT 7th Semester
What is triggering?
A trigger is a type of stored procedure that is automatically executed in response to
certain events within a database. Triggers are typically used to enforce business
rules or maintain data integrity by performing actions such as validating data,
updating related tables, or auditing changes.
Triggers can be associated with a specific table, view, or schema, and can be
triggered by events such as INSERT, UPDATE, or DELETE operations on the
associated object. They can also be triggered by DDL operations such as
CREATE, ALTER, and DROP.
There are several types of constraints that can be used in an Oracle database:
Not Null Constraint: A Not Null constraint ensures that a column cannot
have a null value.
These are a few common techniques for reducing network traffic in an Oracle
database. It's important to consider the specific requirements of your application
and the network infrastructure when choosing which techniques to use.
By Lec. Pratik Chand, Page 8
Elective-Database Administration – CSIT 7th Semester
AWR captures the performance statistics by default in regular interval and can be
controlled by setting the retention period of the statistics.
AWR reports can be generated using the awrrpt.sql script and can be viewed
using SQL*Plus, Oracle Enterprise Manager, or third-party tools. These reports
provide detailed information on various aspects of the database performance,
including the top SQL statements, wait events, and system statistics.
AWR can be a powerful tool for identifying and resolving performance issues in an
Oracle database.
Note: It is important to note that, the more the data captured by AWR the more
disk space it will consume. Therefore, you should consider the retention period and
disk space availability before configuring the AWR.
To use the Automatic Workload Repository (AWR) in an Oracle database, you can
follow these steps:
The AWR is enabled by default in Oracle databases, but you can check its status
by running the following query:
You can generate an AWR report by running the awrrpt.sql script, which is located
in the $ORACLE_HOME/rdbms/admin directory.
options: Additional options can be added to the command line to customize the
report. Here are a few examples:
For example: to generate an AWR report for snapshots 100 and 200, with detailed
statistics and in HTML format, you would run the following command:
Step 1: Ensure that the Automatic Workload Repository (AWR) is enabled. This is
done by setting the statistics_level parameter to TYPICAL or ALL.
Syntax:
BEGIN
DBMS_ADDM.analyze_DB(
start_snap_id => <start_snap_id>,
end_snap_id => <end_snap_id>,
options => <options>);
END;
start_snap_id and end_snap_id are the snapshot IDs for the start and end of the
analysis period. These can be obtained from the DBA_HIST_SNAPSHOT view. If
not specified, the default is to analyze the most recent hour.
Options is an optional parameter that can be used to specify additional options for
the ADDM analysis. This parameter is a bitmap and can be set to any combination
of the following values:
Step 3: View the ADDM report by accessing the Automatic Workload Repository
(AWR) via the Enterprise Manager or the awrrpt.sql script. The report will include
a summary of the performance issues identified by ADDM and recommendations
for resolving them.
It is also worth noting that ADDM is not always needed or the best option for
performance tuning. You should also consider using other performance tuning
tools like SQL Tuning Advisor, SQL Access Advisor, and Real-time SQL
Monitoring.
Tuning SQL:
There are several methods for tuning SQL statements in Oracle Database, some of
the common ones are:
SQL Tuning Advisor: The SQL Tuning Advisor is a built-in tool in Oracle
Database that analyzes a specific SQL statement and provides
recommendations for performance tuning. You can access the SQL Tuning
Advisor through the Enterprise Manager or by using the DBMS_SQLTUNE
package.
SQL Access Advisor: The SQL Access Advisor is a tool that analyzes the
workload of a database and provides recommendations for creating or
By Lec. Pratik Chand, Page 12
Elective-Database Administration – CSIT 7th Semester
It is worth noting that the best method for tuning a SQL statement depends on the
specific circumstances of the query and the database environment. It is always
recommended to test the performance of any changes made to a SQL statement
before applying them in a production environment.
To use the SQL Tuning Advisor through the DBMS_SQLTUNE package, you can
use the following procedure:
BEGIN
-- Create the tuning task
DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => 'SELECT * FROM my_table WHERE id = 123',
task_name => 'my_task',
scope => 'COMPREHENSIVE || BASIC');
This will create a tuning task called "my_task", and execute a comprehensive or
basic analysis on the specified SQL statement, and then generate a report of the
results.
It is worth noting that the SQL Tuning Advisor is a powerful tool, but it can be
time-consuming and resource-intensive, so it should be used judiciously in a
production environment. It's important to test the performance of any changes
made to a SQL statement before applying them in a production environment.
These are general steps and the exact tuning approach will depend on the specific
requirements and environment of your database.
These are general steps and the exact tuning approach will depend on the specific
requirements and environment of your distributed database and network.
End of Unit-7