Professional Documents
Culture Documents
0 The transation %og is 1sed to g1arantee the data integrit" of the database and
for data reo!er".
0 The transation %og in a database ma)s o!er one or more )h"sia% @%es.
;one)t1a%%"( the %og @%e is a string of %og reords. ,h"sia%%"( the se81ene of %og
reords is stored eAient%" in the set of )h"sia% @%es that im)%ement the
transation %og.
0 The SQL Ser!er Database ?ngine di!ides eah )h"sia% %og @%e interna%%" into a
n1mber of !irt1a% %og @%es. Birt1a% %og @%es ha!e no @4ed si/e( and there is no @4ed
n1mber of !irt1a% %og @%es for a )h"sia% %og @%e. The Database ?ngine hooses the
si/e of the !irt1a% %og @%es d"namia%%" whi%e it is reating or e4tending %og @%es. The
si/e or n1mber of !irt1a% %og @%es annot be on@g1red or set b" administrators.
0 The on%" time !irt1a% %og @%es aCet s"stem )erformane is if the %og @%es are
de@ned b" sma%% size and growth_increment !a%1es. 3f these %og @%es grow to a %arge
si/e bea1se of man" sma%% inrements( the" wi%% ha!e %ots of !irt1a% %og @%es. This
an s%ow down database start1) and a%so %og bak1) and restore o)erations. De
reommend that "o1 assign %og @%es a size !a%1e %ose to the @na% si/e re81ired( and
a%so ha!e a re%ati!e%" %arge growth_increment !a%1e.
0 The transation %og is a wra)0aro1nd @%e. 2or e4am)%e( onsider a database with
one )h"sia% %og @%e di!ided into fo1r !irt1a% %og @%es. Dhen the database is reated(
the %ogia% %og @%e begins at the start of the )h"sia% %og @%e. .ew %og reords are
added at the end of the %ogia% %og and e4)and toward the end of the )h"sia% %og.
Log tr1nation frees an" !irt1a% %ogs whose reords a%% a))ear in front of the
minim1m reo!er" %og se81ene n1mber 6-inLS.7. The MinLSN is the %og se81ene
n1mber of the o%dest %og reord that is re81ired for a s1essf1% database0wide
ro%%bak.
#hec$%oints and the "cti&e !ortion of the 'og
0 ;hek)oints E1sh dirt" data )ages from the b1Cer ahe of the 1rrent database
to disk. This minimi/es the ati!e )ortion of the %og that m1st be )roessed d1ring a
f1%% reo!er" of a database. D1ring a f1%% reo!er"( the fo%%owing t")es of ations are
)erformed:
The %og reords of modi@ations not E1shed to disk before the s"stem
sto))ed are ro%%ed forward.
A%% modi@ations assoiated with inom)%ete transations( s1h as
transations for whih there is no ;5--3T or R5LL9A;F %og reord( are ro%%ed
bak.
#hec$%oint (%eration
A hek)oint )erforms the fo%%owing )roesses in the database:
Drites a reord to the %og @%e( marking the start of the hek)oint.
Stores information reorded for the hek)oint in a hain of hek)oint %og
reords.
5ne )iee of information reorded in the hek)oint is the %og se81ene
n1mber 6LS.7 of the @rst %og reord that m1st be )resent for a s1essf1%
database0wide ro%%bak. This LS. is a%%ed the -inim1m Reo!er" LS.
6-inLS.7.
3f the database 1ses the sim)%e reo!er" mode%( marks for re1se the s)ae
that )reedes the -inLS..
Drites a%% dirt" %og and data )ages to disk.
Drites a reord marking the end of the hek)oint to the %og @%e.
Drites the LS. of the start of this hain to the database boot )age.
The hek)oint reords a%so ontain a %ist of a%% the ati!e transations that ha!e
modi@ed the database.
"cti&ities That #ause a #hec$%oint
;hek)oints o1r in the fo%%owing sit1ations:
A ;G?;F,53.T statement is e4)%iit%" e4e1ted. A hek)oint o1rs in the
1rrent database for the onnetion.
A minima%%" %ogged o)eration is )erformed in the database< for e4am)%e( a
b1%k0o)" o)eration is )erformed on a database that is 1sing the 91%k0Logged
reo!er" mode%.
Database @%es ha!e been added or remo!ed b" 1sing ALT?R DATA9AS?.
An instane of SQL Ser!er is sto))ed b" a SG>TD5D. statement or b"
sto))ing the SQL Ser!er 6-SSQLS?RB?R7 ser!ie. ?ither ation a1ses a
hek)oint in eah database in the instane of SQL Ser!er.
An instane of SQL Ser!er )eriodia%%" generates a1tomati hek)oints in
eah database to red1e the time that the instane wo1%d take to reo!er the
database.
A database bak1) is taken.
An ati!it" re81iring a database sh1tdown is )erformed. 2or e4am)%e(
A>T5H;L5S? is 5. and the %ast 1ser onnetion to the database is %osed( or
a database o)tion hange is made that re81ires a restart of the database.
)rite"head Transaction 'og
0 SQL Ser!er 1ses a write0ahead %og 6DAL7( whih g1arantees that no data
modi@ations are written to disk before the assoiated %og reord is written to disk.
This maintains the A;3D )ro)erties for a transation.
0 SQL Ser!er maintains a b1Cer ahe into whih it reads data )ages when data
m1st be retrie!ed. Data modi@ations are not made diret%" to disk( b1t are made to
the o)" of the )age in the b1Cer ahe. The modi@ation is not written to disk 1nti%
a hek)oint o1rs in the database( or the modi@ation m1st be written to disk so
the b1Cer an be 1sed to ho%d a new )age. Driting a modi@ed data )age from the
b1Cer ahe to disk is a%%ed E1shing the )age. A )age modi@ed in the ahe( b1t
not "et written to disk( is a%%ed a dirty page.
0 At the time a modi@ation is made to a )age in the b1Cer( a %og reord is b1i%t in
the %og ahe that reords the modi@ation. This %og reord m1st be written to disk
before the assoiated dirt" )age is E1shed from the b1Cer ahe to disk. 3f the dirt"
)age is E1shed before the %og reord is written( the dirt" )age reates a
modi@ation on the disk that annot be ro%%ed bak if the ser!er fai%s before the %og
reord is written to disk. SQL Ser!er has %ogi that )re!ents a dirt" )age from being
E1shed before the assoiated %og reord is written. Log reords are written to disk
when the transations are ommitted.
'og File "rchitecture in S*' Ser&er
Whenever any query is processed, the data will be passed to Data file. Below is the process how
a query is processed in SQL Server/ Iportance of Lo! "ile #rchitecture$
Database has Data @%e and Log @%e.
The 81er" statement is )assed to the b1Cer ahe and %og ahe.
The data in the b1Cer ahe is a%%ed as Dirt" Data or Dirt" 9%oks.
91Cer ahe ontains the dirt" data 6the 1)dated data orres)onding to the
81er" gi!en in the a))%iation7.
The )roess of writing the data from b1Cer ahe to the data @%es of the
database in the form of h1nks is
a%%ed as ;hek)oint ,roess.
?ah h1nk ontains '1# F9.
The 81er" is written into the %og @%e from the %og ahe.
3f an" t")e of fai%1re o1rs whi%e writing data to the data @%e( then the 81er"
in the %og @%e is e4e1ted at the %ast ommit transation )roessed 6refer
ommit )roess down7 and the remaining data is written to the database
whene!er we start the ser!er.
This )roess of writing data to the database after a fai%1re from the %og @%e is
a%%ed as Reo!er".
,roed1re ;ahe ontains the e4e1tion )%an.
;onte4t ;ahe ontains the data of the stored )roed1re.
Ser!er Le!e% Data Str1t1re ontains the Ser!er %e!e% information.
Commit Process:
o As soon as ommit statement is written to the %og @%e it throws a token
to the 1ser that ommit is om)%eted s1essf1%%" 6?4. 1 row aCeted7(
this )roess is a%%ed as ;ommit ,roess.
Ty%es of isolation le&els in S*' Ser&er
Read ;ommitted
SQL Ser!er a81ires a share %ok whi%e reading a row into a 1rsor b1t frees
the %ok immediate%" after reading the row. 9ea1se shared %ok re81ests are
b%oked b" an e4%1si!e %ok( a 1rsor is )re!ented from reading a row that
another task has 1)dated b1t not "et ommitted. Read ommitted is the
defa1%t iso%ation %e!e% setting for both SQL Ser!er and 5D9;.
Read >nommitted
SQL Ser!er re81ests no %oks whi%e reading a row into a 1rsor and honors no
e4%1si!e %oks. ;1rsors an be )o)1%ated with !a%1es that ha!e a%read" been
1)dated b1t not "et ommitted. The 1ser is b")assing a%% of the %oking
transation ontro% mehanisms in SQL Ser!er.
Re)eatab%e Read
SQL Ser!er re81ests a shared %ok on eah row as it is read into the 1rsor as
in R?AD ;5--3TT?D( b1t if the 1rsor is o)ened within a transation( the
shared %oks are he%d 1nti% the end of the transation instead of being freed
after the row is read. So )hantom rows are This has the same eCet as
s)eif"ing G5LDL5;F on a S?L?;T statement.
(!hantom read+,hantom reads o1rs when an insert or de%ete ation is
)erformed against a row that is being read b" a transation.The seond
transation read shows a row that did not e4ist in the origina% read as the
res1%t of an insertion b" a diCerent transation or d1e to de%etion o)eration
some rows doesnIt a))ear7
Seria%i/ab%e
3n seria%i/ab%e read )hantom reads are not a%%owed bea1se whi%e the @rst
transation is in )rogress other transation wont e4e1te.
Sna)shot
SQL Ser!er re81ests no %oks whi%e reading a row into a 1rsor and honors no
e4%1si!e %oks. ;1rsor is )o)1%ated with the !a%1es as of the time when the
transation @rst started. Sro%% %oks are sti%% re81ested regard%ess of 1se of
sna)shot iso%ation.
Read uncommitted e,am%le+
>nommitted Read a%%ows "o1r transation to read an" data that is 1rrent%"
on a data )age( whether that has been ommitted or not. 2or
e4am)%e(another 1ser might ha!e a transation in )rogress that has 1)dated
data( and e!en tho1gh itIs ho%ding e4%1si!e %oks on the data( "o1r
transation an read it an"wa".