In this Document
Purpose |
Scope |
Details |
Concepts |
Instance Recovery |
When Oracle Database Performs Instance Recovery |
Instance Recovery Phases |
Cache Recovery |
Transaction Recovery |
Temporary Segment Cleanup |
When does SMON cleanup temporary segments? |
Temporary Segments in a Permanent Tablespace |
Temporary Segments in a Temporary Tablespace |
How to identify whether SMON is cleaning up temporary extents ? |
Effects on Database |
Avoidance |
Force Temp Segment cleanup |
Free Space COALESCE |
Effects: |
To have an overview of SMON process and its functions
Applies to Non RAC environment
The System Monitor Process (SMON) is the most critical background process for Oracle Database.It performs critical tasks such as instance recovery,dead transaction recovery and maintenance tasks such as temporary space reclamation, data dictionary cleanup, and undo tablespace management.
SMON performs many database maintenance tasks, including the following:
SMON checks regularly to see whether it is needed. Other processes can call SMON if they detect a need for it.
Instance recovery ensures that the database is in a consistent state after an instance failure.If an instance of an open database fails, either because of a SHUTDOWN ABORT statement or abnormal termination, then the following situations can result:
Instance recovery uses only online redo log files and current online data files to synchronize the data files and ensure that they are consistent.
Whether instance recovery is required depends on the state of the redo threads. A redo thread is marked open in the control file when a database instance opens in read/write mode, and is marked closed when the instance is shut down consistently. If redo threads are marked open in the control file, but no live instances hold the thread enqueues corresponding to these threads, then the database requires instance recovery.
Oracle Database performs instance recovery automatically in the following situations:
The database opens for the first time after the failure of a single-instance database or all instances of an Oracle RAC database. This form of instance recovery is also called crash recovery. Oracle Database recovers the online redo threads of the terminated instances together.
Some but not all instances of an Oracle RAC database fail. Instance recovery is performed automatically by a surviving instance in the configuration.
The SMON background process performs instance recovery, applying online redo automatically. No user intervention is required.
The first phase of instance recovery is called cache recovery or rolling forward, and involves reapplying all of the changes recorded in the online redo log to the data files. Because rollback data is recorded in the online redo log, rolling forward also regenerates the corresponding undo segments.
Rolling forward proceeds through as many online redo log files as necessary to bring the database forward in time. After rolling forward, the data blocks contain all committed changes recorded in the online redo log files. These files could also contain uncommitted changes that were either saved to the data files before the failure, or were recorded in the online redo log and introduced during cache recovery.
After the roll forward, any changes that were not committed must be undone. Oracle Database uses the checkpoint position, which guarantees that every committed change with an SCN lower than the checkpoint SCN is saved on disk. Oracle Database applies undo blocks to roll back uncommitted changes in data blocks that were written before the failure or introduced during cache recovery. This phase is called rolling back or transaction recovery.
Fig 1: Basic Instance Recovery Steps: Rolling Forward and Rolling Back
Oracle® Database Concepts 11g Release 2 (11.2)
Part Number E25789-01
http://docs.oracle.com/cd/E11882_01/server.112/e25789/startup.htm#CEGCHJGF
Oracle Database often requires temporary workspace for intermediate stages of SQL statement execution. Typical operations that may require a temporary segment include sorting, hashing, and merging bitmaps. While creating an index, Oracle Database also places index segments into temporary segments and then converts them into permanent segments when the index is complete.
Oracle Database does not create a temporary segment if an operation can be performed in memory. However, if memory use is not possible, then the database automatically allocates a temporary segment on disk.
Temporary segments will also be created for the following operations a well.
During normal operations, user processes that create temporary segments are responsible for cleanup. If the user process dies before cleaning them up, or the user process receives an error causing the statement to fail, SMON is posted to do the cleanup.
The background process System Monitor (SMON) frees the temporary segments when the statement has been completed.If a large number of sort segments has been created, then SMON may take some time to drop them; this process automatically implies a loss of overall database performance.After SMON has freed up the temporary segment, the space is released for use by other objects.
The background process SMON actually de-allocates the sort segment after the instance has been started and the database has been opened. Thus, after the database has been opened, SMON may be seen to consume large amounts of CPU as it first de-allocates the (extents from the) temporary segment, and after that performs free space coalescing of the free extents created by the temporary segment cleanup. This behavior will be exaggerated if the temporary tablespace, in which the sort segment resides, has inappropriate (small) default NEXT storage parameters.
Check whether there are a large number of temporary extents that might be being cleaned up by running the following query a few times
If the count returned by the above query is dropping while SMON is working, it is likely that SMON is performing temp segment cleanup.
DROP_SEGMENTS event could be set set to force the cleanup of temporary segments.
This routine does what SMON does in the background, i.e. drops temporary segments. It is provided as a manual intervention tool which the user may invoke if SMON misses the post and does not get to clean the temp segments for another 2 hours.
level - tablespace number+1. If the value is 2147483647 then temp segments in ALL tablespaces are dropped, otherwise, only
segments in a tablespace whose number is equal to the LEVEL specification are dropped.
alter session set events 'immediate trace name DROP_SEGMENTS level TS#+1';ion are dropped.
If ts# is 5, an example of dropping the temporary segments in that tablespace would be:
alter session set events 'immediate trace name DROP_SEGMENTS level 6';
Note 177334.1 Overview of Temporary Segments
Note 35513.1 Removing 'Stray' TEMPORARY Segments
Note 61997.1 SMON - Temporary Segment Cleanup and Free Space Coalescing
NOTE:160426.1 - TEMPORARY Tablespaces : Tempfiles or Datafiles ?
Note 102339.1 Temporary Segments: What Happens When a Sort Occurs
Note 1039341.6 Temporary Segments Are Not Being De-Allocated After a Sort
Note 68836.1 How To Efficiently Drop (or Truncate) A Table With Many Extents
Note 47400.1 EVENT: DROP_SEGMENTS - Forcing cleanup of TEMPORARY segments
Note 132913.1 How To Free Temporary Segment in Temporary Tablespace Dynamically
A free extent in a dictionary-managed tablespace is made up of a collection of contiguous free blocks. When new extents are allocated to a tablespace segment, the database uses the free extent which is closest in size to the required extent.When the segments are dropped,their extents are deallocated and marked a free. It is not combined with adjacent free extents to form a larger free extents.The result is fragmentation that makesallocation of larger extents more difficult.
Fragmentation is addressed such that
The SMON background process periodically coalesces neighboring free extents when the PCTINCREASE value for a tablespace is not zero.
Oracle Database automatically and transparently coalesces the free space of a data block only when the following conditions are true:
After coalescing, the amount of free space is identical to the amount before the operation, but the space is now contiguous.
Fig 2: Datablock before and after the Coalesce
If you set PCTINCREASE=0, no coalescing of free extents occurs. If you are concerned about the overhead of ongoing coalesce operations of SMON, an alternative is to set PCTINCREASE=0, and periodically coalesce free space manually.
Manually Coalesce any adjacent free extens user this command:
SMON wakes itself every 5 minutes and checks for tablespaces with default pctincrease != 0.
If the count returned is dropping while SMON is working, it is likely that SMON is coalescing free space.