KyoMel / Yogyakarta, Indonesia

Term 021021 / 344

Pessimistic Concurrency Control (PCC)

Month
July 2025
Day
23
Source
2025/july-term.md

Definition:

PCC is a database locking strategy that prevents conflicts by locking data while it’s being read or modified, ensuring only one transaction can access it at a time.

Use Case Banking systems use PCC to prevent two users from withdrawing the same money simultaneously.

Example:

-- Transaction A locks the row for update
BEGIN;
SELECT * FROM accounts WHERE id = 1 FOR UPDATE;
-- No other transaction can read or update this row until A commits

Keep reading