Supabase and PostgresDatabase and Postgresreference
Postgres MultiXact SLRU contention from foreign-key inserts into a hot parent row
When two transactions hold a row lock on the same row, Postgres stores the holders in a MultiXact: an id in the row’s xmax that points to a member list kept in pg_multixact, cached in SLRU (simple least-recently-used) buffers. A foreign-key insert takes a FOR KEY SHARE lock on the referenced row, so many sessions inserting children of one parent row create MultiXacts on that parent.1 This page measures how many MultiXact ids such a hot parent costs, what that does to the MultiXact SLRU counters in pg_stat_slru, what it does to per-batch latency, and which changes remove the cost. The workload models a production report of about 6,400 MultiXacts a minute, a very large count of MultiXact SLRU block accesses, and batch latency going from 15 ms to 32 ms while many sessions contend on one hot row.
TL;DR
- The generator is one transaction of 10 child-row inserts, each followed by a 1 ms client-side sleep, referencing a single hot parent row, with 64
pgbenchclients. The batch creates 1.00 MultiXact however many inserts it holds: 139,464 (97,812-184,560) MultiXacts a minute with about one member per concurrent client, 60.9 (60.7-61.6), and no parent update (MX01). - Without a write to the parent row the latency cost is small and not separable from the VM’s noise: foreign-key batch p50 20.2 (15.0-20.8) ms against 14.8 (13.1-18.9) ms with no lock, and every SLRU access a hit, 0 block reads a second (MX01 group A).
- Updating the same row turns that into member-SLRU misses and a latency penalty. A foreign-key batch plus a parent
UPDATEin 1 transaction in 10 read 38,372 (34,637-54,300) member blocks a second from disk, 30.30 (27.40-33.38) % of member block accesses, and ran at batch p50 65.8 (60.5-69.4) ms against 15.8 (14.4-16.6) ms for the same load with no foreign key (MX01 group B, pair p50 ratio 3.98 (3.83-4.83)). The ratio in the four MX04 arms was 2.62 to 3.20 at p50 and 4.64 to 6.51 at p95. - The penalty is a cliff in client count: pair p50 ratio 1.01 (0.97-1.12) at 32 clients and 2.76 (2.47-3.09) at 64, with the MultiXact rate about the same (MX06).
- On PG (PostgreSQL) 17, raising
multixact_member_buffersandmultixact_offset_buffersto 16 times the default (512 and 256 blocks, restart required) took member reads to 0 in 15 of 15 runs and cut the median batch latency about 15 to 20%; x16 p95 was still 3.06 (2.26-4.77) times the no-lock control’s (MX02). PG 15 has no such setting (MX00). - Updating a side table instead of the locked row (p50 12.5 ms against 24.7 ms) or spreading the load over 16 parent rows (p50 12.5 ms) removed the penalty with 265,356 and 321,936 MultiXacts a minute still being created. Fewer savepoints helped a little and none helped fully (MX03).
- The report’s 15 to 32 ms doubling did not reproduce at its MultiXact rate: at about 4,359 MultiXacts a minute batch p50 was 13.3 (12.8-15.1) ms against 12.8 (12.7-15.0) with no lock and no block reads (MX01
-R 100).
Which do I pick
Section titled “Which do I pick”| Situation | Choice | Why |
|---|---|---|
| A counter or last-seen column on the row that foreign keys reference | Move it to a side table or another row | side arm: p50 12.5 ms against 24.7 ms and 0 member reads (MX03) |
| Many sessions reference a few parent rows | Spread over more referenced rows where the model allows | 16 parent rows: p50 12.5 (11.8-12.7) ms, 4.9 members per MultiXact (MX03) |
pg_stat_slru shows multixact_member reads on PG 17 | Raise multixact_member_buffers and multixact_offset_buffers to about 16x and restart, and expect the rest of the penalty to stay | 0 reads in 15 of 15 runs; p50 pair ratio 0.80 and 0.85 (MX02) |
| The same pattern on PG 15 | Use the data-model levers; there is no buffer setting | Neither PG 15 image has the setting (MX00), and they read 119,259 and 136,759 member blocks a second (MX04) |
| Sessions locking one row at once are near 64 | Keep the number below the cliff, as a pool-size choice | No penalty at 32 clients, penalty at 64 on this hardware and workload (MX06) |
SELECT ... FOR SHARE on a row other sessions update | Do not use it there | Updates queue behind every share holder: update p95 4,521 ms, 98% of active samples on Lock:tuple (MX01) |
The same flow as text:
- Foreign-key inserts from 64 sessions lock one parent row with
FOR KEY SHARE. - Each batch creates one MultiXact with about one member per concurrent client.
- If nothing updates the parent row, every SLRU access is a hit and latency stays near the no-lock control.
- If the parent row is also updated, member block reads reach about 30% of accesses and the batch queues on the heap page’s content lock, at 64 clients.
- The measured fixes are to move the update, to spread the lock over more rows, or on PG 17 to raise the SLRU buffers, which removes the reads and a fifth of the penalty.
What the images are (MX00)
Section titled “What the images are (MX00)”One container per image, read-only apart from scratch tables. pg_get_multixact_members() and heap_tuple_infomask_flags() read the parent tuple’s xmax and its members while two sessions hold row locks, so “a foreign-key insert leaves a MultiXact of keysh members” is read off the tuple, not inferred from a counter.
| postgres:17 | supabase/postgres 17.11.0.004 | postgres:15 | supabase/postgres 15.19.0.004 | |
|---|---|---|---|---|
multixact_member_buffers | 32 8kB, postmaster, min 16, max 131072 | same | absent | absent |
multixact_offset_buffers | 16 8kB, postmaster, min 16, max 131072 | same | absent | absent |
pg_stat_slru row names | multixact_member, multixact_offset, subtransaction, transaction (lower case, underscores) | same | MultiXactMember, MultiXactOffset, Subtrans, Xact (CamelCase) | same |
MultiXact wait events in pg_wait_events | 7 names (MultixactCreation, MultiXactGen, MultiXactMemberBuffer, MultiXactMemberSLRU, MultiXactOffsetBuffer, MultiXactOffsetSLRU, MultiXactTruncation) | same | view absent | view absent |
| settings not at the built-in default | 15 | 64 | 15 | 65 |
shared_buffers, max_connections | 16384 8kB, 100 | 16384 8kB, 100 | 16384 8kB, 100 | 16384 8kB, 100 |
| Mechanism check | All four images |
|---|---|
| New MultiXact ids after the first session’s foreign-key insert | 0 |
| New ids after a second session’s insert on the same parent | 1, an xmax MultiXact (HEAP_XMAX_IS_MULTI) with members keysh,keysh |
A session already a locker inserts again inside a SAVEPOINT, twice | 0 new ids, 0 |
Foreign-key holder, then SELECT ... FOR SHARE | members keysh,sh |
Foreign-key holder, then a non-key UPDATE | returns in 1 to 3 ms, members keysh,nokeyupd |
- On PG 17 the buffers are settings with context
postmaster, so a change needs a restart.2 On the PG 15 images neither exists; the compile-time sizes were not read, so their values are not stated. pg_stat_slrurow names differ by major version: anything that matches rows by name (an alert, a detector) needs both spellings.3pg_stat_reset_shared('slru')does not exist on 15.19 (ERROR: unrecognized reset target: "slru");pg_stat_reset_slru(NULL)works on all four.- One foreign-key lock holder is a plain xid; the second distinct holder is what creates the MultiXact. A non-key
UPDATEof the parent does not wait forFOR KEY SHAREholders.1 The Supabase custom Postgres configuration documentation lists no MultiXact setting (doc-read 2026-12-03, nomultixactoccurrence in the mirrored Supabase docs); whether the Management API (application programming interface) accepts the two settings was not tested (MX05 did not run).
The generator (MX01)
Section titled “The generator (MX01)”Run 1, postgres:17 at defaults, 64 clients, one hot parent row. The “batch” is 10 child inserts in one transaction. What takes a lock on the parent is the arm: the foreign key (the referential-integrity trigger’s FOR KEY SHARE), an explicit SELECT 1 FROM parent WHERE id = :p FOR SHARE, or nothing (nofk, the control). “Parent update” arms add a second script, UPDATE parent SET hits = hits + 1 WHERE id = :p in its own transaction, at 9 batches to 1 update. Group C rate-limits with pgbench -R; group D turns synchronous_commit on (the other 46 of 48 arms ran it off, because with it on the first smoke run spent most active time in LWLock:WALWrite and IO:WalSync and buried the effect). Autovacuum was off on the four lab tables. Median (min-max) over 3 runs:
| Arm | Batches/s | Batch p50 ms | Batch p95 ms | MultiXacts/min | Per batch | Members per MultiXact | Member blocks read/s | Read share % |
|---|---|---|---|---|---|---|---|---|
a_nofk no lock (control) | 3,554 (2,918-4,068) | 14.8 (13.1-18.9) | 35.8 (24.2-38.4) | 0 | 0.00 | 0.0 | 0 | 0.00 |
a_fk FK (foreign key) insert | 2,324 (1,630-3,076) | 20.2 (15.0-20.8) | 55.2 (46.2-142.5) | 139,464 (97,812-184,560) | 1.00 | 60.9 (60.7-61.6) | 0 | 0.00 |
a_fk_sp FK insert, savepoint per insert | 1,844 (1,707-2,791) | 30.1 (19.3-30.5) | 62.2 (45.5-82.5) | 110,634 (102,402-167,457) | 1.00 | 61.0 (60.9-61.6) | 0 | 0.00 |
a_share SELECT FOR SHARE | 2,740 (1,785-3,764) | 19.5 (14.4-21.9) | 43.2 (28.1-106.1) | 164,379 (107,109-225,813) | 1.00 | 61.0 (60.7-61.9) | 0 | 0.00 |
b_nofk control + parent update | 3,412 (2,682-3,661) | 15.8 (14.4-16.6) | 29.9 (26.9-55.5) | 0 | 0.00 | 0.0 | 0 | 0.00 |
b_fk FK insert + parent update | 848 (651-865) | 65.8 (60.5-69.4) | 176.5 (141.3-243.2) | 90,741 (65,217-93,783) | 1.78 (1.67-1.81) | 55.1 (54.9-55.4) | 38,372 (34,637-54,300) | 30.30 (27.40-33.38) |
b_fk_sp FK insert, savepoint per insert + update | 749 (345-772) | 76.8 (70.0-130.0) | 180.6 (162.1-433.4) | 73,296 (28,125-76,548) | 1.58 (1.36-1.70) | 56.4 (55.7-57.7) | 36,289 (7,332-39,423) | 29.22 (18.17-30.10) |
b_share SELECT FOR SHARE + update | 221 (203-269) | 13.9 (12.8-14.8) | 27.7 (20.7-48.9) | 12,783 (11,775-15,483) | 0.97 (0.96-0.97) | 6.8 (6.6-7.2) | 0 | 0.00 |
c_nofk_r100 control + update, 100 tps target | 89 (88-95) | 12.8 (12.7-15.0) | 26.6 (17.2-47.5) | 0 | 0.00 | 0.0 | 0 | 0.00 |
c_fk_r100 FK + update, 100 tps | 89 (86-89) | 13.3 (12.8-15.1) | 53.2 (24.2-395.8) | 4,359 (4,254-4,740) | 0.82 (0.79-0.92) | 3.8 (2.8-8.4) | 0 | 0.00 |
c_nofk_r400 control, 400 tps | 357 (354-363) | 12.7 (12.6-55.6) | 51.1 (34.0-309.0) | 0 | 0.00 | 0.0 | 0 | 0.00 |
c_fk_r400 FK + update, 400 tps | 358 (358-363) | 12.5 (12.5-44.5) | 20.4 (15.5-366.9) | 23,706 (23,631-25,782) | 1.10 (1.10-1.18) | 5.8 (5.6-22.1) | 0 | 0.00 |
c_nofk_r1000 control, 1000 tps | 899 (892-901) | 13.1 (12.2-90.8) | 570.3 (56.1-712.4) | 0 | 0.00 | 0.0 | 0 | 0.00 |
c_fk_r1000 FK + update, 1000 tps | 898 (898-900) | 12.7 (12.3-17.9) | 403.7 (17.0-532.9) | 64,320 (60,324-68,520) | 1.19 (1.12-1.27) | 21.4 (12.7-30.4) | 2,750 (0-7,441) | 2.95 (0.00-8.04) |
d_nofk_sync control + update, synchronous_commit on | 3,971 (2,502-4,335) | 13.3 (12.5-18.3) | 25.1 (19.6-49.0) | 0 | 0.00 | 0.0 | 0 | 0.00 |
d_fk_sync FK + update, synchronous_commit on | 1,050 (713-1,072) | 49.5 (45.5-77.5) | 128.8 (109.5-170.6) | 122,868 (87,927-125,157) | 1.95 (1.95-2.06) | 54.5 (53.3-54.5) | 88,837 (45,814-91,101) | 33.80 (31.58-35.67) |
- Ten inserts in the batch create one MultiXact, not ten, because a holder that inserts again creates none (MX00). A savepoint around every insert also gives 1.00 per batch, and so does
SELECT ... FOR SHAREbefore inserting into a table with no foreign key. Savepoints did not add MultiXacts in any arm; they added xid assignment (LWLock:XidGenin the top waits ofa_fk_sp, 3% and 6% in two runs) and latency. - The foreign-key batch read the member SLRU about five times more than one explicit lock: 11.2 (11.1-11.3) member blocks a batch against 2.1 (2.1-2.1) for
FOR SHARE. That is inferred from the counts, not traced: the foreign-key check looks the row up on each of the 10 inserts, the explicit lock once. With no parent update every access was a hit: 20,688 to 26,083 hits a second for the foreign-key arms, 0 reads. - Without a write to the parent row the latency cost is small: p95 55.2 (46.2-142.5) against 35.8 (24.2-38.4) ms, p95 higher in 3 of 3 pairs, pair ratio 1.44 (1.29-5.89), while the p50 ranges overlap.
SELECT FOR SHAREpair p95 ratio 1.12 (0.79-4.39) did not separate. The savepoint-per-insert batch was slower again: p50 30.1 (19.3-30.5) ms, pair p95 ratio 1.62 (1.27-3.41). - A parent-row
UPDATEturned the same lock load into the penalty: p50 pair ratio 3.98 (3.83-4.83) and p95 4.72 (3.18-9.04) over the control, 53.20 (45.27-62.79) member block reads a batch and 175.6 (165.2-188.1) member blocks a batch in all. The batch created 1.78 (1.67-1.81) MultiXacts instead of 1.00. The updates cannot be the whole reason: the 9:1 mix runs about 0.11 updates a batch and the extra is 0.78 MultiXacts a batch. Not traced: one candidate is that locking a row whose newest version was just updated also locks the newer version (heap_lock_updated_tupleexists inheapam.cand is called fromheap_lock_tuple); another is MX00’skeysh,nokeyupdMultiXact made by each update itself.4 The same ratio held withsynchronous_commiton (group D: p50 3.96 (3.42-4.23), p95 5.14 (3.48-5.59)), so turning commit flushes off did not create the effect. - What limits that arm is contention, not CPU or SLRU lock waits. 43.0 (42.9-47.3) of the 64 backends were
activeon average against 5.4 (3.9-5.5) in the control; 93% of those samples sat inLWLock:BufferContent(the heap page’s content lock) and the MultiXact SLRU locks were at about 1% (1% to 12% in thesynchronous_commiton arm). Mid-run CPU was 184% (171-257) for the server and 39% (33-40) for the client container on a 10-CPU VM. The source reading, not profiled (PostgreSQLREL_17_11):heap_lock_tupletakes the buffer’s exclusive content lock and, with it held, callsHeapTupleSatisfiesUpdateandcompute_new_xmax_infomask; for a MultiXactxmaxthese reachGetMultiXactIdMembers(a backend-local cache of 256 entries first, then the SLRU banks) andMultiXactIdExpand, which checks every existing member withTransactionIdIsInProgress. So SLRU reads and a per-member liveness check both happen under the page lock. The waits are consistent with that reading, and MX02 and MX06 test it. SELECT FOR SHAREplus the parentUPDATEis a different failure. The batch stayed at p50 13.9 (12.8-14.8) ms, but theUPDATEscript’s p95 was 4,521 (3,612-4,648) ms and 98% of active samples waited onLock:tuple:FOR SHAREconflicts withUPDATE, so the updater queues behind every share holder.1 That is lock queueing, not SLRU pressure.- At the report’s MultiXact rate this model shows no latency effect.
-R 100(89 batches a second plus 10 updates a second): batch p50 13.3 (12.8-15.1) ms against 12.8 (12.7-15.0) for the control, 0 member block reads, 57.4 (54.0-60.2) member block hits a batch (5,083 hits a second; derived: about 440 million hits a day at that rate).-R 400: p50 12.5 (12.5-44.5) against 12.7 (12.6-55.6), 0 reads. The p95 and p99 cells of the-Rarms contain single runs at 300 to 1,000 ms in control arms as well as foreign-key arms, so tails at those rates are VM noise and the pair ratios there (3.09 (0.91-8.34) and 0.46 (0.40-1.19)) mean nothing.-R 1000held its target but its control’s p95 range 56.1-712.4 shows the same noise; reads began (2,750 (0-7,441) a second, in 2 of 3 runs). What reproduced the penalty was a parent-row update on top of high concurrency, about 90,000 or more MultiXacts a minute at 64 clients, not the report’s rate. - How long the default member buffers cover (cell
member_buffer_history_s, 32 blocks over member pages started a second): 213.33 (80.00-213.33) s at-R 100, 22.07 (5.52-23.70) s at-R 400, 2.28 (1.51-4.10) s at-R 1000, 0.63 (0.61-0.87) s in the closed-loop parent-update arm. Member reads appeared when that figure dropped to a few seconds, not before.
SLRU buffer size on PG 17 (MX02)
Section titled “SLRU buffer size on PG 17 (MX02)”MX01 group B shape (foreign-key batches plus a parent UPDATE at 9:1, 64 clients, one hot row), five postgres:17 containers differing only in multixact_member_buffers / multixact_offset_buffers (both postmaster context, so one container cannot change between runs): default 32 / 16, x2 64 / 32, x4 128 / 64, x16 512 / 256, x128 4096 / 2048, plus the no-lock control on the default container. Run 2 (n = 5, every level) and run 5 (n = 10, repeated on the arms that matter because run 2’s latency ranges overlapped):
| Arm | Run | Batch p50 ms | Batch p95 ms | Member blocks read/s | Read share % |
|---|---|---|---|---|---|
| default | 2 | 44.4 (33.5-63.7) | 94.0 (74.0-161.1) | 110,501 (60,458-115,194) | 32.13 (31.31-34.16) |
| x2 | 2 | 37.8 (28.2-51.9) | 81.5 (60.8-134.9) | 45,559 (24,253-86,725) | 19.48 (13.91-21.15) |
| x4 | 2 | 36.6 (31.1-39.9) | 85.1 (70.6-111.1) | 6,143 (3,403-30,762) | 1.48 (0.92-4.41) |
| x16 | 2 | 35.5 (26.0-39.3) | 75.5 (55.1-84.5) | 0 (0-0) | 0.00 |
| x128 | 2 | 35.5 (33.3-43.1) | 83.4 (64.8-89.5) | 0 (0-0) | 0.00 |
| control, default buffers | 2 | 12.3 (11.9-13.3) | 17.3 (15.6-28.3) | 0 | 0.00 |
| default | 5 | 26.5 (22.5-34.0) | 51.1 (37.6-132.6) | 138,413 (87,565-151,421) | 30.94 (24.26-33.58) |
| x16 | 5 | 23.4 (19.6-28.2) | 42.1 (33.5-63.0) | 0 (0-0) | 0.00 |
| control, default buffers | 5 | 12.7 (12.0-12.9) | 13.7 (13.2-14.8) | 0 | 0.00 |
- Member reads disappeared at 16 times the default; at 4 times a few were left, and no level between 4x and 16x was run. Offset-SLRU reads were 5,855 (848-10,604) a second at the default 16 offset buffers and 0 at every raised level (run 2). The buffers covered 0.43 (0.35-0.64) s of history at the default, 1.54 (1.32-1.71) s at x4 and 5.84 (4.25-5.94) s at x16: reads went away once the buffers covered a few seconds.
- Batch latency improved about 15 to 20% at the median and not back to the control. x16 against default, per-run pairs: p50 0.80 (0.53-1.09) in run 2 and 0.85 (0.77-1.03) in run 5, p95 0.59 (0.52-1.02) and 0.81 (0.48-1.10). The ranges reach 1.03 to 1.10, so the improvement is real in most pairs and small. x16 p95 was still 3.06 (2.26-4.77) times the control’s in run 5 (default 3.74 (2.66-10.04)); x128, with 48.02 (43.16-54.65) s of buffer history, was 4.15 (3.16-5.26) times the control in run 2.
- So the member reads are about a fifth of this workload’s penalty. Run 5 medians: default 26.5 ms, x16 23.4 ms, control 12.7 ms, so the reads account for 3.1 of the 13.8 ms above the control (derived). With reads at zero, 35.9 (30.3-40.8) backends were still active on average (default 42.0 (36.5-47.7)), and
LWLock:BufferContentwas 88% of active samples at x16 against 69% at the default, whereLWLock:MultiXactMemberSLRU(18%) andLWLock:MultiXactMemberBuffer(6%) took the difference (run 1 of each arm in run 5). - Runs 2 and 5 are not comparable with each other: the default arm’s p50 was 44.4 ms in run 2 and 26.5 ms in run 5 at similar VM load. Memory for the raised buffers: 512 member and 256 offset buffers at 8 kB are 4 MiB and 2 MiB, and x128 is 32 MiB and 16 MiB (arithmetic from the settings; shared memory use was not measured).
Mitigations (MX03)
Section titled “Mitigations (MX03)”Base is MX01’s group B shape; each arm changes one thing. n = 3, postgres:17 defaults, 64 clients.
| Arm | Batches/s | Batch p50 ms | Batch p95 ms | MultiXacts/min | Member blocks read/s | Read share % |
|---|---|---|---|---|---|---|
base FK insert + parent update | 2,409 (1,446-2,420) | 24.7 (24.4-37.2) | 46.5 (42.7-78.0) | 222,258 (149,070-225,498) | 114,440 (96,973-122,115) | 29.48 (26.31-31.63) |
nofk no foreign key + update | 5,065 (4,962-5,124) | 11.9 (11.8-12.0) | 14.7 (14.5-16.0) | 0 | 0 | 0.00 |
sp_one 1 savepoint per batch | 1,888 (1,115-1,912) | 29.9 (28.4-44.5) | 60.3 (57.6-123.7) | 187,311 (117,984-189,438) | 121,529 (77,447-162,679) | 32.58 (29.91-35.92) |
sp_per savepoint per insert (10) | 1,388 (1,220-1,477) | 35.4 (33.4-42.3) | 97.2 (91.3-104.3) | 141,939 (124,962-150,816) | 134,415 (102,430-154,216) | 32.12 (31.08-34.24) |
side update goes to a side table | 4,423 (4,105-4,939) | 12.5 (12.1-12.6) | 22.4 (14.0-27.8) | 265,356 (246,297-296,328) | 0 | 0.00 |
hot16 16 parent rows | 4,914 (4,494-5,210) | 12.5 (11.8-12.7) | 14.1 (13.5-20.8) | 321,936 (294,684-341,022) | 0 | 0.00 |
upd_rare update at 1 in 100 | 2,594 (2,440-2,994) | 22.5 (21.2-23.4) | 47.6 (34.5-49.7) | 162,123 (152,976-187,185) | 120,809 (119,032-125,224) | 54.65 (52.51-55.19) |
- Moving the update off the locked row, or spreading over 16 parent rows, removed the penalty: pair p50 ratios against base 0.49 (0.34-0.51) and 0.48 (0.34-0.52), 0 member block reads.
sidestill created 265,356 MultiXacts a minute of 62.1 (62.0-62.3) members each andhot16321,936 of 4.9 (4.9-4.9): the penalty came from creating MultiXacts on a row that is also updated. - Dropping the foreign key removed it too (
nofk), which is the no-lock control by construction: it measures what the lock costs and carries no recommendation to drop the key. - Fewer savepoints helped a little and did not fix it. Savepoints per batch: 0 (base) p50 24.7 ms; 1 (
sp_one) 29.9, pair p50 ratio 1.19 (1.15-1.23); 10 (sp_per) 35.4, ratio 1.35 (1.14-1.45), pair p95 ratio 2.09 (1.17-2.44). More savepoints were slower than fewer and none was faster than none; none changed the member read rate materially (pair ratios 1.25 (0.68-1.33) and 1.26 (0.90-1.39)). The cost that rose with savepoint count is consistent with extra subtransaction xid assignment, which was not isolated here. - One update in 100 batches instead of one in 10 did not help:
upd_rarep50 pair ratio 0.86 (0.63-0.92), member reads 120,809 (119,032-125,224) a second against 114,440, read share 54.65 (52.51-55.19)% against 29.48 (26.31-31.63)%. At 64 clients a 1% update share was already enough; a much rarer update was not measured. - Savepoints touch a different SLRU. The
subtransactionSLRU recorded hits only in the savepoint arms and 0 reads in all 177 arm-runs: 1,115 to 1,912 hits a second insp_oneand 12,198 to 14,772 insp_per. That is about one hit per savepoint (inferred from the match, not traced to a code path); with at most 10 savepoints a batch no backend came near the 64 cached subtransactions. - The base arm’s p50 was 65.8 ms in MX01, 44.4 in MX02 run 2, 26.5 in MX02 run 5 and 24.7 here; only within-run comparisons are meaningful.
Images and client count (MX04, MX06)
Section titled “Images and client count (MX04, MX06)”MX04 ran four containers alternating at defaults and 64 clients, the foreign-key batch plus the 9:1 parent update against the no-lock control on each image (n = 3).
| Image | FK + update batch p50 ms | Control p50 ms | Pair p50 ratio | Pair p95 ratio | Member blocks read/s | Read share % |
|---|---|---|---|---|---|---|
postgres:17 | 31.5 (30.9-33.5) | 12.2 (11.8-12.3) | 2.62 (2.58-2.74) | 4.64 (3.66-5.30) | 150,376 (114,779-159,365) | 31.38 (30.41-34.24) |
supabase/postgres:17.11.0.004 | 35.8 (31.1-36.6) | 12.4 (11.7-12.5) | 2.87 (2.65-2.95) | 6.51 (4.77-8.13) | 122,194 (96,343-127,985) | 30.33 (29.72-31.27) |
postgres:15 | 38.5 (29.5-41.1) | 12.1 (11.8-12.2) | 3.16 (2.51-3.40) | 5.89 (4.48-6.99) | 119,259 (116,672-132,443) | 36.92 (35.39-38.71) |
supabase/postgres:15.19.0.004 | 38.6 (34.9-39.7) | 12.0 (12.0-12.1) | 3.20 (2.90-3.31) | 6.13 (4.75-7.09) | 136,759 (120,181-143,898) | 38.97 (38.10-39.42) |
All four behave alike. Supabase over stock at the same major: no separable difference (17: pair p95 1.49 (0.94-1.84), MultiXacts a minute ratio 0.90 (0.80-1.04), control p95 ratio 1.05 (0.84-1.05); 15: p95 1.02 (0.96-1.14)). The supabase image differs from stock in 14 settings by value, among them wal_level logical, effective_cache_size, max_replication_slots and 11 preloaded libraries; none was isolated, so no difference is attributed to any of them. PG 15 over PG 17 at defaults: p95 1.18 (0.87-1.55), member reads 0.881 (0.748-1.016) of PG 17’s.
MX06 added the client-count sweep after MX02 left most of the penalty in place with the reads gone: if the cost under the page lock grows with the number of members, the foreign-key-over-control ratio should grow with the number of concurrent clients (about one member per client). Stock postgres:17, n = 3, one hot parent, the 9:1 update.
| Clients | FK + update batch p50 ms | MultiXacts/min | Members per MultiXact | Member blocks read/s | Pair p50 ratio | Pair p95 ratio | Active backends |
|---|---|---|---|---|---|---|---|
| 8 | 12.8 (12.2-13.1) | 39,876 (31,140-41,313) | 7.6 (7.5-7.8) | 0 | 1.02 (1.01-1.06) | 1.07 (1.01-1.29) | 0.4 |
| 16 | 12.1 (11.9-22.1) | 86,949 (43,650-87,723) | 15.5 (15.1-15.6) | 0 | 1.05 (1.02-1.81) | 1.04 (1.03-3.55) | 0.8 |
| 32 | 12.0 (12.0-13.1) | 154,848 (126,906-160,653) | 31.0 (30.9-31.2) | 0 | 1.01 (0.97-1.12) | 1.68 (1.16-3.24) | 4.6 (4.0-5.7) |
| 64 | 33.2 (29.0-36.9) | 168,948 (146,424-185,904) | 56.9 (56.2-57.3) | 155,604 (98,127-158,133) | 2.76 (2.47-3.09) | 5.66 (4.68-6.88) | 45.3 (43.6-45.6) |
The penalty is a cliff between 32 and 64 clients. At 32 the MultiXact rate was within about 9% of 64’s but the members per MultiXact were 31.0 against 56.9, the active backends 4.6 against 45.3 and the member reads 0 against 155,604 a second (31.85 (30.47-32.71) % of accesses). That is consistent with, not proof of, a queue on the heap page’s content lock that saturates once the number of lockers times the per-lock work, which grows with the member count, passes what the lock can serve. Not isolated: the per-member cost on its own (no profile, no 40 or 48 client point, no run holding the members constant while raising clients), and whether the cliff sits at another client count on other hardware. At 8 clients, about six times the report’s MultiXact rate, there was no latency difference at all.
What was not measured
Section titled “What was not measured”- Any hosted project (compute size, disk, platform settings, the pooler in front of the sessions), and whether
postgres-configaccepts the two buffer settings (MX05 did not run). - The report’s own workload. The model is one hot row, 10-row batches with 1 ms think time, a 9:1 update share, the simple query protocol and 64 clients at most. The 15 ms to 32 ms doubling did not reproduce at the report’s MultiXact rate, so what else the real system had is open: long-running transactions holding old MultiXacts, a row with a long version chain, many hot rows at different update rates, prepared statements, a pooler’s connection churn.
- Long-held old MultiXacts and vacuum: autovacuum was off on the lab tables, and MultiXact freezing,
pg_multixacttruncation and reads from a MultiXact that outlives its transactions were not exercised. - The per-member cost alone, a profile of the page-lock hold time, client counts between 32 and 64 or above 64, and
max_connectionsabove 100. - Subtransaction overflow: batches here use at most 10 savepoints, below the 64 a backend can cache, so the regime that sends every snapshot to the
subtransactionSLRU was not entered. - PG 16, 18 and 19; supabase images other than 17.11.0.004 and 15.19.0.004; an ARM (Advanced RISC Machines) against x86 comparison (all runs are linux/arm64); the effect of
shared_buffers,wal_level=logicaland the preloaded extensions separately;synchronous_commiton for any arm except MX01 group D; and the memory use of the raised buffers.
Reading the numbers
Section titled “Reading the numbers”- Latency is the exact percentile (nearest rank) of the
pgbench -lper-transaction log, field 3, in microseconds, over every batch logged in the 20 s window.5 MultiXact ids created are the delta ofmxid_age('1'::xid)over the window, cross-checked againstpg_control_checkpoint().next_multixact_idafter aCHECKPOINTon each side; no run was flagged for differing by more than 1. Where backends wait comes frompg_stat_activitysampled every 100 ms. - “Work happened” was checked: committed child rows minus the rows the log says completed was 0 in every run of every table, and no run had a failed transaction.
- Latency ranges overlap in places and the VM was shared (VM load before each arm-run 4.3 to 39.9), so only within-run, adjacent-pair comparisons are used for ratios. Figures from different runs of the same arm differ by up to 2.5 times (the default arm’s p50 in MX02 run 2 and run 5).
- One hot parent, one workload shape; the cliff client count, the 16x buffer level and the update-share result are properties of this rig.
What to do about it
Section titled “What to do about it”| Practice | Evidence | Module |
|---|---|---|
| Do not update the row that foreign keys lock | Update going to a side table: p50 12.5 ms against 24.7 ms, 0 member reads, with 265,356 MultiXacts a minute still created; no update at all: 0 reads | MX03, MX01 |
| Spread the lock over more referenced rows | 16 parent rows: p50 12.5 (11.8-12.7) ms with 4.9 members per MultiXact | MX03 |
| Keep sessions locking one row below the cliff | No penalty at 32 clients, penalty at 64; the MultiXact rate was similar at both. A pool-size choice, not a general threshold | MX06 |
| On PG 17, raise the SLRU buffers to about 16x after reads appear | 512 / 256 blocks: 0 reads in 15 of 15 runs from 110,501 and 138,413 a second, median latency down 15 to 20%, the rest of the penalty stays | MX02 |
| On PG 15, use the data-model levers | No buffer setting exists; both PG 15 images read 119,259 and 136,759 member blocks a second | MX00, MX04 |
| Use fewer savepoints per batch | p50 24.7, 29.9 and 35.4 ms at 0, 1 and 10 savepoints; no MultiXacts added; the read rate did not change | MX01, MX03 |
Avoid FOR SHARE on a row other sessions update | Update p95 4,521 (3,612-4,648) ms, 98% of active samples on Lock:tuple | MX01 (b_share) |
Read pg_stat_slru and the MultiXact* wait events to detect it | A read share of about 30% at about 100,000 hits a second was the penalty state; 0 reads at 28,000 hits a second was not | MX00, MX01, MX06 |
Match pg_stat_slru rows by both name spellings across majors | Lower case with underscores on 17.11, CamelCase on 15.19 | MX00 |
Reproducing
Section titled “Reproducing”The experiment is experiments/multixact-slru in supabase-lab. It needs Docker, the pinned images and Bun.
make probe # MX00-MX06, about 60 minutes at n = 3make probe ONLY=MX02 MX_RUNS=5 # one module, 5 runs per armmake facts # measurements of the newest run as markdownEvidence
Section titled “Evidence”| Claim | Status | How it was checked |
|---|---|---|
One MultiXact per locking transaction, keysh,keysh members, none for a repeated holder | measured on the tuple, 4 images | MX00, run 1 facts |
| Rates, member reads, latency of 16 arms | measured, n = 3 | MX01, run 1 facts |
| Buffer sizes x1 to x128 | measured, n = 5 and n = 10 | MX02, run 2 facts, run 5 facts |
| Mitigation arms | measured, n = 3 | MX03, run 3 facts |
| Four images alike | measured, n = 3 | MX04, run 4 facts |
| Client-count cliff between 32 and 64 | measured, n = 3; the mechanism is consistent with, not proof of, the page-lock reading | MX06, run 6 facts |
| Page-lock and SLRU code path | source-read, not profiled4 | PostgreSQL REL_17_11 heapam.c, read for the lab run, not re-read for this page |
| Buffer defaults 32 and 16, restart required | documented2; measured on the PG 17 images | MX00; doc-read again for this page |
FOR KEY SHARE and FOR SHARE conflict rules | documented1; measured on the tuples and in b_share | MX00, MX01 |
| Hosted acceptance of the buffer settings | not measured | MX05 scaffold, did not run |
No docs-versus-runtime disagreement was found, so nothing was filed upstream.
Modules
Section titled “Modules”| Module | Experiment | Test | Artifact |
|---|---|---|---|
| MX00 | multixact-slru | mx00-inventory.ts | run-2026-12-03T06-15-53-848Z |
| MX01 | multixact-slru | mx01-generator.ts | run-2026-12-03T06-15-53-848Z |
| MX02 | multixact-slru | mx02-buffers.ts | run-2026-12-03T06-37-44-945Z, run-2026-12-03T07-12-02-273Z |
| MX03 | multixact-slru | mx03-mitigations.ts | run-2026-12-03T06-51-08-771Z |
| MX04 | multixact-slru | mx04-images.ts | run-2026-12-03T07-00-11-688Z |
| MX05 | multixact-slru | mx05-hosted.ts | none published (scaffold, skipped) |
| MX06 | multixact-slru | mx06-clients.ts | run-2026-12-03T07-24-58-675Z |
Related docs
Section titled “Related docs”- PostgREST retries of an RPC (remote procedure call) that raises 40001 - a looping retry creates one MultiXact per attempt when a second locker holds the same rows, the other route to
pg_multixactgrowth. - Postgres lock table capacity and out of shared memory - table-level lock entries and the SERIALIZABLE predicate locks, beside the row-level modes counted here.
- Postgres lock queue behind ACCESS EXCLUSIVE, lock_timeout and PgBouncer - the queue a conflicting lock request builds, which is what
FOR SHAREplus anUPDATEdid on a single row. - Postgres statistics counters - what resets
pg_stat_slruand the other cumulative counters read here. - Foreign keys to auth.users block sign-in during validation - the table-level lock modes of DDL (data definition language) on
auth.users, where this page starts at the row lock a foreign-key insert takes.
References
Section titled “References”-
PostgreSQL Global Development Group, “Explicit Locking,” PostgreSQL 17 Documentation. https://www.postgresql.org/docs/17/explicit-locking.html ↩ ↩2 ↩3 ↩4
-
PostgreSQL Global Development Group, “Resource Consumption,” PostgreSQL 17 Documentation,
multixact_member_buffersandmultixact_offset_buffers. https://www.postgresql.org/docs/17/runtime-config-resource.html ↩ ↩2 -
PostgreSQL Global Development Group, “The Cumulative Statistics System,” PostgreSQL 17 Documentation,
pg_stat_slru. https://www.postgresql.org/docs/17/monitoring-stats.html ↩ -
PostgreSQL Global Development Group, “src/backend/access/heap/heapam.c,” postgres/postgres, tag
REL_17_11. https://github.com/postgres/postgres/blob/REL_17_11/src/backend/access/heap/heapam.c ↩ ↩2 -
PostgreSQL Global Development Group, “pgbench,” PostgreSQL 17 Documentation, per-transaction logging. https://www.postgresql.org/docs/17/pgbench.html ↩