Maximum amount of pg_locks

From: Tim Herren <tim(dot)herren(at)protonmail(dot)ch>
To: "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Maximum amount of pg_locks
Date: 2026-01-28 20:12:01
Message-ID: hS-XH0n2SemZiCabUk02t2mKBBLxiFFF-iA7u_RIp8HuTPrFt1T3J_ljcMcYV7syotOSkKM7zV9jwTVcnkz356oltoxkLJjXvMIObTMP254=@protonmail.ch
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi

I'm trying to wrap my head around the way the calculation for the maximum amount of locks works in postgres 16.11
I already came to the understanding that the maximum amount of locks are not on a transaction basis, but rather influenced by the setting "max_locks_per_transaction" and the "max_connections".
I'm saying influenced rather than calculated because on my server a simple multiplication of those two values, set at 512 and 180 respectively gives 92160.

Yet I regularly observe around 119k locks during my backup using "pg_dump -Fc".

postgres=# SELECT
locktype,
mode,
count(*)
FROM pg_locks
GROUP BY 1, 2
ORDER BY 3 DESC;
locktype | mode | count
------------+-----------------+--------
relation | AccessShareLock | 119948
virtualxid | ExclusiveLock | 2
(2 rows)

The database I'm backing up at that time contains 242 schemas and each has around 500 relations (a mix of tables and sequences).
So that matches pretty well.

I've verified that my configured setting is enough in the sense that I get a usable backup and my database remains operational during the backup period. Non the less I would like to understand where that difference comes from and how close to the "actual limit" I am.
Please let me know if this needs more information.
Thanks

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Beniamin Hendre 2026-01-28 20:21:00 Re: Maximum amount of pg_locks
Previous Message Ron Johnson 2026-01-28 19:33:27 Re: Restoration process generates 1.2 TB of WAL files.