<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by KARANDE ARYAN on Medium]]></title>
        <description><![CDATA[Stories by KARANDE ARYAN on Medium]]></description>
        <link>https://medium.com/@aryan.karande21?source=rss-ddbbfc27dff5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*K97Azss2PEQ5-VGU</url>
            <title>Stories by KARANDE ARYAN on Medium</title>
            <link>https://medium.com/@aryan.karande21?source=rss-ddbbfc27dff5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:33:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aryan.karande21/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TRANSACTION MANAGEMENT IN DBMS]]></title>
            <link>https://medium.com/@aryan.karande21/transaction-management-in-dbms-788e12dc2058?source=rss-ddbbfc27dff5------2</link>
            <guid isPermaLink="false">https://medium.com/p/788e12dc2058</guid>
            <category><![CDATA[acid-properties]]></category>
            <category><![CDATA[concurrency-control]]></category>
            <category><![CDATA[serializability-in-dbms]]></category>
            <category><![CDATA[state-diagram]]></category>
            <category><![CDATA[schedule]]></category>
            <dc:creator><![CDATA[KARANDE ARYAN]]></dc:creator>
            <pubDate>Mon, 08 May 2023 09:25:25 GMT</pubDate>
            <atom:updated>2023-05-08T09:32:15.872Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>A set of operations known as a transaction is used to carry out a logical set of tasks.</li><li>Transaction allows one to modify data. This can be done by adding new data, changing already-existing data, or removing data that is no longer needed.</li><li>If the database operations only retrieve data instead of updating the database, these transactions are also called read-only<strong> transactions.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*pVJliRUaUt9AYg2mUHQmnw.png" /><figcaption>Database Transaction</figcaption></figure><p><strong>Operations of Transaction:</strong></p><p>Following are the main operations of transaction:</p><ol><li><strong>Read(X)</strong>: Read X and store it in main memory.</li><li><strong>Write(X)</strong>: Write the value back to the database from the main memory.</li></ol><p><strong>Property of Transaction</strong></p><p>ACID Properties</p><p>A transaction is a very short piece of program that might include a number of low level operations.</p><p>The database system keeps track of four properties to guarantee the precision, accuracy, and data integrity throughout a transaction. These traits are frequently referred to as ACID properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*XvlsDnfoK0L46o8E9Qmr8w.png" /></figure><h3>Atomicity</h3><ul><li>It specifies that all transaction operations must occur simultaneously; otherwise, the transaction will fail.</li><li>There is no halfway point, so the transaction cannot take place in stages. Each transaction is handled as a single unit that is either carried out entirely or not at all.</li></ul><p>Atomicity involves the following two operations:</p><ul><li><strong>Abort</strong>: Changes are not saved in the database.</li><li><strong>Commit</strong>: Permanent changes stored in the database.</li></ul><h3>Consistency</h3><ul><li>Consistency is one of the fundamental properties of a DBMS. It ensures that the data stored in a database is accurate and reliable by enforcing rules and constraints that ensure the integrity of the data.</li><li>In a DBMS, consistency means that any transaction that updates the database must bring the database from one valid state to another valid state. A valid state is one that satisfies all the integrity constraints and business rules defined for the database. If a transaction fails to maintain consistency, the DBMS must roll back the transaction and restore the database to its previous consistent state.</li></ul><h3>Isolation</h3><ul><li>Isolation is one of the four properties of ACID that guarantee the reliability of a database system.</li><li>In a multi-user environment, multiple transactions may access the same data simultaneously, and it is essential to ensure that each transaction sees a consistent view of the database. Isolation ensures that each transaction executes independently and as if it were the only transaction in the system, regardless of other transactions that are executing concurrently.</li></ul><h3>Durability</h3><ul><li>Durability is one of the four properties of ACID that guarantee the reliability of a database system.</li><li>In a DBMS, durability is achieved through the use of transaction logs, which record all the changes made to the database during a transaction. Once a transaction is committed, the DBMS guarantees that the changes made by the transaction are stored permanently, even if there is a system failure, such as a power outage or a hardware failure.</li></ul><p><strong>State diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*DWT8O7IMgKm_-GIXnfTaiA.png" /></figure><ol><li><strong>Active</strong> − The state where the transaction is initially executed .</li><li><strong>Partially Committed</strong> − The transaction has chances of failing during execution, so in this state we make the required changes(R/W operations)on local memory instead of actual database to prevent inconsistency.</li><li><strong>Failed</strong> − A transaction enters a failed state if any of the checks conducted by the database recovery system do not pass. In this state, the transaction cannot proceed any further.</li><li><strong>Aborted</strong> − The recovery manager rolls back all write operations on the database to return it to the condition it was in before the transaction was executed if any of the checks fail and the transaction reaches a failure state. Aborted transactions are those that are in this state.</li><li><strong>Committed</strong> −Transaction reaches this state when all the operations are executed successfully.The changes made in local memory during partial state are permanently stored in the database.</li></ol><h3>Schedule</h3><p>A schedule is a chronological order of operations that are performed on a database by one or more transactions.</p><p>A schedule defines the sequence in which the operations of different transactions are carried out in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*KcFpt5nNEssCmaQaxTboqQ.png" /></figure><h3>1. Serial Schedule</h3><p>A serial schedule executes transactions in a strictly order, with each transaction completing its entire set of operations before the next transaction begins. This means that each transaction has exclusive access to the database during its execution, and no other transaction can access or modify the same data until the first transaction has completed.</p><p>Because a serial schedule guarantees that the results of the transactions are always consistent and that the database is always in a valid state. However, the drawback of a serial schedule is that it can be inefficient, as it can result in longer execution times and reduced throughput when compared to concurrent schedules</p><h3>2. Non-serial Schedule</h3><ul><li>Unlike serial schedules, non-serial schedule is a type of schedule in which the transactions are executed concurrently, with their operations interleaved in an arbitrary order. This can result in increased concurrency and improved performance, as multiple transactions can be executed in parallel, making better use of system resources.</li><li>However, non-serial schedules can also lead to problems such as data inconsistency, data corruption, and transaction conflicts.</li><li>Here operations are interleaved.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*zJHluo-BUA4jBqvSGLLbtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*3dCa4KpDnyV3DfML824EWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*SN2gBs89fT54gnY56Qiyiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*PrL0zFqpaN6tucWu1aT0pg.png" /></figure><p><strong>Serializability in DBMS</strong></p><p>There is a chance that the database could end up in an inconsistent state when several transactions are active concurrently.</p><p>As a result, the DBMS concept of <strong>serializability</strong> ensures that concurrent transaction execution yields the same outcome as sequential transaction execution. We can determine which schedules are serializable with the aid of serializability.</p><ul><li><strong><em>What is a serializable schedule?</em></strong></li></ul><p>A serializable schedule is a schedule that produces the same result as if the transactions were executed serially, one after the other, in some order.</p><p>Because a transaction in a serial schedule only begins when the previous transaction has completed execution, a serial schedule yields the same results as if the transactions were carried out sequentially. However, the issue arises when working with a non-serial schedule. It needs to have its serializability checked.</p><p>If a non-serial schedule can be converted into a serializable schedule by switching out a few of the non-conflicting operations between transactions without affecting the schedule’s overall outcome, it is said to be serializable.</p><p>Types of Serializability</p><p><strong>Conflict serializabilit</strong>y :</p><p>Conflict serializability is a method for determining whether a schedule of transactions in a database is serializable. Conflict serializable schedules are those that can be converted into serial schedules by swapping out non-conflicting operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*0VCd3vlSpCGJD1XNc0up1w.png" /></figure><p><strong>Conflicting operations:</strong></p><p>If all three of the following criteria are met, the operations are referred to as conflicting operations:</p><ol><li>Both the operations should be in different transactions.</li><li>Both work on the same data.</li><li>Minimum one of them should contain one write operation.</li></ol><p><strong>Example</strong>: Check the following for Conflict serializability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*0q25LJdQ3f3kB7AmCP6y_Q.png" /></figure><p><strong>Step I: </strong>Finding conflict pairs</p><ol><li>T4 → T2 [R(A), W(A)]</li><li>T3 → T2 [R(A), W(A)]</li><li>T1 → T3 [W(B), R(B)]</li><li>T1 → T2 [W(B), W(B)]</li><li>T3 → T2 [R(B), W(B)]</li></ol><p><strong>Step II: </strong>Drawing precedence graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*Gvq79WFtNGNB0q-SW_p6_A.png" /></figure><p><strong>Step III: </strong>Checking for loop</p><p>Since in our case, the graph does not make a complete cycle/ loop. This implies that the transaction is conflict serializable and therefore converted into a serial schedule.</p><p><strong>Step IV: </strong>Indegree concept</p><p>Delete one with lowest degree</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*WpG-vbOAnTB2NfZJM7mi7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*53NP2w4yhdFmVlARAhzObA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*huQUbLJURH-Drsd_LHnLgw.png" /></figure><p><strong>Step V:</strong>Possible serial path</p><ol><li>T4 → T1 → T3 → T2</li><li>T1 → T4 → T3 → T2</li><li>T1 → T3 → T4 → T2</li></ol><p><strong>View serializability </strong>is a type of operation in the serializable in which each transaction should result in a specific output, and this output is the product of the data item’s proper sequential execution. View serializability, as opposed to conflict serializability, aims to avoid database inconsistency.</p><p>If all the following three conditions are satisfied then it is view serializable:</p><ol><li>Initial read</li><li>Update read</li><li>Final Write</li></ol><p>Examples: Check for view serializability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*e-cqYUkLzRlYCeING7iKGg.png" /></figure><p><strong>Step I</strong>: Checking for initial read</p><p>Condition satisfied since both schedule starts with read operation</p><p><strong>Step II</strong>: Checking for update read</p><p>Since in both schedules there is no read except the initial read so no need to check that condition.</p><p><strong>Step III</strong>: Checking for final write</p><p>Condition satisfied since both schedule ends with write operation</p><p><strong>Concurrency Control</strong></p><p>In a DBMS, concurrency control is a method of controlling concurrent processes without causing conflicts.</p><p>For controlling and managing the concurrent execution of database activities and avoiding database inconsistencies, concurrency control is essential. The main aim of concurrency control protocols is to achieve serializability and recoverability. In concurrency control we discuss how to make concurrent schedules serializable.</p><p><strong>Problems of Concurrency</strong></p><ul><li>When different transactions update the same record(w-w conflict) then lost update problems occur.</li><li>If a new transaction selects a row that has been changed by a first transaction, there are problems with uncommitted dependencies.</li><li>If a new transaction repeatedly tries to read the same record and it reads the different record, this is known as a non-repeatable read.</li></ul><p><strong>Concurrency Control Protocols</strong></p><p>The concurrent execution of database transactions is guaranteed by concurrency control protocols to be atomic, consistent, isolated, durable, and serializable. Thus, these protocols are defined as:</p><ol><li><strong>Lock-based Protocols</strong></li></ol><p>One of the most popular methods of concurrency control in DBMS is locking. This method uses locks to limit simultaneous access to data elements so that only one transaction can use them. This method prevents a transaction from reading or writing data until it obtains the proper lock. Lock-based protocols are used to lock or isolate a specific transaction to a single user in order to deal with the concurrency issue in DBMS for concurrent transactions. Locks come in two different types:</p><ol><li><strong>Shared Lock (S):</strong> When a shared lock is aquired, read-only access is permitted. Since the transaction does not have authority to edit data on the data item while holding this lock, it can be shared between transactions, as the name would imply.</li></ol><p>2. <strong>Exclusive Lock (X): </strong>It is permitted to read and write if a transaction-locked data item is in Exclusive mode. This lock cannot be used concurrently with the same data item. After the ‘write’ process is complete, transactions may unlock the data item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*zsQOZQMoyLbI4TyBfvfydg.png" /></figure><p><strong>Problems in Shared/Exclusive Lock.</strong></p><ol><li>It might not be enough to create only a serializable schedule.</li><li>Irrecoverability may not be removed.</li><li>Could still be locked in a deadlock.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*EFHbL1YyAh_vCJFdhHDCUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*WWnp_4qRDsZ7xRMWpG186Q.png" /></figure><p>Above examples discuss the problems in locking protocols, in the first example it follows locking protocols but still it is not serializable as there is loop in the transaction T1 and T2. In 2nd problem T2 read the value which is updated by T1 and T2 is committed first. In future if T1 fails then it will be a dirty read problem, so the schedule is irrecoverable. In the third example, T2 is waiting for the resources which are already taken by T1 and similarly for T1 so this is not free from deadlock.</p><p><strong>2. Two Phase Locking Protocol (2PL)</strong></p><p>The Two-Phase Locking Protocol, often called as the 2PL protocol, is used for controlling the concurrency in DBMS that assures serializability by locking data item in a transaction and preventing the other from concurrently accessing the same data.</p><p>When the transaction starts to run in the first phase, it needs authorization for the locks which it requests. In the growing<strong> </strong>phase, the transaction acquires all of the locks. On releasing the initial lock, the transaction enters into the third phase. The transaction cannot acquire any more locks during this third step. It only releases the locks that have been obtained.</p><p>In the 2PL protocol all transactions are allowed to make a request for acquire and release the lock in two steps:</p><ol><li><strong>Growing Phase: </strong>Transactions may acquire locks during this phase, but they do not unlock any transaction.</li></ol><p>2. <strong>Shrinking Phase:</strong> A transaction can release the locks during this stage but cannot acquire new locks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*2ZcJwRvyOtJpAQWDP0OmVA.png" /></figure><p><strong>Advantage: </strong>Serializability is achieved</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*feAm6Np93hxzEi1SR3UVug.png" /></figure><p><strong>Disadvantages</strong></p><ol><li>Irrecoverability may not be removed.</li><li>Cascading rollbacks are possible.</li></ol><p>In the following example if a T1 transaction fails then all other transactions which are reading the value updated by T1 must be rolled back to solve the dirty read problem.This is called as cascading rollback problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*QgAKaztFk8TH_z4lMguPfg.png" /></figure><p><strong>3. Timestamp Ordering Protocol</strong></p><p>In this concurrency control protocol, we assume that the older transaction will be completed first. In this protocol,</p><ul><li>Every transaction is given a timestamp, which is a unique value.</li><li>Tells order of transactions when they enter into the system.</li><li>Read_TS(RTS)= the last transaction for which the read operation was successful.</li><li>Write_TS(WTS)= the last transaction for which the write operation was successful.</li></ul><p><strong>Rules:</strong></p><ol><li>Read(A) operation is performed by Transaction Ti.</li></ol><p>a. If TS(Ti)&lt;WTS(A), then Rollback transaction Ti</p><p>b. else, perform the R(A) operation. RTS(A) is set to max{ TS(Ti)}, RTS(A)</p><p>2. Write(A) operation is performed by Transaction Ti.</p><p>a. If TS(Ti) &lt; RTS(A), then Rollback transaction Ti</p><p>b. If TS(Ti) &lt; WTS(A), then Rollback transaction Ti</p><p>c. else, carry out the write(A) operation. WTS(A) is set to TS(Ti).</p><p>Following example shows that, when the older transaction starts any conflicting operation there is no problem to perform the operation. And When younger transaction starts conflicting operations it must be rolled back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*ZIGthMWth6S0PHK9iLtToQ.png" /><figcaption>Serializable Schedules.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*_U-M1xNDWuuA6Jk9BpwSKg.png" /><figcaption>Rollback Transaction</figcaption></figure><p>If younger transactions perform any operation and then older transactions perform conflicting operations then the latest operation must be rollback. Otherwise, transactions will always be serializable from older transaction to younger transaction(T1-&gt;T2).</p><p><strong>4. Validation Based Protocol</strong></p><p>Validation-based protocol is used to prevent concurrency in DBMS, commonly referred to as optimistic concurrency control technique. This protocol minimizes interference during transaction execution by updating Instead of the actual data, local copies of the data.</p><p>Following are 3 phases in validation-based protocols:</p><ol><li>Read Phase</li><li>Validation Phase</li><li>Write Phase</li></ol><p><strong>Read Phase</strong></p><p>It is used to read different data items’ values and store them in local variables. Without changing the underlying database, it is feasible to carry out all write operations on temporary variables.</p><p><strong>Validation Phase</strong></p><p>This stage involves comparing the temporary variable value to the actual data to determine whether it violates serializability.</p><p><strong>Write Phase</strong></p><p>If the transaction validation is successful then changes are committed to the database; otherwise, the transaction is rolled back.</p><p>Since the validation step is the one that actually decides whether the transaction will commit or roll back.</p><p><strong>Recovery techniques</strong></p><ol><li>Undoing –In the event of a crash, the recovery manager has the capability to undo transactions. This is achieved by checking the transaction’s log entry.</li><li>Deferred update — This method waits until a transaction reaches the commit point before physically updating the database stored on disc</li><li>Prior to committing, all updates made by a transaction are stored in local memory. As a result, if a transaction fails to reach its commit point, the database will remain unaltered, and therefore, there is no need to perform an UNDO operation.</li></ol><p>In the following example, if the T1 transaction fails then there will be no log entry for commit, when recovery manager can’t find both start and commit then the transaction will be rolled back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*xSgN84PtuNK5xgfp2Fp6rg.png" /></figure><p>4. Immediate update — The database directly update the database when operation is performed before the transaction reaches its commit point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*fSV9K9oe2wEjAuhxxsPFyg.png" /></figure><p>In the above example the transaction is failed then there is no log entry for commit operation. So, when the recovery manager checks for log entries of both start and commit and on failure it will <strong>undo </strong>the changes in the database in case of Immediate recovery.</p><p>5. Caching/Buffering — Disc pages that contain data items that need to be updated are cached in main memory buffers and the updates are made in the memory before writing back to the disk.In case of system failure,data is fetched from cache to provide quick recovery.Demerit of this technique is that cache memory is volatile, so in events of power outage data can be lost.</p><p>6. Shadow paging –During the shadow paging technique, the DBMS maintains two page tables: one for the shadow copy of the database and one for the original database. All updates are performed on the shadow copy of the database, and once the updates are complete, the page table for the original database is replaced with the page table for the shadow copy. In case of system failure,the original database is replaced with a recently committed page table of the shadow copy,hence bringing the database to the consistent state without any complex procedure.</p><blockquote><em>Authors : Harshita Bhagat, Aryan Karande, Parth More, Vaishali More</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=788e12dc2058" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>