Re: Maximum amount of pg_locks - Mailing list pgsql-admin

From Beniamin Hendre
Subject Re: Maximum amount of pg_locks
Date
Msg-id CAOST94jEPPCk4BhrDYSrnB80e-uq2EdY5HJ7oxypk31VYAUXRA@mail.gmail.com
Whole thread Raw
In response to Maximum amount of pg_locks  (Tim Herren <tim.herren@protonmail.ch>)
List pgsql-admin
Actualisation script maximo plus??

mie., 28 ian. 2026, 22:12 Tim Herren <tim.herren@protonmail.ch> a scris:
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

pgsql-admin by date:

Previous
From: Tim Herren
Date:
Subject: Maximum amount of pg_locks
Next
From: Tom Lane
Date:
Subject: Re: Maximum amount of pg_locks