Lock:tuple
The tuple wait event is a specific type of lock contention that occurs at the row level.
The tuple wait event occurs when a backend process is waiting to acquire a lock on a specific tuple (a physical row version).
when a transaction wants to update or delete a row, it must first lock that row. If another transaction already holds a lock on that row,
the second transaction enters a "waiting" state. If the contention is specifically for the right to access the row structure itself or to wait for a prior locker to finish, it is categorized as a Lock: tuple event.
Understanding both tuple & transactionid wait events
transactionid: You are waiting for another transaction to COMMIT or ROLLBACK so you can see if the row is actually available.
tuple: You are waiting in a "queue" to acquire the lock on the row itself. This usually happens when three or more transactions are trying to modify the same row simultaneously.
When multiple sessions target the same row, the sequence usually looks like this:
- Transaction A updates a row and holds the lock.
- Transaction B tries to update the same row. It sees Transaction A is busy and starts waiting (this often shows as a transactionid wait).
- Transaction C tries to update the same row. Because there is already a queue forming, Transaction C (and any subsequent transactions) will wait on the tuple event.
Essentially, tuple is the "waiting room" for row-level locks when there is high concurrency on a single record.
Common Causes of Lock: tuple Wait Events
- High Concurrency on Specific Rows: When multiple transactions attempt to modify the same row simultaneously, it leads to contention.
- Long-Running Transactions: Transactions that hold locks for extended periods can cause other transactions to wait.
- Inefficient Application Logic: Poorly designed application logic that frequently updates the same rows can increase contention.
- Massive batch updates:If a large batch job updates thousands of rows in a single transaction without committing, any other process trying to touch those same rows will be queued.