The PostgreSQL serializable_buffers setting defaults to 32 buffers of 8kB, or 256kB of shared memory, and on most servers it sits unused. The cache backs pg_serial, a small on-disk store that Serializable Snapshot Isolation (SSI) falls back on when it can no longer track committed transactions in full. Without any SERIALIZABLE workload, it never matters.
With one, the question is how many serializable commits happen while your longest transaction is still open.
What the setting controls
PostgreSQL 17 made seven SLRU cache sizes configurable, including this one. Valid values run from 16 buffers up to 131072 (1GB) in multiples of 16, and a change requires a restart. It stays at 32 whether the machine is a laptop or has a terabyte of RAM, because it doesn’t follow shared_buffers the way transaction_buffers and subtransaction_buffers do. PostgreSQL 15 and 16 hard-code the value at 16.
Why records run out
Every serializable transaction gets a record, and that record has to outlive the commit until all transactions that overlapped it are done. The pool holds ten records per backend slot, so 1,360 on a default PostgreSQL 18 or 19 install.
That normally suffices. A run of 5,000 back-to-back serializable read-write transactions on 18.7 left pg_serial alone. Repeating it with one serializable transaction idling in a second session pushed commit 1,359 into pg_serial.
After that point, every new serializable transaction first evicts the oldest committed record. The evicted transaction’s SIREAD locks go to a shared placeholder, which pg_locks shows as SIReadLock rows with virtualtransaction -1/0. Its conflict information shrinks to a flag, and a transaction that wrote data leaves one 8-byte entry in pg_serial. The loss is detail: PostgreSQL treats summarized conflicts pessimistically, so a few transactions get serialization failures they otherwise wouldn’t.
What matters is the number of commits, not elapsed time. At 100 serializable commits a second, about 14 seconds is enough. On the test machine, 31,000 commits a second used up the pool in roughly 45 milliseconds, and a single two-second transaction produced 62,000 summarizations.
Which transactions count
- A serializable read-write transaction counts, even before it has written anything.
- A prepared serializable transaction counts, and keeps counting after its session disconnects.
- A serializable READ ONLY transaction doesn’t, unless a read-write one was open when it took its snapshot.
- READ ONLY DEFERRABLE never counts.
- REPEATABLE READ is unaffected.
The cost of a cache miss
pg_serial is an XID-indexed array with 1,024 entries per page. It covers the whole range from the oldest open serializable transaction’s xmin to the newest summarized XID, and read-committed traffic widens that range too. After ten million XIDs passed with no serializable work, the commit that started summarization took 52 milliseconds instead of 0.17, and the store had grown to 76MB.
Writing is cheap because the files skip WAL and fsync. Reading is the expensive side. When a serializable transaction hits a row version it can’t see, or one since changed, it must look up the responsible XID in pg_serial. It does that holding SerializableXactHashLock exclusively, the lock all serializable transactions need to take snapshots and commit. A cache miss therefore becomes a file read inside that lock.
The worst-case test started with an old read-only serializable transaction. After 2.4 million XIDs went by (about 18MB of pg_serial), it counted a million-row table, which needed 2.86 million lookups. A REPEATABLE READ transaction of the same age did that in 0.06 seconds. With four clients running short serializable transactions at the same time, the count took 5.7 seconds at 32 buffers and 1.2 seconds at 4096. The clients managed 6,400 transactions a second at 32 buffers and 14,500 at 4096.
Three caveats apply. All data sat in the OS page cache, so a miss cost about two microseconds, and real disks will cost more. subtransaction_buffers was set to 2048 because the same lookup first maps each XID through pg_subtrans. One test also needed max_pred_locks_per_transaction at 640, since the default of 64 ran four clients out of shared memory in about a quarter of a second.
How to check your own server
Query pg_stat_slru with WHERE name = ‘serializable’ (the row is named Serial through PostgreSQL 16). All zeros means pg_serial hasn’t been used since the last stats reset, so there’s nothing to tune. Otherwise blks_zeroed times 1,024 gives the XIDs spanned and blks_read counts misses. Counters only update when a backend goes idle outside a transaction, so a long transaction’s own reads show up once it ends.
For a live problem, look for backends in IO:SlruRead while others wait on LWLock:SerializableXactHash, and for serialization failures ending in “old pivot” or “old committed transaction”. Then sort pg_stat_activity by xact_start and check pg_prepared_xacts.
Fix the transaction, then size the cache
Deal with the offending transaction before touching the parameter. idle_in_transaction_session_timeout covers forgotten sessions and transaction_timeout (PostgreSQL 17 and later) covers runaway ones. Prepared transactions need to be resolved by hand. Long reports belong in READ ONLY DEFERRABLE transactions.
If long serializable read-write transactions are part of the design, take the XIDs consumed during the longest one (age(backend_xmin) late in its life), divide by 1,024, and round up to a multiple of 16. Set subtransaction_buffers to at least half of that. A value of 4096 costs 32MB and covers 4.2 million XIDs. Since changing PostgreSQL serializable_buffers means a restart, pick a generous number the first time.
A bigger PostgreSQL serializable_buffers value makes the slowdown shorter and milder but doesn’t remove it: even with zero misses, the scan still takes the lock 2.86 million times.
Source: thebuild.com