Self Tuning of Oracle Database Using SQL Scripts

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/267712043

Self Tuning of Oracle Database Using SQL Scripts

Article · July 2011

CITATIONS READS
0 1,494

3 authors, including:

Pooja Rani
National Institute of Technology Puducherry
4 PUBLICATIONS   54 CITATIONS   

SEE PROFILE

All content following this page was uploaded by Pooja Rani on 25 November 2014.

The user has requested enhancement of the downloaded file.


IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 532

Self Tuning of Oracle Database Using SQL Scripts


Pooja Rani1 , Pariniyojit Kumar Singh2, Hitesh Kumar Sharma3
1
Department of Information Technology, ITM University,
Gurgaon, Haryana, India

Abstract • Database buffer cache


• Redo log buffer
The Oracle professionals or DBA’s should know how to • Shared pool
accurately predict the high-water mark of RAM demands for
• Java pool
their database, and fully allocate the RAM, reserving only
enough to accommodate spikes in user connections. For an • Large pool (optional)
Oracle server, in this paper the goal is to keep all the RAM • Data dictionary cache
memory demands of the database and database connections • Other miscellaneous information
beneath the amount of physical RAM memory. In an Oracle
environment, we can accurately control the amount of RAM
Variable SGA contains 4 main components as listed
memory that is used by the database instance System Global
Area (SGA). This is because the Oracle database above, those are “Database Buffer Cache”, “Redo Log
administrator can issue alter system command to change the Buffer”, “Shared Pool” and “Large Pool”. We call it
RAM memory areas, and can grow and shrink the RAM variable SGA because we can alter the size of each of
memory areas on as needed basis. these components manually using ALTER SYSTEM
command. The size of each of the components of
Keywords: SGA, PGA, DBWn, LGWR, CKPT, SMON variable SGA is determined by INIT.ORA parameters.

Following are the INIT.ORA parameter for each of the


1. Introduction component:

An Oracle database is a combination of oracle Instance • Database Buffer Cache – db_block_buffers


and data files on the file system. Oracle Database = This is used to hold the data into the memory. When
Oracle Instance + Datafiles Again Oracle Instance is ever a user access the data, it gets fetched into database
nothing but Memory architecture and Background buffer cache and it will be managed according to LRU
processes. Oracle database uses memory for its (Least recently used) algorithm.
operation. The total memory allocated to the Oracle • Redo Log Buffer – log_buffer
database can be broadly categorized into SGA (System This memory block hold the data which is going to be
Global Area) and PGA (Program Global Area). written to redo log file.

We can also categorize SGA into fixed SGA and • Shared Pool – shared_pool_size
variable SGA. Fixed SGA is a component of the SGA This contains 2 memory section, 1) Library Cache 2)
that varies in size from platform to platform and release Dictionary Cache.
to release. It is compiled into the database. The fixed
SGA contains a set of variables that point to the other
components of the SGA and variables that contain the • Large Pool – Large_pool_size
values of various parameters. The size of the fixed If defined then used for heavy operations such as bulk
SGA is something over which we have no control and it copy during backup or during restore operation.
is generally very small. Think of this area as a
bootstrap section of the SGA, something Oracle uses The total size of SGA is determined by a p arameter
internally to find the other bits and pieces of the SGA_MAX_SIZE. Below is the simple calculation of
SGA.[1]” memory sizes.

1.1 System Global Area 1.2 Program Global Area

SGA Contains following data structure: PGA contains information about bind variables, sort
areas, and other aspect of cursor handling. This is not a
IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 533

shared area and every user has its own PGA. But why • Read necessary data blocks from datafiles on disk
PGA is required for every user? The reason being that into the shared database buffers of the SGA, if the
even though the parse information for SQL or PLSQL blocks are not already present in the SGA
may be available in library cache of shared pool, the • Return results in such a way that the application can
value upon which the user want to execute the select or process the information
update statement cannot be shared. These values are
stored in PGA. This is also called Private Global II. Background Process - An Oracle instance can have
Area.Database buffer cache is again divided into 3 many background processes; not all are always present.
different types of cache. The background processes in an Oracle instance include
the following: On many operating systems, background
1. Default Cache processes are created automatically when an instance is
2. Keep Cache started.
3. Recycle Cache
Database writer (DBWn) - The database writer
If we define the cache size using DB_CACHE_SIZE process (DBWn) writes the contents of buffers to
(or DB_BLOCK_BUFFER and specify the block size) datafiles. The DBWn processes are responsible for
then this will be default cache. The cache has a limited writing modified (dirty) buffers in the database buffer
size, so not all the data on disk can fit in the cache. cache to disk. Although one database writer process
When the cache is full, subsequent cache misses cause (DBW0) is adequate for most systems, you can
Oracle to write dirty data already in the cache to disk to configure additional processes (DBW1 through DBW9)
make room for the new data to improve write performance if your system modifies
data heavily. These additional DBWn processes are not
2.3 Shared Pool Reserved Size useful on uniprocessor systems.

Shared Pool, as we have seen previously contains the Log Writer (LGWR) – The log writer process
parsed SQL statements and execution plans. With (LGWR) is responsible for redo log buffer
continuous use of database, after a p eriod of time the management–writing the redo log buffer to a redo log
shared pool will get fragmented. New parsed SQL and file on disk. LGWR writes all redo entries that have
execution plans comes and old one gets aged out and been copied into the buffer since the last time it wrote.
hence overwritten. This will also lead to larger
packages being aged out with new entries going into Checkpoint (CKPT) - When a checkpoint occurs,
shared pool. Hence access to such larger packages will Oracle must update the headers of all datafiles to record
take time to parse and create execution plan. This might the details of the checkpoint. This is done by the CKPT
cause performance issues. To avoid such situation, you process. The CKPT process does not write blocks to
can define ap arameter disk; DBWn always performs that work.
SHARED_POOL_RESERVED_SIZE. This will
reserve some additional space other then System Monitor (SMON) – The system monitor
shared_pool_size[2]. process (SMON) performs crash recovery, if
necessary, at instance startup. SMON is also
2. Process Architecture responsible for cleaning up temporary segments that are
no longer in use and for coalescing contiguous free
Oracle has several process running in the background extents within dictionary-managed tablespaces. If any
for proper functioning of database. Following are the dead transactions were skipped during crash and
main categories of process. instance recovery because of file-read or offline errors,
SMON recovers them when the tablespace or file is
brought back online. SMON wakes up regularly to
I. Server Process – to handle the requests of user check whether it is needed.
processes connected to the instance. Server processes
(or the server portion of combined user/server
processes) created on behalf of each user’s application Process Monitor (PMON) -The process monitor
can perform one or more of the following: (PMON) performs process recovery when a user
process fails. PMON is responsible for cleaning up the
database buffer cache and freeing resources that the
• Parse and execute SQL statements issued through the user process was using. For example, it resets the status
application of the active transaction table, releases locks, and
IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 534

removes the process ID from the list of active 4. Oracle 9i Scripts


processes.
The goal for an oracle server is to keep the RAM
Archiver Process (ARCn) -The archiver process memory demands of the database and database
(ARCn) copies online redo log files to a designated connections below the amount of physical RAM
storage device after a l og switch has occurred. ARCn memory. We can control the amount of the RAM used
processes are present only when the database is in by the database SGA in an oracle environment by
ARCHIVELOG mode, and automatic archiving is issuing alter system commands.
enabled.An Oracle instance can have up to 10 ARCn
processes (ARC0 to ARC9). The LGWR process starts SCRIPT 1
a new ARCn process whenever the current number of A quick dictionary query (sc1.sql) against the
ARCn processes is insufficient to handle the workload. v$parameter view will yield the correct for each PGA
The ALERT file keeps a record of when LGWR starts a RAM region size.
new ARCn process.
set pages 999;
column pga_size format 999,999,999
Lock Manager Server (LMS) - In Oracle9i Real select 2048576+a.value+b.value pga from
Application Clusters, a L ock Manager Server process v$parameter a, v$parameter b where
(LMS) provides inter-instance resource management. a.name=’sort_area_size’ and
b.name=’hash_area_size’
The data dictionary query output shows that the Oracle
Queue Monitor (QMNn) – The queue monitor
PGA will use 3.6 megabytes of RAM for each
process is an optional background process for Oracle
connected Oracle session.
Advanced Queuing, which monitors the message
queues. You can configure up to 10 queue monitor
PGA
processes. These processes, like the Jnnn processes, are
3,621,440
different from other Oracle background processes in
If we now multiply the number of connected users of
that process failure does not cause the instance to
the PGA demands for each user, we will know exactly
fail.[3]
how much RAM should be reserved for connected
sessions.
3. Implementation of Proposed System

The primary goal for an Oracle server is to keep the SCRIPT 2


RAM memory demands of the database and the Computing total PGA RAM
database connection below the amount of physical Ram This script reads both the sort_area_size and
memory. We can control the amount of RAM used by hash_area_size to compute the total PGA region.This
the database SGA in an Oracle environment by issuing script will display a prompt for the high water mark of
alter system commands. Let’s take a closer look at these connected users and then computes the total PGA RAM
new Oracle9i features and scripts, which allow you to to reserve for dedicated oracle connections.The MS-
see detailed RAM memory usage. Windows PGA session incurs a 2MB overhead in this
example.
3.1 Algorithm Sc2.sql
---------------------
Compute PGA sizes
It defines three variables: ∆RT abbreviates for change set pages 999;
in response time, BUFFER_SIZE denotes the current column pga_size format 999,999,999
size of buffer, CACHE_SIZE corresponds to the size of accept hwm number prompt ‘Enter the high-water mark
cache memory of connected users:’
ALGORITHM
select &hwm*(2048576+a.value+b.value) pga from
1. dbTuner (ESTIMATED_CACHE_SIZE)
v$parameter a, v$parameter b
2. Begin
3. Run application, algorithm and process
where = a.name ’sort_area_size’ and
4.
5.
Calculate the change in response time (∆RT)
If (∆RT>0)
b.name=’hash_area_size’
{
Run Script
Running the script,we see that we are prompted for the
{
BUFFER_SIZE = BUFFER_SIZE + 1
high water mark.we will assume that the HWM of
}
Allocate more RAM and update CACHE_SIZE connected sessions to the oracle database server is
Else IF (∆RT<0)
{
100.Oracle will do the math and display the amount of
Run Script
{
RAM to reserve for oracle connections.
BUFFER_SIZE = BUFFER_SIZE - 1
Reduce RAM and update CACHE_SIZE
}
}
6. Go To Step 4
6. Stop application, algorithm and process
7. End
IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 535

SQL>@Sc2 @Sc3

Enter the high water mark of connected users:100 ************** OUTPUT *************
Old 2: &hwm*(2048576+a.value+b.value)pga_size SQL> @Sc3
New 2:100*(2048576+a.value+b.value) pga_size Enter cache to decrease: shared_pool_size
PGA Enter cache to increase: db_cache_size
------------------ Enter amount to change: 2048576
362,144,000
Returning to our example Windows server, we are alter system set shared_pool_size = 39283072;
ready to calculate the optimum SGA size. Multiplying System altered.
100 by the amount needed for each PGA region(3.62 alter system set db_cache_size = 27825792;
MB) and adding the 2 MB PGA overhead, gives us System altered.
the total PGA size of 3 64 MB.The maximum size for This script prompts the DBA for the name of the cache
the SGA is determined by subtracting the total PGA and the sizes and issues the proper appropriate alter
and the OS overhead from the total RAM on the server. system commands to adjust the regions.
Here is a summary:
Total RAM on Windows Server 1250 MB Less:
Total PGA regions for 100 users: SCRIPT 4
364 MB Script provides us with DBHR
RAM reserved for Windows(20%) column bhr format 9.99
250 MB column mydate heading 'yr. mo dy Hr.'
select
________________ to_char(snap_time,'yyyy-mm-dd HH24') mydate,
Maximum SGA size new.name buffer_pool_name,
636 MB (((new.consistent_gets-old.consistent_gets)+
This leaves 636 MB of free memory for the SGA. (new.db_block_gets-old.db_block_gets))-
Therefore, the RAM allocated to the data buffers should (new.physical_reads-old.physical_reads))
be adjusted to make the SGA size less than 636 MB, the / ((new.consistent_gets-old.consistent_gets)+
server will begin to page RAM, impairing the (new.db_block_gets-old.db_block_gets)) bhr
performance of the entire server. from
perfstat.stats$buffer_pool_statistics old,
SCRIPT 3 perfstat.stats$buffer_pool_statistics new,
Script that adjusts the RAM caches perfstat.stats$snapshot sn
where
set heading off (((new.consistent_gets-old.consistent_gets)+
set feedback off (new.db_block_gets-old.db_block_gets))-
set verify off (new.physical_reads-old.physical_reads))
accept decrease_pool char prompt 'Enter cache to / ((new.consistent_gets-old.consistent_gets)+
decrease: ' (new.db_block_gets-old.db_block_gets)) < .90
accept increase_pool char prompt 'Enter cache to and
increase: ' new.name = old.name
accept change_amount number prompt 'Enter amount to and
change: ' new.snap_id = sn.snap_id
spool Sc3.sql and
select old.snap_id = sn.snap_id-1;
'alter system set &decrease_pool =
'||to_char(to_number(value)-&change_amount)||';' **************** OUTPUT **************
from v$parameter where name = Here is a sample of the output from this script:
lower('&decrease_pool'); SQL> @Sc4
select yr. mo dy Hr BUFFER_POOL_NAME BHR
'alter system set &increase_pool =
'||to_char(to_number(value)+&change_amount)||';' ------------- -------------------- -----
from v$parameter where name = 2011-02-12 15 DEFAULT .94
lower('&increase_pool'); 2011-02-12 15 KEEP .98
spool off 2011-02-12 15 RECYCLE .84
set feedback on 2011-02-12 16 DEFAULT .91
IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 536

2011-02-12 16 KEEP .96 when object_type = 'INDEX PARTITION' then


2011-02-12 16 RECYCLE .68 'IDX PART'
else object_type end c2,
This script provides us with data buffer hit ratio for sum(num_blocks) c3,
each of the buffer pools at one hour intervals. It is (sum(num_blocks)/greatest(sum(blocks), .001))*100
important that the KEEP pool always has a 99-100 % c4,
DBHR. If this is not the case, data blocks should be to buffer_pool c5,
the KEEP pool to make it the same size as the sum of sum(bytes)/sum(blocks) c6
all object data blocks that are assigned to the KEEP from
pool. t1,
dba_segments s
SCRIPT 5 where
Script provides us with the contents of data buffers s.segment_name = t1.object_name
set pages 999 and
set lines 92 s.owner = t1.owner
ttitle 'Contents of Data Buffers' and
drop table t1; s.segment_type = t1.object_type
create table t1 as and
select nvl(s.partition_name,'-') = nvl(t1.subobject_name,'-')
o.owner owner, group by
o.object_name object_name, t1.owner,
o.subobject_name subobject_name, object_name,
o.object_type object_type, object_type,
count(distinct file# || block#) num_blocks buffer_pool
from having
dba_objects o, sum(num_blocks) > 10
v$bh bh order by
where sum(num_blocks) desc;
o.data_object_id = bh.objd
and * ******* OUTPUT *******************
o.owner not in ('SYS','SYSTEM')
and
bh.status != 'free' 5. Conclusion & Future work
group by
o.owner,
o.object_name, Tuning the database can become quite complex, but
o.subobject_name, Oracle9i offers the administrator and unparalleled
o.object_type ability to control the PGA and SGA. Until Oracle9i
order by evolves into a completely self-tuning architecture, the
count(distinct file# || block#) desc; DBA will be responsible for adjusting the dynamic
column c0 heading "Owner" format a12 configuration of the system RAM. It is intended to give
column c1 heading "Object|Name" format a30 the DBA a high-level overview of the silent features
column c2 heading "Object|Type" format a8 involved in scheduling dynamic reconfigurations within
column c3 heading "Number of|Blocks Oracle. In the future, we may expect complete self-
in|Buffer|Cache" format 99,999,999 tuning databases to emerge, but in the meantime the
column c4 heading "Percentage|of object|blocks administrator must track the historical behavior of the
in|Buffer" format 999 database and apply it to predictive models. It is only in
column c5 heading "Buffer|Pool" format a7 this way that scare instance resources can be
column c6 heading "Block|Size" format proactively applied to develop an optimally-tuned
99,999 Oracle database. As people get more sophisticated in
select their self-tuning endeavors, many more Oracle metrics
t1.owner c0, may become self-tuning. For example, there are dozens
object_name c1, of self-tuning parameters that are considered immutable
case when object_type = 'TABLE PARTITION' then that may be found to be changeable. As an example,
'TAB PART' let’s consider the optimizer_index_cost_adj parameter.
IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 2, July 2011
ISSN (Online): 1694-0814
www.IJCSI.org 537

References

[1] loannis Alagiannis (DIAS, I&C, EPFL) ,Towards


Adaptive, Flexible, and Self-tuned database system
by in EDIC-ru/05.05.2009.
[2] Foundations of Automated Database Tuning by
VLDB ‘06, September 12– 15, 2006, Seoul,
Korea.Copyright 2006 VLDB Endowment, ACM
[3] Rethinking Database System Architecture: Towards
a Self-tuning RISC-style Database System in Cairo,
Egypt, 2000
[4] AutoAdmin: Self-Tuning Database Systems
Technology, Copyright 2006 IEEE
[5] Self-Tuning Database Systems: A Decade of
Progress, Copyright 2007 VLDB Endowment
[6] Automatic Physical Database Tuning: A relaxation
based Approach, Copyright 2005
[7] SQL Memory Management in Oracle9i,Hong Kong,
China, 2002
[8] Self-Tuning for SQL Performance in Oracle
Database 11g. 2009 IEEE 25th International
Conference on Data Engineering

View publication stats

You might also like