Self Tuning of Oracle Database Using SQL Scripts
Self Tuning of Oracle Database Using SQL Scripts
Self Tuning of Oracle Database Using SQL Scripts
net/publication/267712043
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.
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.
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
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
References