]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add support for lock statistics in pgstats
authorMichael Paquier <michael@paquier.xyz>
Tue, 24 Mar 2026 06:32:09 +0000 (15:32 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 24 Mar 2026 06:32:09 +0000 (15:32 +0900)
commit4019f725f5d43f37b23222d06d20e3da1038d373
tree2d1310914d3c79c8d2f133e692e4e8be8c5f907f
parenta90d86518243a077cdd1445ec8586ffb81dae408
Add support for lock statistics in pgstats

This commit adds a new stats kind, called PGSTAT_KIND_LOCK, implementing
statistics for lock tags, as reported by pg_locks.  The implementation
is fixed-sized, as the data is caped based on the number of lock tags in
LockTagType.

The new statistics kind records the following fields, providing insight
regarding lock behavior, while avoiding impact on performance-critical
code paths (such as fast-path lock acquisition):
- waits and wait_time: respectively track the number of times a lock
required waiting and the total time spent acquiring it.  These metrics
are only collected once a lock is successfully acquired and after
deadlock_timeout has been exceeded.
fastpath_exceeded: counts how often a lock could not be acquired via
the fast path due to the max_locks_per_transaction slot limits.

A new view called pg_stat_lock can be used to access this data, coupled
with a SQL function called pg_stat_get_lock().

Bump stat file format PGSTAT_FILE_FORMAT_ID.
Bump catalog version.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/aIyNxBWFCybgBZBS%40ip-10-97-1-34.eu-west-3.compute.internal
21 files changed:
doc/src/sgml/monitoring.sgml
src/backend/catalog/system_views.sql
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c
src/backend/utils/activity/Makefile
src/backend/utils/activity/meson.build
src/backend/utils/activity/pgstat.c
src/backend/utils/activity/pgstat_lock.c [new file with mode: 0644]
src/backend/utils/adt/pgstatfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/include/pgstat.h
src/include/utils/pgstat_internal.h
src/include/utils/pgstat_kind.h
src/test/isolation/expected/lock-stats.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/lock-stats.spec [new file with mode: 0644]
src/test/regress/expected/rules.out
src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql
src/tools/pgindent/typedefs.list