From 13f44d2fee591e6375c18b574d97336e64028218 Mon Sep 17 00:00:00 2001 From: Shihao Date: Sat, 19 Sep 2026 19:09:34 -0400 Subject: [PATCH v1 2/2] Lower the maximum of autovacuum_naptime to one hour The old maximum was INT_MAX / 1000 seconds, about 24 days. A value that large only delays autovacuum, wraparound vacuums included, and a wrong setting has been reported to end in an XID wraparound outage. The only thing a larger naptime changes is how often a worker starts in each database. Starting a worker costs about 13ms of CPU. So at a naptime of one hour, all the worker starts in a cluster with 1000 databases cost about 0.4% of one core, and with 10000 databases about 4%. That is everything a larger value could save, so nothing real is lost above one hour. contrib/test_decoding set the naptime to 1d to keep autovacuum quiet during its tests. Use autovacuum = off there instead, which also holds on animals where the run takes longer than the naptime. With autovacuum off, index_update_stats() no longer updates the relstats of the table, so the MERGE in the ddl test gets a different plan and decodes its rows in a different order. Update the expected output for that. The new order is stable. A configuration file with a larger value now stops the server from starting, so this is for master only. Discussion: https://postgr.es/m/CAGjGUAJSuWzskc=6Kkh+3BPU6AfRm62MWdTAc=7-jPKxxanUpA@mail.gmail.com --- contrib/test_decoding/expected/ddl.out | 10 +++++----- contrib/test_decoding/logical.conf | 2 +- doc/src/sgml/config.sgml | 3 ++- src/backend/utils/misc/guc_parameters.dat | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/contrib/test_decoding/expected/ddl.out b/contrib/test_decoding/expected/ddl.out index 746c53a3231..d8286f78133 100644 --- a/contrib/test_decoding/expected/ddl.out +++ b/contrib/test_decoding/expected/ddl.out @@ -209,11 +209,6 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc data -------------------------------------------------------------------------------------------------------------------------------------------------- BEGIN - table public.replication_example: INSERT: id[integer]:-20 somedata[integer]:-20 somenum[integer]:-20 zaphod1[integer]:null zaphod2[integer]:null - table public.replication_example: INSERT: id[integer]:-19 somedata[integer]:-19 somenum[integer]:-19 zaphod1[integer]:null zaphod2[integer]:null - table public.replication_example: INSERT: id[integer]:-18 somedata[integer]:-18 somenum[integer]:-18 zaphod1[integer]:null zaphod2[integer]:null - table public.replication_example: INSERT: id[integer]:-17 somedata[integer]:-17 somenum[integer]:-17 zaphod1[integer]:null zaphod2[integer]:null - table public.replication_example: INSERT: id[integer]:-16 somedata[integer]:-16 somenum[integer]:-16 zaphod1[integer]:null zaphod2[integer]:null table public.replication_example: UPDATE: id[integer]:-15 somedata[integer]:-15 somenum[integer]:-14 zaphod1[integer]:null zaphod2[integer]:null table public.replication_example: UPDATE: id[integer]:-14 somedata[integer]:-14 somenum[integer]:-13 zaphod1[integer]:null zaphod2[integer]:null table public.replication_example: UPDATE: id[integer]:-13 somedata[integer]:-13 somenum[integer]:-12 zaphod1[integer]:null zaphod2[integer]:null @@ -235,6 +230,11 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'inc table public.replication_example: DELETE: id[integer]:3 table public.replication_example: DELETE: id[integer]:4 table public.replication_example: DELETE: id[integer]:5 + table public.replication_example: INSERT: id[integer]:-16 somedata[integer]:-16 somenum[integer]:-16 zaphod1[integer]:null zaphod2[integer]:null + table public.replication_example: INSERT: id[integer]:-17 somedata[integer]:-17 somenum[integer]:-17 zaphod1[integer]:null zaphod2[integer]:null + table public.replication_example: INSERT: id[integer]:-20 somedata[integer]:-20 somenum[integer]:-20 zaphod1[integer]:null zaphod2[integer]:null + table public.replication_example: INSERT: id[integer]:-19 somedata[integer]:-19 somenum[integer]:-19 zaphod1[integer]:null zaphod2[integer]:null + table public.replication_example: INSERT: id[integer]:-18 somedata[integer]:-18 somenum[integer]:-18 zaphod1[integer]:null zaphod2[integer]:null COMMIT (28 rows) diff --git a/contrib/test_decoding/logical.conf b/contrib/test_decoding/logical.conf index cc12f2542b4..4aace27b9e7 100644 --- a/contrib/test_decoding/logical.conf +++ b/contrib/test_decoding/logical.conf @@ -1,4 +1,4 @@ wal_level = logical max_replication_slots = 4 logical_decoding_work_mem = 64kB -autovacuum_naptime = 1d +autovacuum = off diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 4b86a1edfe6..889ddfa7098 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -9490,7 +9490,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; database and issues VACUUM and ANALYZE commands as needed for tables in that database. If this value is specified without units, it is taken as seconds. - The default is one minute (1min). + The default is one minute (1min), and the + maximum is one hour (1h). This parameter can only be set in the postgresql.conf file or on the server command line. diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils/misc/guc_parameters.dat index c57441f7d98..2c71afd892d 100644 --- a/src/backend/utils/misc/guc_parameters.dat +++ b/src/backend/utils/misc/guc_parameters.dat @@ -208,7 +208,7 @@ variable => 'autovacuum_naptime', boot_val => '60', min => '1', - max => 'INT_MAX / 1000', + max => '3600', }, { name => 'autovacuum_vacuum_cost_delay', type => 'real', context => 'PGC_SIGHUP', group => 'VACUUM_AUTOVACUUM', -- 2.37.1 (Apple Git-137.1)