Re: Shared hash table allocations
Heikki Linnakangas <hlinnaka@iki.fi>
On 30/03/2026 18:28, Heikki Linnakangas wrote: > To be clear, the init_size/max_size are not completely unused at the > moment: the lock manager sets max_size to 2 * init_size, and ... Huh, I only now realized the implications of the above. The formula in the lock manager is actually: #define NLOCKENTS() \ mul_size(max_locks_per_xact, add_size(MaxBackends, max_prepared_xacts)) ... max_table_size = NLOCKENTS(); init_table_size = max_table_size / 2; So the initial size is only half of the maximum you get from max_locks_per_xacts * max_connections. That means that if something consumes the "wiggle room" shared memory, you might get *fewer* locks than you might expect based on the GUCs. I've somehow always thought that it's the other way round, that you might get *more* locks than max_locks_per_xacts * max_connections if you're lucky, but that max_connections * max_locks_per_xacts was guaranteed. This will change with these patches. I wonder if we should change the defaults somehow. In usual configurations, people are currently getting much more lock space than you'd expect based on max_connections and max_locks_per_transaction, and after these patches, they'll get much fewer locks. It might be prudent bump up the default max_locks_per_transaction setting so that you'd get roughly the same amount of locks in the default configuration. - Heikki
Commits
-
Remove HASH_DIRSIZE, always use the default algorithm to select it
- 4953a25b7f3b 19 (unreleased) landed
-
Allocate all parts of shmem hash table from a single contiguous area
- 9fe9ecd516b0 19 (unreleased) landed
-
Prevent shared memory hash tables from growing beyond initial size
- 999e9ebb51c9 19 (unreleased) landed
-
Merge init and max size options on shmem hash tables
- 9ebe1c4f2c7c 19 (unreleased) landed
-
Change default of max_locks_per_transactions to 128
- 79534f90657c 19 (unreleased) landed
-
Make the lock hash tables fixed-sized
- e1ad034809a4 19 (unreleased) landed
-
Remove 10% safety margin from lock manager hash table estimates
- 3e854d2ff1a6 19 (unreleased) landed
-
Remove bogus "safety margin" from predicate.c shmem estimates
- feb03dfecdc9 19 (unreleased) landed
-
Make ShmemIndex visible in the pg_shmem_allocations view
- 1bdbb211bbf3 19 (unreleased) landed
-
Change the signature of dynahash's alloc function
- 7b424e3108e4 19 (unreleased) landed
-
Remove HASH_SEGMENT option
- dde69621c324 19 (unreleased) landed
-
Use ShmemInitStruct to allocate shmem for semaphores
- 40c41dc77306 19 (unreleased) landed