// postgresql · memory

maintenance_work_mem

Memory for VACUUM, CREATE INDEX, ALTER TABLE ADD FOREIGN KEY and similar maintenance.

기본값
64MB
Range
64kB to 2TB
Restart needed
아니요
Default checked on
PostgreSQL 18

기능

Only one maintenance operation runs per session, so this can be much larger than work_mem. A larger value makes index builds sort in memory and lets VACUUM remember more dead row IDs per pass over the indexes.

기본값

64MB. 64MB (PostgreSQL 18), unchanged since 9.4. From PostgreSQL 17 VACUUM can use more than 1GB of it; earlier versions capped dead-tuple storage at 1GB.

Check the current value

SHOW maintenance_work_mem;

SELECT setting, unit, boot_val, context, source, pending_restart
FROM pg_settings
WHERE name = 'maintenance_work_mem';

Change it

SET maintenance_work_mem = '1GB';   -- this session
ALTER ROLE reporting SET maintenance_work_mem = '1GB';   -- new sessions of one role

ALTER SYSTEM SET maintenance_work_mem = '1GB';
SELECT pg_reload_conf();

No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).

When to change it

Raise it to 1GB or more on servers with RAM to spare, or SET it in the session that builds a big index.

What can go wrong

Autovacuum workers also use it unless autovacuum_work_mem is set, so autovacuum_max_workers x this value can be allocated at once.

Questions about maintenance_work_mem

What is the default value of maintenance_work_mem in PostgreSQL?

64MB. 64MB (PostgreSQL 18), unchanged since 9.4. From PostgreSQL 17 VACUUM can use more than 1GB of it; earlier versions capped dead-tuple storage at 1GB.

Does changing maintenance_work_mem require a restart?

No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).

When should I change maintenance_work_mem?

Raise it to 1GB or more on servers with RAM to spare, or SET it in the session that builds a big index.

Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.

// one client for every engine

Check maintenance_work_mem on your own server

SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.