BC0050 Oracle & Distributed Databases 4 Credits (Book ID: B0894) Assignment Set 1 (40 Marks) Answer all the questions 4 x 10 = 40 1. rite a !"#S$" co%e for fin% Sum of & num'ers usin( )*"+ "oop set serveroutput on; declare n number ! "n; a number ; b number ; begin a ! 1; b ! 0; #$ile(a %! n) loop b ! b & a; a ! a&1; end loop; dbms'output(put'line()sum o*natural numbers)++b); end; ,. -ifferentiate 'etween !"#S$" functions an% proce%ures. 1( ,unction is mainl- used in t$e case #$ere it must return a value( .$ere as a procedure ma- or ma- not return a value or ma- return more t$an one value using t$e /01 parameter( 2( ,unction can be called *rom S23 statements #$ere as procedure can not be called *rom t$e s4l statements 5( ,unctions are normall- used *or computations #$ere as procedures are normall- used *or e6ecuting business logic( 4( 7ou can $ave DM3 (insert update delete) statements in a *unction( 8ut -ou cannot call suc$ a *unction in a S23 4uer- 9( ,unction returns 1 value onl-( :rocedure can return multiple values (ma6 1024)( ;( Stored :rocedure supports de*erred name resolution( <6ample #$ile #riting a stored procedure t$at uses table named tabl1 and tabl2 etc(( but actuall- not e6ists in database is allo#ed onl- in during creation but runtime :age 1 t$ro#s error ,unction #ont support de*erred name resolution( =( Stored procedure returns al#a-s integer value b- de*ault >ero( #$ere as *unction return t-pe could be scalar or table or table values ?( Stored procedure is precompiled e6ecution plan #$ere as *unctions are not( @( A procedure ma- modi*- an obAect #$ere a *unction can onl- return a value 1$e B<10BC statement immediatel- completes t$e e6ecution o* a subprogram and returns control to t$e caller( .. -raw a %ia(ram of oracle architecture an% explain it 'riefl/. 1$e /racle server consists o* p$-sical *iles and memor- components( 1$e /racle @i Database product is made up t$ree main components namel- 1( 0he 1racle Ser2er 1$is is t$e /racle database management s-stem t$at is able to storeD manage and manipulate data( Et consists o* all t$e *ilesD structuresD processes t$at *orm /racle Database @i( 1$e /racle server is made up o* an /racle instance and an /racle database( 2( 0he 1racle *nstance Fonsists o* t$e memor- components o* /racle and various background processes( 5( 0he 1racle %ata'ase 1$is is t$e centrali>ed repositor- #$ere t$e data is stored( Et $as a p$-sical structure t$at is visible to t$e /perating s-stem made up o* operating s-stem *iles and a logical structure t$at is recogni>ed onl- t$e /racle Server( 1$e *igure 5(1 displa-s t$e arc$itecture o* t$e /racle Database @i( Et is broadl- divided into t$e memor- components #$ic$ *orm t$e /racle instance and t$e p$-sical database components #$ere di**erent kinds o* data are stored( :age 2 4. -raw the %ia(ram of lo(ical structure of oracle %ata'ase an% explain it in 'rief. ,ig belo# s$o#s t$e logical structure o* oracle database( :age 5
1$e /racle database is divided into increasingl- smaller logical units to manageD storeD and retrieve datae**icientl- and 4uickl-( 1$e *igure s$o#s t$e relations$ips bet#een t$e logical structures o* t$e database( 3ogical structure mainl- consists o* tablespaceDsegmentsDe6tentsD andoracle data blocks 1A83<S:AF< <ac$ database is logicall- divided into one or more tablespaces ( /ne or more data*iles are e6plicitl-created *or eac$ tablespace to p$-sicall- store t$e data o* all logical structures in a tablespace( 1$ecombined si>e o* t$e data*iles in a tablespace is t$e total storage capacit- o* t$e tablespace( S<GM<C1 A segment is a set o* e6tents allocated *or a certain logical structure( 1$e segments can be o* one o* *ollo#ing t-pe data segmentD inde6 segmentD temporar- segmentD rollback segment( :age 4 <H1<C1 1$e ne6t level o* logical database space is an e6tent( An e6tent is a speci*ic number o* contiguous datablocksD obtained in a single allocationD and used to store a speci*ic t-pe o* in*ormation( /BAF3< DA1A83/FIS At t$e *inest level o* granularit-D /racle database data is stored in data blocks( /ne data blockcorresponds to a speci*ic number o* b-tes o* p$-sical database space on disk( 1$e standard block si>e isspeci*ied b- t$e D8'83/FI'SEJ< initiali>ation parameter( En additionD -ou can speci*- up to *ive ot$erblock si>es :age 9 December 2011 Bachelor of Computer Application (BCA) Semester 4 BC0050 Oracle & Distributed Databases 4 Credits (Book ID: B0894) Assignment Set 2 (40 Marks) Answer all the questions 4 x 10 = 40 1. -iscuss the o'3ecti2es of $uer/ !rocessin(. 1$e main obAectives o* 4uer- processing in a distributed environment is to *orm a $ig$ level4uer- on a distributed databaseD #$ic$ is seen as a single database b- t$e usersD into an e**iciente6ecution strateg- e6pressed in a lo# level language on local databases(K An important point o* 4uer- processing is 4uer- optimi>ation( 8ecause man- e6ecution strategiesare correct trans*ormations o* t$e same $ig$Llevel 4uer-D t$e one t$at optimi>es (minimi>es)resource consumption s$ould be retained(K 1$e good measures o* resource consumption are 1$e total cost t$at #ill be incurred in processing t$e 4uer-( Et is t$e some o* all times incurred in processing t$e operations o* t$e 4uer- at various sites and intrinsic communication( 1$e resource time o* t$e 4uer-( 1$is is t$e time elapsed *or e6ecuting t$e 4uer-( Since operations can be e6ecuted in parallel at di**erent sitesD t$e response time o* a 4uer- ma- be signi*icantl- less t$an its cost(K /bviousl- t$e total cost s$ould be minimi>ed( En a distributed s-stemD t$e total cost to be minimi>ed includes F:0D EM/D and communication costs( 1$ese costs can be minimi>ed b- reducing t$e number o* EM/ operations t$roug$ *ast access met$ods to t$e data and e**icient use o* main memor-( 1$e communication cost is t$e time needed *or e6c$anging t$e data bet#een sites participating in t$e e6ecution o* t$e 4uer-( En centrali>ed s-stemsD onl- F:0 and EM/ cost $ave to be considered 2( -iscuss the 4eatures of the )etero(eneous Ser2ices. 1$e *ollo#ing are t$e *eatures o* Neterogeneous Services( Cot all *eatures listed belo# are necessaril- supported b- -our Neterogeneous Services agent or /racle Gate#a-( 1( Distributed 1ransactions A transaction can span bot$ /racle and nonL /racle s-stemsD #$ile still guaranteeingD t$roug$ /racleOs t#o p$ase commit mec$anismD t$at c$anges are eit$er all committed or all rolled back( :age 1 2( 1ransparent S23 access Entegrate data *rom nonL/racle s-stems into t$e /racle environment as i* t$e data is stored in one singleD local database( S23 statements issued b- t$e application are transparentl- trans*ormed into S23 statement understood b- t$e nonL/racle s-stem 5( :rocedural Access :rocedural s-stemsD like messaging and 4ueuing s-stemsD are accessed*rom an /racle@i server using :3MS23 remote procedure calls( 4( Data Dictionar- translations 1o make t$e nonL/racle s-stem appear as anot$er /racle serverD S23 statements containing re*erences to /racle)s data dictionar- tables are trans*ormed into S23 statements containing re*erences to a nonL/racle s-stemOs data dictionar- tables( 9( :assLt$roug$ S23 /ptionall-D application programmers can directl- access a nonL/racle s-stem *rom an /racle application using t$e nonL/racle s-stemOs S23 dialect( ;( Accessing stored procedures Stored procedures in S23Lbased nonL /racle s-stems are accessed as i* t$e- #ere :3MS23 remote procedures( =( Cational 3anguage Support Neterogeneous Services supports multiLb-te c$aracter setsD and translate c$aracter sets bet#een a nonL/racle s-stem and t$e /racle@i server( ?( MultiL1$readed Agents MultiLt$readed agents take advantage o* -our operating s-stem)s t$reading capabilities( MultiLt$readed agents reduce t$e number o* re4uired processes b- taking advantage o* multiLt$readed server capabilities( @( Agent Sel*LBegistration Agent sel*Lregistration automates t$e process o* updating Neterogeneous Services con*iguration data on remote $ostsD ensuring correct operation over $eterogeneous database links( 10( Management Enter*ace :rovides a grap$ic representation o* active Neterogeneous Services agents and o* #$ic$ user sessions are accessing t$ose agents( .. +xplain the steps in2ol2e% in reco2er/ of %istri'ute% transactions. 1$e issue o* recover- mec$anism is important in t$e case o* revoking t$e s-stem to per*orm normal database operations a*ter a *ailure( 1$usD be*ore discussing about recover-D let us *irst anal->e about t$e di**erent kinds o* *ailure t$at can occur in a centrali>ed database( Co# let us consider recover- problems in distributed databases( ,or t$is purposeD let us assume t$at at eac$ site a 3ocal 1ransaction Manager is available( <ac$ agent can issue begin'transactionD commitD and abort primitives to its 31M( :age 2 A*ter $aving issued a begin'transaction to its 31MD an agent #ill possess t$e properties o* a local transaction( .e #ill call an agent t$at $as issued a begin'transaction primitive to its local transaction manager a SubLtransaction( Also to distinguis$ t$e begin'transactionD commitD and abort primitives o* t$e distributed transaction *rom t$e local primitives issued b- eac$ agent to its 31MD #e #ill call t$e later as local'beginD local'commitD and local'abort( ,or building a Distributed 1ransaction Manager (D1M)D t$e *ollo#ing properties are e6pected *rom t$e 31M <nsuring t$e atomicit- o* subLtransaction .riting some records on stable storage on be$al* o* t$e distributed transaction manager .e need t$e second re4uirementD as some additional in*ormation must also be recorded in suc$ a#a- t$at t$e- can be recovered in case o* *ailure( En order to make sure t$at eit$er all actions o* a distributed transaction are per*ormed or none is per*ormed at allD t#o conditions are necessar- At eac$ site eit$er all actions are per*ormed or none is per*ormed All sites must take t$e same decision #it$ respect to t$e commitment or abort o* sub transaction( :age 5 8egin'transaction .$en it is issued b- t$e root agentD D1M #ill $ave to issue a local'begin primitive to t$e 31M at t$e site o* origin and all t$e sites at #$ic$ t$ere are alread- active agents o* t$e same applicationD t$us trans*orming all agents into subLtransactions; *rom t$is time on t$e activation o* a ne# agent b- t$e same distributed transaction re4uires t$at t$e local'begin be issued to t$e 31M #$ere t$e agent is activatedD so t$at t$e ne# agent is created as a SubL transaction( 1$e e6ample o* ,0CD 1BACS,<B is taken *or e6plaining t$is concept( 1$e *ig ?(1 e6plains t$is( Abort .$en an abort is issued b- t$e root agentD all e6isting subLtransactions must be aborted( Essuing local'aborts to t$e 31Ms at all sites #$ere t$ere is an active sub transaction per*orms t$is( Fommit 1$e implementation o* t$e commit primitive is t$e most di**icult and e6pensive( 1$e main di**icult- originates *rom t$e *act t$at t$e correct commitment o* a distributed transaction re4uires t$at al subLtransactions commit locall- even i* t$ere are *ailures( :age 4 En order to implement t$is primitive *or a distributed transactionD t$e general idea o* 2L:$ase commit :rotocol $as been developed( Et is discussed in detail in t$e ne6t section( 4( hat are the %ifferent 0rou'leshootin( pro'lems in -istri'ute% 0ransaction5 A net#ork or s-stem *ailure can cause t$e *ollo#ing t-pes o* problems A t#oLp$ase commit being processed #$en a *ailure occurs ma- not be completed at all nodes o* t$e session tree( E* a *ailure persists (*or e6ampleD i* t$e net#ork is do#n *or a long time)D t$e data e6clusivel- locked b- inLdoubt transactions is unavailable to statements o* ot$er transactions( 1$e *ollo#ing sections describe t$ese situations( 4ailures that *nterrupt 0wo6!hase Commit 1$e user program t$at commits a distributed transaction is in*ormed o* a problem b- one o* t$e *ollo#ing error messages A robust application s$ould save in*ormation about a transaction i* it receives an- o* t$e above errors( 1$is in*ormation can be used later i* manual distributed transaction recover- is desired( 4ailures that !re2ent -ata Access .$en a user issues a S23 statementD /racle@i attempts to lock t$e re4uired resources to success*ull- e6ecute t$e statement( No#everD i* t$e re4uested data is currentl- being $eld b- statements o* ot$er uncommitted transactions and continues to remain locked *or an e6cessive amount o* timeD a timeLout occurs( 0ransaction 0ime61ut A DM3 S23 statement t$at re4uires locks on a remote database ma- be blocked *rom doing so i* anot$er transaction (distributed or nonLdistributed) currentl- o#n locks on t$e re4uested data( E* t$ese locks continue to block t$e re4uesting S23 statementD a timeLout occursD t$e statement is rolled backD and t$e *ollo#ing error message is returned to t$e user /BAL0204@ timeLout distributed transaction #aiting *or lock 8ecause no data $as been modi*iedD no actions are necessar- as a result o* t$e timeout( Applications s$ould proceed as i* a deadlock $as been encountered( 1$e user #$o e6ecuted t$e statement can tr- to reLe6ecute t$e statement later( E* t$e lock persistsD t$e user s$ould contact an administrator to report t$e problem( "oc7 4rom *n6-ou't 0ransaction A 4uer- or DM3 statement t$at re4uires locks on a local database ma- be :age 9 blocked *rom doing so inde*initel- due to t$e locked resources o* an inLdoubt distributed transaction( En t$is caseD t$e *ollo#ing error message is immediatel- returned to t$e user En t$is caseD t$e S23 statement is rolled back immediatel-( 1$e user #$o e6ecuted t$e statement can tr- to reLe6ecute t$e statement later( E* t$e lock persistsD t$e user s$ould contact an administrator to report t$e problemD including t$e ED o* t$e indoubt distributed transaction( 8anuall/ 12erri%in( *n6-ou't 0ransactions A database administrator can manuall- *orce t$e F/MME1 or B/338AFI o* a local inLdoubt distributed transaction( No#everD a speci*ic inLdoubt transaction s$ould be manuall- overridden onl- #$en t$e *ollo#ing situations e6ist 1$e inLdoubt transaction locks data t$at is re4uired b- ot$er transactions( An inLdoubt transaction prevents t$e e6tents o* a rollback segment to be used b- ot$er transactions( 1$e *ailure t$at did not allo# t$e t#oLp$ase commit p$ases to complete #ill not be corrected in an acceptable time period( :age ;