-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review 'max_locks_per_transaction' setting in FlowDB #5157
Comments
Does this change at all with new style partitions? |
I haven't found the definitive answer to that yet, but I think not. |
After a little thinking, it may decrease the number of locks required because of the different approach to partition pruning, but won't I think mitigate entirely. This suggests that the shared memory assignment is going to be 168 bytes per possible lock, so increasing this to quite a large number (e.g. 5 years, all event types) doesn't seem untenable to me? |
OK, so 5 years of 4 event types with indexes on Of course, to actually use all of those locks would require 200 transactions simultaneously accessing the events tables, which is perhaps unlikely in practice. |
Can we set this using the configurator script? |
Postgres stores table locks in memory, with pre-allocated space for
max_locks_per_transaction * max_connections
locks. Attempting to take more locks than this at any one time will result in an out-of-memory error. In the FlowDB defaults we setmax_connections=200
, and we're not explicitly settingmax_locks_per_transaction
so that defaults to 64.Queries that select from partitioned tables require an
AccessShareLock
on each partition, as well as on every index on each of those partitions (this is true even if the query only requires data from one partition - postgres needs to obtain a lock before checking constraints to assess whether a partition is required). The events tables have a partition per day, and typically a number of indexes on each partition, so this can result in a large number of locks required for each query.E.g. if the
events.calls
table contains 2 years of data, with 3 indexes (ondatetime
,msisdn
andlocation_id
), then anEventTableSubset
query such as:would require
365*2*(3+1)=2920
'AccessShareLock' table locks. With the current default settings, just 5 such transactions (of a possible 200) would be sufficient to exhaust the memory allocated for200*64=12800
locks.From this I think it's clear that the default
max_locks_per_transaction=64
is insufficient for our heavy use of partitions, and we need to increase it. A suitable value would depend on the maximum span of data we expect to keep in the DB at any given time, along with the typical number of indexes we create on the events tables.At the same time it's worth considering whether this is the right solution. As far as I can tell there's no major reason it would be a bad idea to allow significantly more table locks per transaction, but it's possible this issue is a sign we should be approaching something a bit differently.
The text was updated successfully, but these errors were encountered: