Skip to main content

Lock Contention & Bloat Analysis

This section of the AWR report covers two important operational health dimensions: lock contention between sessions, and bloat accumulation in tables and indexes.


Lock Contention Analysis

{screenshot: awr-lock-contention-section}

What Is Lock Contention?

Lock contention occurs when one session holds a lock that another session needs. The waiting session is blocked until the lock is released. Under high concurrency, lock contention can cascade into serious performance degradation.

Data Source

Lock contention data is captured from pg_locks samples recorded at each AWR snapshot interval. The report shows the most frequent blocking patterns observed between the two selected snapshots.

Lock Contention Table

ColumnDescription
Blocking QueryThe query holding the lock
Blocked QueryThe query waiting for the lock
Lock TypeType of lock requested
RelationTable or index involved
OccurrencesNumber of times this blocking pattern was observed
Max Wait (s)Longest observed wait duration

{screenshot: awr-lock-contention-table}

Common Lock Types in PostgreSQL

Lock ModeTriggered By
AccessShareLockSELECT statements
RowShareLockSELECT FOR UPDATE / SHARE
RowExclusiveLockINSERT, UPDATE, DELETE
ShareUpdateExclusiveLockVACUUM, CREATE INDEX CONCURRENTLY
AccessExclusiveLockALTER TABLE, DROP TABLE, TRUNCATE

Interpreting Lock Contention Results

Frequent transactionid locks → Long-running transactions blocking others. Review application transaction boundaries and ensure transactions are kept as short as possible.

AccessExclusiveLock contention → DDL operations (ALTER TABLE, VACUUM FULL) blocking normal DML. Schedule maintenance operations during off-peak windows.

Row-level lock contention on the same relation → Hot-row contention in high-concurrency tables. Consider application-level redesign or optimistic locking patterns.


Bloat Analysis

{screenshot: awr-bloat-section}

What Is Bloat?

PostgreSQL uses an MVCC (Multi-Version Concurrency Control) architecture. When rows are updated or deleted, the old versions are not immediately removed — they become dead tuples that accumulate as bloat in tables and indexes until VACUUM reclaims them.

Excessive bloat:

  • Wastes disk space
  • Slows down sequential and index scans
  • Increases I/O load

Bloat Estimates Table

The AWR report provides bloat estimates for the most bloated tables and indexes in the monitored databases:

Table Bloat:

ColumnDescription
TableSchema and table name
Live RowsEstimated number of live rows
Dead RowsEstimated dead tuple count
Table SizeCurrent physical size
Bloat SizeEstimated reclaimable space
Bloat %Percentage of table that is bloat

Index Bloat:

ColumnDescription
IndexIndex name and associated table
Index SizeCurrent physical size
Bloat SizeEstimated reclaimable space
Bloat %Percentage of index that is bloat

{screenshot: awr-bloat-table}

Bloat Thresholds

Bloat %Action
< 10%Normal — no action needed
10–30%Monitor — increase autovacuum aggressiveness
> 30%Investigate — consider manual VACUUM or VACUUM FULL during a maintenance window

:::warning VACUUM FULL VACUUM FULL reclaims all bloat but takes an AccessExclusiveLock on the table, blocking all access during the operation. Use it only during scheduled maintenance windows. For online bloat reduction, consider pg_repack. :::


Next Steps