Sunday, 16 July 2017



WHAT IS SCN ?? WHERE IT IS STORED ?? TYPES OF SCN ??

 SCN :

             Internal timestamp used by the Oracle Database which is necessary to satisfy the ACID properties of a transaction.

The database uses SCNs to query and track changes

In order to understand SCN purpose in database. First learn how many types of SCN 's exist and their purpose.

Each type of SCN and their location and what they have been called and its purpose
PlacestoredCalled asVisible as columnRelated ViewPurpose
ControlFileSystem SCNcheckpoint
_change#
V$databaseFor recover database using backup control file
ControlFileindividual datafile SCNcheckpoint
_change#
v$datafileWe need this individual SCN for each datafile since there are some datafiles which need recovery due to offline status, this is different from the System SCN above
ControlFileStop SCNlast_change#v$datafileFor Instance Recovery
DatafileStart SCNcheckpoint
_change#
v$datafile_headerThe start of the SCn when the instance started
RedofileHighSCNNext_change#V$log_historyThe last scn recorded in the redo log files.
RedofileLowSCNFIRST_CHANGE#V$logThe oldest recorded SCN from where the next redo log file starts.
BlockBlockSCNEx: scn: 0x0000.
00046911
Dump the block
alter system
dump datafile
3 block min
10 block
max 12;
Every data block also has block SCN (aka block version).  to match up the redo records before applying it
RedofileCommitSCNITL
List header
v$database
current_scn
dbms_flashback.
get_
system_
change_
number
Every commit will generate SCN, aka commit SCN, that marks a transaction boundary.
Redo? PGA? Not sure where it recordsSnapshotSCNWhen a transaction or query begins, the current SCN is recorded. That SCN serves as the snapshot SCN for the query or transactionscn: kcmgss in v$sysstat?

Current SCN from v$database?
When the query starts it has to note down the SCN that current database or block has so that it can report consistent block back




  • Just like a ticker of clock, SCN keep increment at database level via a different background process like AQ, SMON, job queues… etc.
  • A checkpoint number is the SCN number at which all the dirty buffers are written to disk. There can be a checkpoint at object/tablespace/datafile/database level.
  • Whenever a transaction commits (SCN at redo logs as highest SCN (NEXT_CHANGE#) & lowest SCN (FIRST_CHANGE#) get recorded)
  • Whenever a checkpoint occures (SCN get recorded as CHECKPOINT_CHANGE# into database (v$database/system checkpoint) / datafile (v$datafile_header/datafile START SCN) / controlfile (v$datafile/STOP SCN) / Redo entry (v$log/ High SCN & low SCN))
  • SCN also recorded for Slot reserved for transaction in undo segment.
  • By default a block-level SCN is recorded for each block. (Rows sharing same block can be check using ora_rowscn)
In shutdown normal or shutdown immediate,
When happen checkpoint, will SCN wrote four places to go. Three places in the control file, one in datafile header.
1.System checkpoint SCN ===========> (SYSTEM CHECKPOINT SCN in control file)
2.Datafile checkpoint SCN ===============> (DATAFILE CHECKPOINT SCN in control file)
3.Stop SCN ======================> (STOP SCN in control file)
4.Start SCN ================================> (DATAFILE HEADER)
Why CONTROL FILE stored in two places to be divided (SYSTEM CHECKPOINT SCN, DATAFILE CHECKPOINT SCN?) When you put a tbs set to read-only, SCN will freeze to stop him, this time DATAFILE CHECKPOINT SCN is no longer incremental changes, but the overall SYSTEM CHECKPOINT SCN will continue to increase, but still advancing. So, this is why you need are stored in two places SCN.
 Also check out this recovery based articles for more understanding
https://karunadba.blogspot.in/2017/07/difference-between-media-recovery-crash.html

1 comment: