DEV Community

Haseeb Ashraf
Haseeb Ashraf

Posted on

On Overview of Concurrency Control in PostgreSQL

Today, we will take a look at concurrency control in PostgreSQL.
It is a control mechanism that maintains isolation and atomicity, which are some of the important properties that are required to run many transaction parallelly in the database.
Overall, concurrency control can be categorized into three main techniques:

  • Multi-version Concurrency Control (MVCC)
  • Strict Two-Phase Locking (S2PL)
  • Optimistic Concurrency Control (OCC)

Whenever a data item is read through a transaction, one of the versions is selected by the system to make sure that the system ensures isolation of the transaction.
The main reason MVCC is considered advantageous is that readers and writers don't block each other.

In some versions of RDBMS and PostgreSQL, a variations of MVCC is used, known as Snapshot Isolation(SI).
Rollback segments are used by some database systems to implement SI. Whenever an item is being read, an appropriate version of an item is used by PostgreSQL in response to an individual transaction that is using visibility check rules.

Whenever a transaction is initiated in PostgreSQL, a unique identifier is assigned to each transaction known as a transaction id(txid). This txidis a 32-bit unsigned integer with approximately 4.2 billion unique combinations. Whenever a transaction starts, the built-in txid_current() function returns the current txid.

The above was a short overview of concurrency control in PostgreSQL.

Top comments (0)