In this Document
APPLIES TO:Oracle Database - Enterprise Edition - Version 9.2.0.8 and laterInformation in this document applies to any platform. PURPOSETo have an overview of SMON process and its functions SCOPEApplies to Non RAC environment DETAILSConceptsThe 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 RecoveryInstance 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. When Oracle Database Performs Instance RecoveryWhether 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 SMON background process performs instance recovery, applying online redo automatically. No user intervention is required. Instance Recovery PhasesCache RecoveryThe 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. Transaction RecoveryAfter 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) http://docs.oracle.com/cd/E11882_01/server.112/e25789/startup.htm#CEGCHJGF
Temporary Segment CleanupOracle 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.
When does SMON cleanup temporary segments?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.
SMON also might get tied up cleaning uncommitted transactions though, and be too busy to process requests to grow an existing sort segment. Starting with Oracle 8i, playing around with fast_start_parallel_rollback might workaround that.In addition, actions like CREATE INDEX create a temporary segment for the index, and only convert it to permanent once the index has been created. Also, DROP <object> converts the segment to temporary and then cleans up the temporary segment.
Temporary Segments in a Permanent TablespaceThe 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. Temporary Segments in a Temporary TablespaceThe 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. How to identify whether SMON is cleaning up temporary extents ?Check whether there are a large number of temporary extents that might be being cleaned up by running the following query a few times
SELECT COUNT(*) FROM DBA_EXTENTS WHERE SEGMENT_TYPE='TEMPORARY';
If the count returned by the above query is dropping while SMON is working, it is likely that SMON is performing temp segment cleanup. Effects on Database
Avoidance
Force Temp Segment cleanupDROP_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. 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
Free Space COALESCEA 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:
ALTER TABLESPACE TABLESPACENAME COALESCE
SMON wakes itself every 5 minutes and checks for tablespaces with default pctincrease != 0.
SELECT COUNT(*) FROM DBA_FREE_SPACE;
If the count returned is dropping while SMON is working, it is likely that SMON is coalescing free space. Effects:
Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents.
Note 61997.1 SMON - Temporary Segment Cleanup and Free Space Coalescing (Doc ID 61997.1)
Note 105120.1 Advantages of Using Locally Managed vs Dictionary Managed Tablespaces
|