Why is the shared invalidation queue sized at 4096 messages?

From: Staroverov Ilja <i(dot)staroverov(at)ftdata(dot)ru>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Why is the shared invalidation queue sized at 4096 messages?
Date: 2026-11-30 11:31:48
Message-ID: 5F8C199B-3E5A-4497-90B6-11D1C158D7BE@localhost.localdomain
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Does anyone remember why 4096 was chosen for MAXNUMMESSAGES? Are there
reasons to keep this particular size today?

I traced 4096 back to the 1999 rewrite, which changed the capacity
from 4000 to 4096 [1]. The code explains the benefit of a power of two
for ring indexing. Tom's 2008 rewrite kept the capacity and changed
how backends catch up and when their caches are reset [2]. Robert
later explained how catchup signals and forced resets work [3].

In 2020, Tom was skeptical about making the queue size a GUC [4] and
separately mentioned that he had considered increasing it [5]. In the
2023 postgres_fdw investigation, Andres still saw resets with a
substantially larger queue [6]. In 2025, Yura Sokolov at Postgres
Professional reported that increasing the capacity to 16384 helped
avoid full cache resets on a client workload [7]. The recent switch
to atomics kept the capacity at 4096 in master [8, 9].

I came across this while investigating workloads that repeatedly
create and drop temporary tables. Tantor's release notes document an
increase from 16384 to 32768 for that workload [10]. Postgres
Professional also mentions enlarging the queue in its 1C:ERP case
study [11]. A recent PostgreSQL 18.6 case study measured substantial
SInvalWrite contention under similar load [12].

Are there workloads where a larger fixed queue has been shown to hurt
performance? Since the catchup and cleanup thresholds are derived
from MAXNUMMESSAGES, I'm particularly interested in any comparisons
that held those thresholds constant.

Thanks,

[1] https://github.com/postgres/postgres/commit/22fe3d4b0425fee1af0147a57e05aad70c3badd7
[2] https://postgr.es/m/373.1213813174@sss.pgh.pa.us
[3] https://www.postgresql.org/message-id/CA%2BTgmoaGzZL8P_CNO%2BUPpuOzeq8RHihXmRynrjAu72eFAoX40Q%40mail.gmail.com
[4] https://postgr.es/m/1734227.1594244155@sss.pgh.pa.us
[5] https://postgr.es/m/1937613.1601057234@sss.pgh.pa.us
[6] https://postgr.es/m/20230207044705.b462csjpi5rngso3@awork3.anarazel.de
[7] https://www.postgresql.org/message-id/7f312548-23b3-4893-a34a-f904a0f3a674%40postgrespro.ru
[8] https://commitfest.postgresql.org/patch/7001/
[9] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/sinvaladt.c#L95-L123
[10] https://docs.tantorlabs.ru/tdb/en/17_12/se/release_17_6_0.html
[11] https://habr.com/ru/companies/postgrespro/articles/1093472/ (in Russian)
[12] https://postgres.ai/blog/20261118-hidden-costs-of-create-temp-table

--
Ilya Staroverov

Browse pgsql-hackers by date

  From Date Subject
Next Message Mario Karuza 2026-11-30 11:57:14 Re: Improve hash aggregate spilling by writing only the needed columns
Previous Message vignesh C 2026-11-30 10:37:00 Re: Preserve conflict log table during upgrade