Locks

The MVCC model used in PostgreSQL makes locks less of an issue than in some other databases. High performance applications still need to be careful to minimize how often they take stronger locks however, and performance tuning work will regularly require looking for situations where locking behavior is a bottleneck.

The details of how locking works in the database is described extensively at http://www.postgresql.org/docs/current/static/explicit-locking.html.

The other useful manual section is the description of the pg_locks view, which lets you see all the active locks in the database, available at http://www.postgresql.org/docs/current/static/view-pg-locks.html.

As there's far too many details involved in locking to cover all of them in this chapter, consider those sections of the documentation required reading in addition to what's here. This section will mainly present how to work with pg_locks and examples of what sort of information you'll actually see in there. All of these are locks generated by running the standard and select-only pgbench tests.