maintenance_work_mem
Read PG 18 manual ↗Specifies the maximum amount of memory to be used by maintenance operations, such as VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY.
- Type
- integer
- Context
- user
- Measured default
- 64 MiB
- Unit
- kB
- Metadata snapshot
- 18
Definition PG 18 manual
Specifies the maximum amount of memory to be used by maintenance operations, such as VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY. If this value is specified without units, it is taken as kilobytes. It defaults to 64 megabytes (64MB). Since only one of these operations can be executed at a time by a database session, and an installation normally doesn't have many of them running concurrently, it's safe to set this value significantly larger than work_mem. Larger settings might improve performance for vacuuming and for restoring database dumps.
Note that when autovacuum runs, up to autovacuum_max_workers times this memory may be allocated, so be careful not to set the default value too high. It may be useful to control for this by separately setting autovacuum_work_mem.
Measured default history
| Version interval | Default |
|---|---|
| 9.0 – 9.3 | 16 MiB |
| 9.4 – 19 | 64 MiB |
Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗
How it works
maintenance_work_mem applies to maintenance operations including VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY. Because a session normally runs only one such operation at a time, it can usually be set higher than work_mem.
For parallel utility commands, PostgreSQL treats maintenance_work_mem as a limit for the entire utility command rather than granting the full amount to every parallel maintenance worker. CPU and I/O consumption can still rise with parallelism.
Autovacuum is a separate concurrency concern: when autovacuum_work_mem is -1, each autovacuum worker inherits maintenance_work_mem, so several workers can make the aggregate budget much larger than the single-operation value.
Operational considerations
Assuming the value is harmless because maintenance is infrequent while leaving autovacuum_work_mem at -1.
Multiplying the limit by parallel maintenance workers; PostgreSQL applies it to the utility command as a whole.
Using a permanently large cluster-wide value for a one-off restore instead of a scoped SET.
Expecting more memory alone to solve maintenance dominated by locks or storage I/O.
Workload guidance
OLAP: Larger values are often useful for index builds, vacuuming large relations, and restores. Schedule heavy maintenance and verify that concurrent maintenance, query memory, and the OS still fit together.
OLTP: Use enough memory to keep routine vacuum and index work efficient, but budget explicitly for simultaneous autovacuum workers. If interactive latency matters and maintenance_work_mem is large, give autovacuum_work_mem its own lower ceiling.
SMALL: Keep the global value modest and temporarily raise it only for controlled maintenance sessions. Check autovacuum inheritance before increasing it.
Version history 4
- PG 16 → 17changed
- PG 11 → 12changed
- PG 9.5 → 9.6changed
- PG 9.3 → 9.4changed
Related entries
Further reading
Definition snapshot: english-manuals:68a841cd948c9a3dd03bb8af36b… · English manual source