// postgresql · vacuum, statistics & maintenance

vacuum_cost_delay

How long VACUUM sleeps each time it exhausts its I/O cost budget; 0 runs unthrottled.

Padrão
0 (unthrottled)
Range
0 to 100ms
Restart needed
Não
Default checked on
PostgreSQL 18

O que faz

Cost-based vacuum spreads a manual VACUUM's writes over time instead of taking all the bandwidth it can, one budget of vacuum_cost_limit (200) per process. Autovacuum keeps its own delay, autovacuum_vacuum_cost_delay (2ms), unless that is set to -1 to inherit this value.

Valor padrão

0 (unthrottled). 0 (PostgreSQL 18); the default has been 0 since PostgreSQL 12 (it was 20ms).

Check the current value

SHOW vacuum_cost_delay;

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

Change it

SET vacuum_cost_delay = '2ms';   -- this session
ALTER ROLE reporting SET vacuum_cost_delay = '2ms';   -- new sessions of one role

ALTER SYSTEM SET vacuum_cost_delay = '2ms';
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

SET it in the session running a deliberate VACUUM on a busy server during business hours; 1-2ms is usually enough to keep VACUUM from dominating the disk.

What can go wrong

A few milliseconds of delay per cost budget caps VACUUM far below what the disk can do, so a vacuum that would finish in minutes can take hours. Operations holding critical locks skip the delay, so the throttle never becomes a hard bound on vacuum progress.

Questions about vacuum_cost_delay

What is the default value of vacuum_cost_delay in PostgreSQL?

0 (unthrottled). 0 (PostgreSQL 18); the default has been 0 since PostgreSQL 12 (it was 20ms).

Does changing vacuum_cost_delay 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 vacuum_cost_delay?

SET it in the session running a deliberate VACUUM on a busy server during business hours; 1-2ms is usually enough to keep VACUUM from dominating the disk.

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

// one client for every engine

Check vacuum_cost_delay 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.

Texto e dados desta página: CC BY 4.0, com crédito ao SQLly (sqlly.app). Código e trechos SQL: MIT. Detalhes da licença