Repository navigation
12.29.0
Schema version: 39 (a migration runs on upgrade — see Upgrading).
Maintenance now finds and rebuilds bloated job indexes.
Highlights
Bloated job indexes are rebuilt during maintenance
Autovacuum reclaims heap space but never shrinks a btree, so a job index stays at the size of the largest backlog its queue has ever held. Every later vacuum then walks all of those pages, which becomes the dominant cost on a queue that has drained. For example, on a real installation job_common_i5 sat at 130 MB for live data worth ~136 kB, churning disk pages and draining the instance's IO burst balance (#876, thanks @danilofuchs for the report and the measurements).
Maintenance now runs a density check and rebuilds what it finds with REINDEX INDEX CONCURRENTLY, which holds no lock against readers or writers (#883).
const boss = new PgBoss({ connectionString }) // reindex: true
// or turn rebuilds off and drive them yourself
const boss = new PgBoss({ connectionString, reindex: false })
// or move the thresholds
const boss = new PgBoss({
connectionString,
reindex: { maxIndexBytes: 512 * 1024 * 1024 },
reindexIntervalSeconds: 3600
})| Threshold | Default | Meaning |
|---|---|---|
minPages |
128 | Ignore indexes smaller than this many 8 kB pages |
maxEntriesPerPage |
5 | Live entries per page below which an index counts as bloated. A freshly built job index holds 140-170 |
minSizeRatio |
4 | How many times larger than its live entries need an index must be. The needed size is estimated from pg_stats, so a wide singletonKey — which legitimately packs fewer than five entries per page — is not mistaken for bloat |
maxIndexBytes |
2 GB | Never rebuild an index larger than this; a rebuild that expensive is left to an operator |
The check runs on reindexIntervalSeconds (default 1 day). Bloat that is detected but not rebuilt raises an index_bloat warning naming the reason.
Two new entry points hand over the statements to run by hand:
// needs an instance; skips the ownership and size filters, since an operator may run these as another role
const commands = await boss.getReindexCommands()
// [
// 'REINDEX INDEX CONCURRENTLY pgboss."job_common_i5"',
// 'REINDEX INDEX CONCURRENTLY pgboss."job_common_pkey"'
// ]
// needs no instance and no connection — paste into psql or hand to a monitoring tool
import { getIndexBloatPlans } from 'pg-boss'
const sql = getIndexBloatPlans('pgboss')CLI
pg-boss reindex # rebuild the bloated job indexes
pg-boss reindex --dry-run # print the SQL instead
pg-boss reindex --force # every job index, not only the bloated onesAn index the connected role does not own is reported up front rather than attempted, and sets a non-zero exit code. pg-boss doctor gained an INDEX BLOAT section — informational, like extra indexes, so it never changes the exit code.
supervise() takes options
// skip the bloat check and the shared interval, rebuild every job index now
await boss.supervise(undefined, { reindex: { force: true } })
// run maintenance without touching indexes
await boss.supervise(undefined, { reindex: false })force is accepted only here, not in the constructor — a timer that rebuilt every job index on every interval is never what you want.
Upgrading
Schema 39 adds one nullable column to the version table. ADD COLUMN with no default is a catalog-only change in PostgreSQL — no table rewrite, no lock on the job tables, no BAM command. Rolling back to 38 drops the column.
No new indexes, and nothing about fetch, insert or maintenance timing changes. The one behavioral difference on upgrade is that index rebuilding is on by default: a bloated installation will rebuild during its next maintenance pass after the upgrade. Set reindex: false in the constructor to keep detection and warnings without rebuilds.
Full Changelog: 12.28.1...12.29.0