Professional Documents
Culture Documents
B1 071 RDBMS Exp9
B1 071 RDBMS Exp9
Grade: AA / AB / BB / BC / CC / CD /DD
1. Dr. P.S. Deshpande, SQL and PL/SQL for Oracle 10g.Black book, Dreamtech Press
2. www.db-book.com
3. Korth, Slberchatz, Sudarshan : “Database Systems Concept”, 5th Edition , McGraw
Hill
4. Elmasri and Navathe,”Fundamentals of database Systems”, 4th Edition,PEARSON
Education.
5. https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html
Resources used:
Theory
Lock-based Protocols
Database systems equipped with lock-based protocols use a mechanism by which any
transaction cannot read or write data until it acquires an appropriate lock on it. Locks
are of two kinds −
1. Binary Locks − A lock on a data item can be in two states; it is either locked or
unlocked.
2. Shared/exclusive − This type of locking mechanism differentiates the locks
based on their uses. If a lock is acquired on a data item to perform a write
operation, it is an exclusive lock. Allowing more than one transaction to write
on the same data item would lead the database into an inconsistent state. Read
locks are shared because no data value is being changed.
Step 1.
If we want to perform DML operation then table should get locked first in exclusive mode and
then it is possible for that particular transaction;
Step 2:
Simply press enter key till it asks for password and then furnish password which was given
during installation.
Step 3:
Default user is postgres, you may create another user (‘temp_user’) for testing the protocol.
Psql -d postgres -U postgres – where 1st postgres keyword is database name and last postgres
keyword is default user as ‘postgres’
Step 5:
Open another sql shell from start. And login as a different user with psql -d command.
Step 6:
Now try to lock and access the same table with different user and with similar commands
Step 7:
Step 8:
Now table is been locked in another shell with user – temp_user , obseve.
Step 9:
Every transaction will lock and unlock the data item in two different phases.
Growing Phase − All the locks are issued in this phase. No locks are released, after all
changes to data-items are committed and then the second phase (shrinking phase)
starts.
Shrinking phase − No locks are issued in this phase, all the changes to data-items are
noted (stored) and then locks are released.
A transaction can release a shared lock after the lock point, but it cannot release any
exclusive lock until the transaction commits. This protocol creates a cascade less
schedule.
A transaction cannot release any lock either shared or exclusive until it commits.
The 2PL protocol guarantees serializability, but cannot guarantee that deadlock will
not happen
Conclusion :