What is Two-Phase Locking (2PL)?

It is a concurrency control protocol used in databases to ensure serializability (correct execution of transactions in a consistent order).It uses locks to control read/write access to data during transactions.

Or

Two phase locking (2PL) is a rule used in Database to ensure correctness when many users work together.

What do you guys think 🤔Why is 2PL needed?

In a multi-user environment, two transactions may access the same data at the same time, causing inconsistency.

2PL ensures transactions do not interfere with each other and the database remains correct.

#For better understanding let's take an real world example

In a database, many users can work at the same time like

1.someone transfer money.

2.someone checks their balance.

3.someone updates their address.

Let's think What If not handled properly ???🤔

Obviously guys 🤷

1.Data may get lost.

2.One may see wrong or partial data.

3.Database may become inconsistent.

Ok 2PL( Two-phase locking) are of two phase

1.Growing Phase