anjali db 3

14
 CSE 351 DBMS ASSIGNMENT - 3 Submitted BY: Submitted to: Anjali Sharma Mrs. Harjeet A2801 10804864 Roll no : 26

Transcript of anjali db 3

Page 1: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 1/14

  CSE 351

DBMS

ASSIGNMENT - 3

Submitted BY: Submitted to:

Anjali Sharma Mrs. Harjeet

A2801

10804864

Roll no : 26

Page 2: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 2/14

Part A

1. Which of the schedules below (if any) is conflict serializable?For each serializable schedule, show an equivalent serialschedule.

Schedule 1

T1: write(A)T1: read(F)T2: write(B)T3: increment(C)T1: increment(E)T4: increment(E)T2: read(F)T4: read(D)T3: read(A)T4: write(B)T2: write(C)T1: increment(D)T3: read(F)T2: increment(E)

ANSWER : This Is an conflict serializable as the

Increment (E) of T1 is conflicting with

Incrément(E) of T4 as the two instructions Accesssame data items.

Page 3: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 3/14

 

SOLUTION : EQUIVALENT SERIAL SCHEDULE

T1 T2 T3 T4

write(A)

read(F)

incrément(E)

incrément(D)

write(B) 

read(F) 

write(C)

increment(E) 

increment(C) 

read(A) 

read(F) 

increment(E)

read(D) 

write(B) 

Schedule 2

T2: write(B)T1: write(A)T2: read(F)T3: increment(C)

Page 4: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 4/14

T4: increment(E)T1: read(F)T2: increment(E)T1: read(D)T4: write(B)T2: write(C)T3: read(A)

T4: increment(D)T1: increment(E)T3: read(F)

SOLUTION : EQUIVALENT SERIAL SCHEDULE

T2 T1 T3 T4write(B) 

read(F)

increment(E)

write(C)

write(A) 

read(F) 

read(D) 

increment(E) 

increment(C)

read(A)

read(F)

increment(E) 

write(B)

increment(D) 

Page 5: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 5/14

 

2.Identify various transaction control statements in oracle. How islocking applied in oracle?

Ans. A transaction is a series of SQL statements that either succeedsor fails as a unit. Transactions are a standard part of relational

databases and prevent inconsistent data. The classic example of this isa bank transaction:

update accounts

set balance = balance - trans_amount

where account_no = from_account;

update accounts

set balance = balance + trans_amount

where account_no = to_account;

Suppose the first update statement succeeds, but the second statement

fails due to an error. The data is now inconsistent. We prevent this

combining two statements into a transaction, whereby either both

statements will succeed or both statements will fail.

 A transaction begins with the first SQL statement issued after the

previous transaction, or the first SQL statement after connection to the

database. The transaction ends with the commit or rollback statement.

Commit versus rollback

When a commit statement is issued to the database, the transaction is

ended, and:

y   All work done by the transaction is made permanent.

y  Other sessions can see the changes made by this transaction.

y   Any locks acquired by the transaction are released.

The syntax of the commit statement is:

commit [work];

The optional keyword work is available for increased readability. Until

the transaction is committed, only the session executing that transaction

can see the changes made by that session.

Page 6: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 6/14

When a rollback statement is issued to the database, the transaction is

ended, and:

y   All work done by the transaction is undone, as if hadn't been issued.

y   Any locks acquired by the transaction are released.

The general syntax of the rollback statement is:rollback [work] [to savepoint save_point_name];

 An explicit rollback statement is often used when an error that prevents

further work is detected. If a session disconnects from the database

without ending the current transaction with commit or rollback, the

transaction is automatically rolled back by the database.

Savepoints

The rollback statement undoes the entire transaction. With the savepoint

command, however, only a part of the transaction need be undone.

The syntax for the savepoint command is:

Savepoint save_point_name; 

Note that savepoints are not declared in the declarative section, since

they are global to a transaction, and the transaction can continue past

the end of the block. Once a savepoint is defined, the program can roll

back to the savepoint using the "to savepoint" rollback syntax. When a

rollback to savepoint is issued, the following things occur:

y   Any work done since the savepoint is undone. The savepoint remains

active, however. It can be rolled back to again, if needed.

y   Any locks and resources acquired by the SQL statements since the

savepoint will be released.

y  The transaction is not finished, because SQL statements are stillpending.

savepoint is often used before a complicated section of a transaction. If this part of the transaction fails, it can be rolled back, allowing the earlier part to continue

Page 7: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 7/14

locking in oracle

Locks are mechanisms that prevent destructive interaction betweentransactions accessing the same resource.General Object Type Affected By Locks:

User objects, such as tables and rows (structures and data)

System objects not visible to users, such as shared data structures inthe memory and data dictionary rows

Isolation Levels 

Isolation Levels are how Oracle executes SQL statements in

regards to read consistency and is directly related to what lock may

be ignored.

  Read Committed (Default)

  Serializable Transactions

  Read-only 

1. Read Committed (Oracle Default)

Each query executed by a transaction sees only data that was

committed before the query (not the transaction) began. An Oracle

query will never read dirty (uncommitted) data.

Because Oracle does not prevent other transactions from modifying

the data read by a query, that data may be changed by other transactions between two executions of the query

2. Serializable Transactions

See only those changes that were committed at the time the

transaction began, plus those changes made by the transaction itself 

through INSERT, UPDATE, and DELETE statements.

* Note: Not Usable in Distributed Transactions

3. Read-Only

Page 8: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 8/14

See only those changes that were committed at the time the

transaction began and do not allow INSERT, UPDATE, and DELETE

statements.

Setting at Transaction Level:

SET TRANSACTION ISOLATION LEVEL READ COMMITTED; 

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; SET TRANSACTION ISOLATION LEVEL READ ONLY; 

Setting at Session Level:

 ALTER SESSION SET ISOLATION_LEVEL READ COMMITTED; 

 ALTER SESSION SET ISOLATION_LEVEL SERIALIZABLE; 

 ALTET SESSION SET ISOLATION_LEVEL READ ONLY;

Lock duration

All locks acquired by statements within a transaction are held for the

duration of the transaction.

Oracle releases all locks acquired by the statements within a

transaction when an explict or implied commit or roll back is

executed. Oracle also releases locks acquired after a savepoint when

rolling back to the savepoint.

* Note: Only transactions not waiting for the previously locked

resources can acquire locks on now available resources. Waiting

transactions continue to wait until after the original transaction

commits or completely rolls back.

Lock modes

1. Exclusive Lock Mode

Prevents the associates resource from being shared. This lock mode

is obtained to modify data. The first transaction to lock a resourceexclusively is the only transaction that can alter the resource until the

exclusive lock is released

2. Share Lock Mode

Page 9: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 9/14

 Allows the associated resource to be shared, depending on the

operations involved. Multiple users reading data can share the data,

holding share locks to prevent concurrent access by a writer (who

needs an exclusive lock). Several transactions can acquire share

locks on the same resource.

Lock types

DML locks (data locks)

DDL locks (dictionary locks)

Oracle Internal Locks/Latches

Oracle Distributed Locks

Oracle Parallell Cache Management Locks

2.Give examples of situations where deadlock may occur. Whatcorrective measures you will take to eliminate this?

Ans. DEADLOCKSOracle automatically detects deadlock situations and resolves them byrolling back one of the statements involved in the deadlock. Thisreleases one set of the conflicting row locks. A corresponding messagealso is returned to the transaction that undergoes the rollback.

DEADLOCK OCCURENCE Deadlocks often occur when transactions override Oracle default

locking. Oracle itself does no lock escalation and does not use readlocks for queries and does not use page-level locking, deadlocksrarely occur in Oracle.

DEADLOCK AVOIDANCE

Deadlocks can usually be avoided if transactions accessing the sametables lock those tables in the same order, either through implicit or explicit locks and when a sequence of locks for one transaction arerequired, you should consider acquiring the most exclusive (leastcompatible) lock first

Always close explicit cursors when finished to free locks.

Page 10: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 10/14

 

PART B

3. Show different states of a transaction with the help of diagram.Consider any system of your choice to exemplify states

Ans.

Transaction A short sequence of operations with the database which

represents one meaningful activity in the user's environment.

ACID Property of Transactions

  Atomicity: Either all updates are performed or none

  Consistency: If the database state at the start of a transaction is

consistent, it will be consistent at the end of the transaction

Page 11: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 11/14

  Isolation: When multiple transactions are executed concurrently, the

net effect is as though each transaction has executed in isolation

  Durability: After a transaction completes (commits), its changes arepersistent

Page 12: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 12/14

Transaction States

  Active: Initial state; when the transaction is executing

  Partially Committed: When the last statement has finished

execution

  Failed: On discovery that normal execution can no longer proceed

  Aborted: After the rollback is performed from a failed transaction  Committed: After successful completion

  Terminated: Either committed or aborted

Page 13: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 13/14

 

4. Does locking ensure that deadlock won¶t happen? Justify your answer with examples

5. Make a comparative study of recovery tools available in market

Ans. Recovery Review strives to help consumers to better comprehend

the modern data recovery market with strong emphasis to the do-it-yourself type of products. We carefully select only the best data recovery tools toproduce unbiased reviews. We do our best to provide independent opinionson a variety of different data recovery, undelete and unformat tools. Youare encouraged to download and use the reviewed tools.

There are several types of data recovery products.

y  Undelete and unerase utilities simply recover deleted files. You'llcertainly find the right type of product if you're looking for a tool toquickly recover a few files.

y  Hard disk and partition recovery tools recover corrupted harddrives and partitions, repair formatted volumes and fix broken file

Page 14: anjali db 3

8/8/2019 anjali db 3

http://slidepdf.com/reader/full/anjali-db-3 14/14

systems. If you are looking for a tool to fix FAT, NTFS, ext2fs or MacOS logical disks, look no further!

y  Removable media recovery tools fix and repair data on corruptedUSB sticks, ZIP drives, digital cameras, and memory cards such asSD, Compact Flash, MMC, Memory Stick. This category lists tools for portable MP3 and video players such as iPod, iRiver, and Zune.

y  CD and DVD recovery tools recover data from optical media with

incomplete sessions, burn errors or wrong disk parameters.y  Password recovery tools provide access to password-protected

documents such as ZIP archives, MS Office, and Adobe PDFdocuments. 

y  Database recovery and repair software fix corrupted databasessuch as MS Access or FoxPro DBF.

y  Email recovery tools fix corrupted mailboxes and recover lost emailin Microsoft Exchange, Outlook, Outlook Express, Eudora, The Bat!,or Vista Windows Mail.

y  Everything else includes other useful tools related to data recovery,including secure delete tools, data wipers, and backup software.