0% found this document useful (0 votes)
7 views

Database Tuning

Uploaded by

bstarsgamer34
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Database Tuning

Uploaded by

bstarsgamer34
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Elective-Database Administration – CSIT 7th Semester

Unit-7: Database Tuning

What is Database Tuning?


Oracle database tuning refers to the process of optimizing the performance of an
Oracle database. This can include adjusting settings, creating indexes, and
reorganizing data to improve the efficiency of SQL queries. Additionally,
monitoring and analyzing performance metrics, such as CPU usage, memory
usage, and disk I/O can be used to identify areas for improvement. The goal of
tuning is to minimize response time and maximize throughput for a given
workload.

Where we can user database tuning?


Oracle Database tuning can be used in a variety of situations where the
performance of an Oracle Database needs to be optimized. Some common use
cases include:

 High-traffic environments: In environments where a large number of users


and/or transactions are accessing the database, tuning can be used to ensure
that the database can handle the load and respond quickly to queries.
 Data warehousing and business intelligence: Tuning can be used to
optimize the performance of large data warehouses and business intelligence
systems that rely on Oracle databases.
 Application development: Oracle Database tuning can be used to optimize
the performance of applications that rely on an Oracle database as their
underlying data store.
 Cloud-based deployments: Oracle Database tuning can be used to optimize
the performance of Oracle databases deployed in cloud environments such
as Amazon Web Services (AWS) or Oracle Cloud Infrastructure (OCI).
 Consolidation: When multiple databases are consolidated into a single
Oracle database, tuning can be used to ensure optimal performance and
resource usage.

Overall, Oracle Database tuning is important to ensure that the database is


performing at its best and providing the best possible user experience.

By Lec. Pratik Chand, Page 1


Elective-Database Administration – CSIT 7th Semester

Tuning Application Design:


Oracle Database tuning can also be applied to the design of applications that use an
Oracle database. This can include the following steps:

 Identifying performance bottlenecks: By analyzing performance metrics,


such as response time and resource usage, it is possible to identify areas of
the application where performance is poor.
 Optimizing SQL queries: By reviewing and optimizing the SQL queries
used in the application, it is possible to reduce the resources required to
execute them. This can include using indexes, rewriting queries, and
adjusting the database schema.
 Reducing database load: By reducing the number of database connections,
transactions, and other resources used by the application, it is possible to
reduce the load on the database and improve performance.
 Caching and materialized views: Caching frequently used data and
creating materialized views can improve performance by reducing the
number of database queries needed.
 Designing for scalability: By designing the application to scale out, it is
possible to handle an increasing number of users and transactions without
affecting performance.
 Use of Oracle's built-in features: Oracle provides a lot of built-in features
like Data compression, Partitioning, and parallel execution that can be used
to optimize the performance of the application.
 Properly indexing the database: Indexing the database can greatly improve
query performance by allowing the database to quickly locate the data it
needs.
 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.
 Normalizing the data: Normalizing the data in the database can help to
reduce data redundancy and improve query performance.
 Partitioning large tables: Partitioning large tables can help to improve
query performance by allowing the database to quickly locate the data it
needs.

By Lec. Pratik Chand, Page 2


Elective-Database Administration – CSIT 7th Semester

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.

Business executives should work with application designers to establish


performance goals and set realistic performance expectations. During design and
development, the application designers can then determine which combination of
system resources and Oracle features best meet these needs.

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.

Fig: 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.

By Lec. Pratik Chand, Page 3


Elective-Database Administration – CSIT 7th Semester

Fig: Benefit of tuning during the life of an application

Tuning Memory Usase:


Oracle Database tuning can be applied to optimize the use of memory resources.
Some specific ways to tune memory usage include:

 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

 Enabling Automatic Shared Memory Management (ASMM): ASMM


automatically adjusts the size of the shared pool, buffer cache, and other
memory structures based on the current workload, which can help to ensure
that the database has enough memory to perform efficiently.
 Setting Memory Target: Memory Target allows you to set the total amount
of memory that the database should use. If memory pressure is high, the
database will automatically adjust the memory usage of the SGA and PGA.

Overall, by adjusting these and other memory-related parameters, it is possible to


tune the use of memory resources to ensure that the database performs as
efficiently as possible in terms of both performance and resource usage.

Tuning Database Access:


Oracle Database tuning can also be applied to optimize access to the database.
Some specific ways to tune database access include:

 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.

By Lec. Pratik Chand, Page 5


Elective-Database Administration – CSIT 7th Semester

 Enabling Transparent Data Encryption: Transparent Data Encryption


encrypts sensitive data in the database, which can help to improve security
and compliance.

Overall, by applying these and other techniques, it is possible to tune database


access to ensure that the database performs as efficiently as possible in terms of
both performance and security.

Tuning Data Manipulation:


Oracle Database tuning can also be applied to optimize data manipulation
operations such as inserts, updates, and deletes. Some specific ways to tune data
manipulation include:

 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

Overall, by applying these and other techniques, it is possible to tune data


manipulation operations to ensure that the database performs as efficiently as
possible, in terms of both performance and resource usage.

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.

What is data constraint?


A constraint is a set of rules that enforces data integrity in a database. It is used to
limit the type of data that can be inserted or updated in a table. Constraints are used
to define the relationships between tables and to ensure that the data in the table is
accurate and consistent.

There are several types of constraints that can be used in an Oracle database:

 Primary Key Constraint: A primary key constraint is used to uniquely


identify each row in a table. It ensures that no two rows in the table have the
same primary key value.
 Foreign Key Constraint: A foreign key constraint is used to maintain
referential integrity between two related tables. It ensures that a value in the
foreign key column of one table matches the primary key column of another
table.
 Unique Constraint: A unique constraint ensures that no two rows in a table
have the same value in a specified column or set of columns.
 Check Constraint: A check constraint is used to validate the data in a
column against a Boolean expression. It is used to ensure that the data in a
column meets certain conditions.

By Lec. Pratik Chand, Page 7


Elective-Database Administration – CSIT 7th Semester

 Not Null Constraint: A Not Null constraint ensures that a column cannot
have a null value.

Reducing Network Traffic:


Reducing network traffic is a common technique used to improve the performance
of a database system that is accessed over a network. Here are a few ways to
reduce network traffic in an Oracle database:

 Minimizing round trips: By reducing the number of round trips between


the application and the database, you can reduce the amount of network
traffic. One way to do this is by using stored procedures or packages, which
can perform multiple operations in a single round trip.
 Reducing data transfer: Another way to reduce network traffic is by
reducing the amount of data that needs to be transferred over the network.
This can be achieved by using techniques such as data compression, data
caching, and pagination of data.
 Using a connection pool: Connection pooling allows the application to
reuse database connections, reducing the number of connections that need to
be created and closed. This can reduce the amount of network traffic and
improve the performance of the application.
 Optimizing the database design: Proper database design and normalization
can reduce the amount of data that needs to be transferred over the network.
 Using a middleware: A middleware layer can be used to reduce the amount
of network traffic by offloading certain tasks such as data validation, data
transformation, and security to the middleware layer.
 Using a database proxy: A database proxy can be used to reduce network
traffic by caching data and compressing network traffic.
 Using database links: Database links can be used to reduce network traffic
by allowing the database to access data on a remote database without having
to transfer the data over the network.

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

Using Automatic Workload Repository (AWR):


The Automatic Workload Repository (AWR) is a feature in Oracle databases that
automatically collects and stores performance statistics. The AWR is used to
diagnose and troubleshoot performance issues in an Oracle database.

AWR captures a wide range of performance statistics, including statistics on


database activity, performance of SQL statements, and performance of the
operating system and hardware. The statistics are collected and stored in the AWR
repository, which can be queried to generate performance reports.

AWR can be used to:

 Identify performance bottlenecks


 Compare performance over time
 Analyze the performance of specific SQL statements
 Identify the impact of specific events such as system changes or software
upgrades

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.

By Lec. Pratik Chand, Page 9


Elective-Database Administration – CSIT 7th Semester

Steps to user AWR:

To use the Automatic Workload Repository (AWR) in an Oracle database, you can
follow these steps:

Step 1: Verify that the AWR is enabled:

The AWR is enabled by default in Oracle databases, but you can check its status
by running the following query:

SELECT * FROM DBA_HIST_WR_CONTROL;

Step 2: Generate an AWR report:

You can generate an AWR report by running the awrrpt.sql script, which is located
in the $ORACLE_HOME/rdbms/admin directory.

Syntax: @?/rdbms/admin/awrrpt.sql [start_snap_id end_snap_id] [options]

start_snap_id: The snapshot ID of the start point for the report.

end_snap_id: The snapshot ID of the end point for the report.

These can be obtained by running the following query:

select snap_id, to_char(end_interval_time,'dd-mon-yyyy hh24:mi:ss') as


end_time from dba_hist_snapshot;

options: Additional options can be added to the command line to customize the
report. Here are a few examples:

 -instance: to specify the instance name.


 -detail: to include detailed statistics in the report.
 -html: to generate the report in HTML format.
 -term: to generate the report in plain text format.

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:

SQL> @?/rdbms/admin/awrrpt.sql 100 200 -detail -html

By Lec. Pratik Chand, Page 10


Elective-Database Administration – CSIT 7th Semester

Automatic Database Diagnostic Monitor (ADDM)


The Automatic Database Diagnostic Monitor (ADDM) is a feature in Oracle
Database that automatically analyzes the performance of a database and provides
recommendations for performance tuning. ADDM runs periodically (by default,
every hour) and generates a report that identifies potential performance issues and
recommends actions to resolve them. ADDM can be used to analyze the
performance of both the entire database and individual components, such as
specific SQL statements or segments. The ADDM report is available in the
Automatic Workload Repository (AWR) and can be viewed using the Enterprise
Manager or the awrrpt.sql script.

To use the Automatic Database Diagnostic Monitor (ADDM) in Oracle Database,


you can follow these general steps:

Step 1: Ensure that the Automatic Workload Repository (AWR) is enabled. This is
done by setting the statistics_level parameter to TYPICAL or ALL.

Step 2: Run the ADDM analysis by executing the DBMS_ADDM.analyze_DB


procedure. You can specify the start and end snapshot IDs for the analysis, or use
the default values to analyze the most recent hour.

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:

By Lec. Pratik Chand, Page 11


Elective-Database Administration – CSIT 7th Semester

 DBMS_ADDM.ADDMO_EXCLUDE_CURR_SQL : Exclude the current


SQL statement from analysis
 DBMS_ADDM.ADDMO_EXCLUDE_CURR_PLSQL : Exclude the
current PL/SQL block from analysis
 DBMS_ADDM.ADDMO_EXCLUDE_CURR_JAVA : Exclude the current
Java statement from analysis
 DBMS_ADDM.ADDMO_EXCLUDE_CURR_CALLSTACK : Exclude the
current call stack from analysis
 DBMS_ADDM.ADDMO_USE_AWR_AS_BASELINE : Use AWR as the
baseline for ADDM analysis

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.

Step 4: Implement the recommended actions to resolve the identified performance


issues.

Step 5: Re-run the ADDM analysis to verify the improvements in performance.

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

modifying indexes, materialized views, and partitions to improve query


performance. The SQL Access Advisor can be accessed through the
Enterprise Manager or by using the DBMS_SQLTUNE package.
 Explain Plan: The Explain Plan is a tool that shows the execution plan of a
SQL statement, including the steps the database takes to execute the
statement and the estimated cost of each step. This can be used to identify
any inefficiencies in the execution plan and make adjustments to the SQL
statement or database configuration to improve performance.
 Real-time SQL Monitoring: This feature allows you to monitor the
performance of a running SQL statement and identify any issues that may be
causing poor performance. It can be accessed via the Enterprise Manager or
by using the V$SQL_MONITOR view.
 SQL Trace: SQL Trace is a tool that captures detailed information about a
SQL statement as it is executed. This information can be used to identify
performance bottlenecks and optimize the SQL statement.
 Indexing: Indexes are used to speed up the retrieval of data from tables.
You can create indexes on columns that are frequently searched, sorted or
joined.
 Partitioning: Partitioning is the process of dividing a large table into
smaller, more manageable pieces. This can improve query performance by
allowing the database to scan only the partitions that contain the relevant
data.
 Materialized views: Materialized views are pre-computed views that can be
used to improve query performance. They can be used to pre-aggregate data,
pre-join tables, or pre-filter data.

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.

By Lec. Pratik Chand, Page 13


Elective-Database Administration – CSIT 7th Semester

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. It
can be accessed through the Enterprise Manager or by using the
DBMS_SQLTUNE package.

To use the SQL Tuning Advisor through the Enterprise Manager:

 Log in to the Enterprise Manager


 Navigate to the "Performance" tab and select "SQL Tuning Advisor"
 Select the SQL statement you want to tune and click on "Advise"
 The advisor will analyze the statement and provide recommendations for
improving performance.

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');

-- Execute the tuning task


DBMS_SQLTUNE.EXECUTE_TUNING_TASK(
task_name => 'my_task');

-- Generate a report of the results


DBMS_SQLTUNE.REPORT_TUNING_TASK(
task_name => 'my_task');
END;

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.

By Lec. Pratik Chand, Page 14


Elective-Database Administration – CSIT 7th Semester

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.

Performance tuning in a multi-tenant environment:


Performance tuning in a multi-tenant environment in Oracle involves optimizing
the database resources shared by multiple tenants (users). Here are some steps to
consider:

 Resource allocation: Allocate appropriate system resources such as CPU,


memory, and disk space to each tenant to ensure fair usage and avoid
resource contention.
 Segregate data: Use separate tablespaces and schemas for each tenant to
minimize the impact of data-intensive operations on other tenants.
 Optimize SQL queries: Monitor the performance of SQL queries and tune
them to reduce execution time. Use explain plan, indexing, and partitioning
as needed.
 Monitoring and diagnostics: Use performance monitoring tools like the
Oracle Automatic Workload Repository (AWR) and the Active Session
History (ASH) report to identify performance bottlenecks and resolve them.
 Regular maintenance: Perform regular database maintenance activities
such as updating statistics, rebuilding indexes, and freeing up unused space
to maintain optimal performance.
 Security: Ensure proper security measures are in place to prevent
unauthorized access to tenant data.

These are general steps and the exact tuning approach will depend on the specific
requirements and environment of your database.

Distributed Database and Network Tuning:


Distributed database and network tuning involves optimizing the communication
between database nodes and optimizing network performance. Here are some steps
to consider:

By Lec. Pratik Chand, Page 15


Elective-Database Administration – CSIT 7th Semester

 Network configuration: Configure the network for optimal performance by


using high-speed connections, load balancing, and minimizing latency.
 Database configuration: Configure database nodes to communicate
efficiently by minimizing network traffic and optimizing data transfer
between nodes.
 Query optimization: Monitor and optimize SQL queries that are executed
across multiple nodes in a distributed database to reduce response time.
 Data distribution: Balance the distribution of data across nodes to reduce
network traffic and improve query performance.
 Indexing: Use appropriate indexing strategies to reduce query response time
and minimize network traffic.
 Load balancing: Use load balancing techniques such as round-robin or IP
hash to distribute requests evenly across nodes and reduce response time.
 Monitoring: Use performance monitoring tools to track network and
database performance and identify areas for improvement.

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

By Lec. Pratik Chand, Page 16

You might also like