0% found this document useful (0 votes)
61 views

Anjali DB 3

This document contains a student's assignment submission for a database management systems (DBMS) course. It includes: 1) Analysis of two transaction schedules to determine if they are conflict serializable, and providing equivalent serial schedules. 2) A description of transaction control statements in Oracle such as commit, rollback, savepoints, isolation levels, lock types and durations. Examples of situations where deadlocks may occur and preventative measures are also discussed. 3) A request to show transaction states in a diagram using an example system.

Uploaded by

anjaliangel1989
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Anjali DB 3

This document contains a student's assignment submission for a database management systems (DBMS) course. It includes: 1) Analysis of two transaction schedules to determine if they are conflict serializable, and providing equivalent serial schedules. 2) A description of transaction control statements in Oracle such as commit, rollback, savepoints, isolation levels, lock types and durations. Examples of situations where deadlocks may occur and preventative measures are also discussed. 3) A request to show transaction states in a diagram using an example system.

Uploaded by

anjaliangel1989
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CSE 351

DBMS
ASSIGNMENT - 3

Submitted BY: Submitted to:


Anjali Sharma Mrs. Harjeet
A2801
10804864
Roll no : 26
Part A

1. Which of the schedules below (if any) is conflict serializable?


For each serializable schedule, show an equivalent serial
schedule.

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 Access


same data items.
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)
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 T4
write(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)
2.Identify various transaction control statements in oracle. How is
locking applied in oracle?
Ans. A transaction is a series of SQL statements that either succeeds
or fails as a unit. Transactions are a standard part of relational
databases and prevent inconsistent data. The classic example of this is
a 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:
 All work done by the transaction is made permanent.
 Other sessions can see the changes made by this transaction.
 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.
When a rollback statement is issued to the database, the transaction is
ended, and:
 All work done by the transaction is undone, as if hadn't been issued.
 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:
 Any work done since the savepoint is undone. The savepoint remains
active, however. It can be rolled back to again, if needed.
 Any locks and resources acquired by the SQL statements since the
savepoint will be released.
 The transaction is not finished, because SQL statements are still
pending.
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

locking in oracle
Locks are mechanisms that prevent destructive interaction between
transactions 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 in
the 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 
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 resource
exclusively is the only transaction that can alter the resource until the
exclusive lock is released

2. Share Lock Mode 


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. What


corrective measures you will take to eliminate this?
Ans. DEADLOCKS
Oracle automatically detects deadlock situations and resolves them by
rolling back one of the statements involved in the deadlock. This
releases one set of the conflicting row locks. A corresponding message
also 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 read
locks for queries and does not use page-level locking, deadlocks
rarely occur in Oracle.

DEADLOCK AVOIDANCE
• Deadlocks can usually be avoided if transactions accessing the same
tables lock those tables in the same order, either through implicit or
explicit locks and when a sequence of locks for one transaction are
required, you should consider acquiring the most exclusive (least
compatible) lock first
• Always close explicit cursors when finished to free locks.

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
• 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 are


persistent
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
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 to
produce unbiased reviews. We do our best to provide independent opinions
on a variety of different data recovery, undelete and unformat tools. You
are encouraged to download and use the reviewed tools.

There are several types of data recovery products.

 Undelete and unerase utilities simply recover deleted files. You'll


certainly find the right type of product if you're looking for a tool to
quickly recover a few files.
 Hard disk and partition recovery tools recover corrupted hard
drives and partitions, repair formatted volumes and fix broken file
systems. If you are looking for a tool to fix FAT, NTFS, ext2fs or
MacOS logical disks, look no further!
 Removable media recovery tools fix and repair data on corrupted
USB sticks, ZIP drives, digital cameras, and memory cards such as
SD, Compact Flash, MMC, Memory Stick. This category lists tools for
portable MP3 and video players such as iPod, iRiver, and Zune.
 CD and DVD recovery tools recover data from optical media with
incomplete sessions, burn errors or wrong disk parameters.
 Password recovery tools provide access to password-protected
documents such as ZIP archives, MS Office, and Adobe PDF
documents.
 Database recovery and repair software fix corrupted databases
such as MS Access or FoxPro DBF.
 Email recovery tools fix corrupted mailboxes and recover lost email
in Microsoft Exchange, Outlook, Outlook Express, Eudora, The Bat!,
or Vista Windows Mail.
 Everything else includes other useful tools related to data recovery,
including secure delete tools, data wipers, and backup software.

You might also like