PostgreSQL 19Dev & Eng
Content type: Hands-on
6 min read
PostgreSQL 19 speeds up VACUUM on GIN indexes larger than the cache
- Reading
- 6 min
- Tables
- 1
- Code
- 3
A test comparing PostgreSQL 18 and 19 shows a gain of up to 2.2 times in GIN index cleanup when they exceed shared_buffers; in small indexes, the difference amounts to no more than milliseconds.
Why a GIN index can weigh more than the table suggests
GIN (Generalized Inverted Index) is the index type used for tsvector, jsonb, and array columns, structures in which each row can contain dozens of searchable values. Unlike a B-tree index, where one row becomes one entry, in GIN a single row can generate many entries: each word of a document, each element of an array, each key of a JSON.
The practical result is that a table with a modest row count can accumulate a disproportionately large GIN index. And during VACUUM, cleanup needs to traverse a good part of that structure: the amount of work in heap cleanup and the amount of index reading don't grow at the same rate.
This is where the change tested in an article published on Planet PostgreSQL, and republished on the Microsoft for PostgreSQL blog (the source of this text), comes in. PostgreSQL 19 now allows this GIN index cleanup path to use streaming reads.
The test design: full cache versus overflowing cache
The question that motivated the experiment is direct: does the difference between PostgreSQL 18 and 19 change when the GIN index no longer fits in shared_buffers? To answer it, the study's author compared PostgreSQL 18.6 and PostgreSQL 19 across three independent pairs of Azure Database for PostgreSQL Flexible Server instances, all with 16 vCPUs, 1 TiB of Premium storage, zone-redundant high availability, and shared_buffers fixed at 16 GiB.
Each case started from a fresh database, with a simple table and a newly created GIN index on the tags (array) and document (tsvector) columns, with fastupdate = off so as not to mix pending list behavior into the measurement. Autovacuum was turned off only on these benchmark tables, in isolation; on a real application table, it should remain on.
The tested table followed this format:
CREATE TABLE public.docs (
id bigint NOT NULL,
tags text[] NOT NULL,
document tsvector NOT NULL,
payload text NOT NULL
) WITH (autovacuum_enabled = false, toast.autovacuum_enabled = false);
CREATE INDEX docs_search_gin
ON public.docs
USING gin (tags, document)
WITH (fastupdate = off);The measured command was an isolated VACUUM, without TOAST, without parallel workers, and without heap truncation, so that the comparison would fall exclusively on index reading:
VACUUM (VERBOSE, INDEX_CLEANUP ON, PARALLEL 0, PROCESS_TOAST FALSE, TRUNCATE OFF) public.docs;The numbers: little difference until the index overflows the cache
Four index sizes were tested, from 0.50 GiB to 26.62 GiB, each with three independent runs per version. The medians summarize the pattern found:
| Rows | GIN Size | PG18 | PG19 | Gain |
|---|---|---|---|---|
| 1 million | 0.50 GiB | 0.05 s | 0.04 s | 1.25x |
| 10 million | 2.78 GiB | 0.27 s | 0.25 s | 1.08x |
| 100 million | 21.30 GiB | 12.51 s | 9.83 s | 1.27x |
| 125 million | 26.62 GiB | 25.19 s | 11.43 s | 2.20x |
In the two smaller sizes, the entire index fit within the 16 GiB of shared_buffers: zero index page reads during cleanup, and the difference between versions stayed in the range of milliseconds, with no operational relevance. The scenario changes in the two larger sizes, which exceed the available cache: in the 21.30 GiB case, cleanup read about 953 thousand blocks of the target index; in the 26.62 GiB case, about 1.657 million blocks.
An important technical caveat is worth noting, at the point where the author comments on the nature of the measurement:
I wouldn't label this a controlled cold-disk benchmark.
author of the original article, published on Planet PostgreSQL
A PostgreSQL buffer read only means that the page wasn't in shared_buffers; it may very well have come from the operating system cache or from a cache layer of the managed storage, not necessarily from physical disk. This doesn't invalidate the observed pattern, but it limits the conclusion to a "read regime different from the PostgreSQL cache," not to "precisely measured physical I/O."
What changes for those who operate PostgreSQL in production
For those who administer databases with real data volume, the practical takeaway is objective: the gain from PostgreSQL 19 shows up when GIN index cleanup already spends time reading pages into the buffer, not when the index lives comfortably in memory. In individual runs, the gain per pair ranged from 1.40x to 2.24x in the largest case, and from 1.26x to 1.50x in the intermediate case; the 2.20x median doesn't capture the full variation between runs.
In summary: before celebrating an isolated speedup number, you need to confirm whether your GIN index actually exceeds the shared_buffers available on the production server. That is the factor that decides whether the streaming read change is worth the upgrade effort or goes unnoticed.
Another point the test makes explicit: it isolated the cleanup of a newly created index, without deletes, updates, or a concurrent pending list. A full autovacuum cycle on an application table under real write load requires a different measurement, because the behavior of dead tuple removal and the pending list wasn't part of this experiment.
The checklist before considering the upgrade
To assess whether this scenario applies to your own environment, the first step is to map the size of existing GIN indexes against the configured shared_buffers:
SHOW shared_buffers;
SELECT n.nspname AS schema_name,
c.relname AS index_name,
pg_size_pretty(pg_relation_size(c.oid)) AS index_size
FROM pg_class AS c
JOIN pg_namespace AS n ON n.oid = c.relnamespace
JOIN pg_am AS am ON am.oid = c.relam
WHERE c.relkind = 'i'
AND am.amname = 'gin'
ORDER BY pg_relation_size(c.oid) DESC;With that list in hand, a few precautions are worth taking before attributing any future gain to PostgreSQL 19:
- Capture real
VACUUM (VERBOSE)evidence in the current environment: elapsed time, index buffer reads and hits. - Compare equivalent data, index definitions, and maintenance settings between the two versions: it's not valid to measure a freshly built index against one that's already been cleaned before.
- If cumulative statistics are used, take snapshots before and after the specific operation, instead of attributing server lifetime counters to a single
VACUUM. - Also test under the real cleanup conditions of the application: deletes, updates, pending list, and concurrency, not just the freshly created, untouched index from the lab.
Where the gain doesn't show up
The test is also honest about its own limits. The settings used (maintenance_work_mem = '1GB', vacuum_cost_delay = 0, vacuum_cost_limit = 10000, among others) favored maximum throughput of the maintenance operation, turning off the mechanism that normally limits the impact of VACUUM on other concurrent workloads. In production, zeroing out cost_delay has this side effect and needs to be carefully evaluated, not copied from the lab.
For small indexes, the result is clear: moving from PostgreSQL 18 to 19 doesn't fix anything that wasn't already fast. The streaming reads path only becomes interesting when GIN index cleanup is already, today, a visible item in the database's maintenance time budget, precisely because it grows faster than the table's row count would suggest.
Translated from the Brazilian Portuguese original · Read the original
PostgreSQL 19's WAIT FOR LSN Matches Synchronous Replication in Tests, But Carries an Unfixed Bug
Load tests with hundreds of thousands of transactions show that PostgreSQL 19's WAIT FOR LSN delivers consistent reads on replicas without paying the price of traditional synchronous replication, but two bugs found along the way require attention before going to production.





