[PATCH] Don't report unchanged auto-tuned settings as needing a restart

From: 이지호 <jiho99322(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: [PATCH] Don't report unchanged auto-tuned settings as needing a restart
Date: 2026-11-25 05:54:29
Message-ID: CAFK+_hc=W86cqxmGrgcAeJxnf3uG9r-bsna5dAdW29kL4DjMRg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

If transaction_buffers, subtransaction_buffers, commit_timestamp_buffers
or io_max_concurrency is set to its auto-tuning value in
postgresql.conf, a reload reports the setting as changed even though
nothing in the file was touched:

LOG: received SIGHUP, reloading configuration files
LOG: parameter "transaction_buffers" cannot be changed without
restarting the server
LOG: parameter "subtransaction_buffers" cannot be changed without
restarting the server
LOG: parameter "commit_timestamp_buffers" cannot be changed
without restarting the server
LOG: parameter "io_max_concurrency" cannot be changed without
restarting the server
LOG: configuration file "..." contains errors; unaffected changes
were applied

After that, pg_settings.pending_restart is true for these four, and
pg_file_settings shows them with applied = false and "setting could
not be applied". Restarting does not clear it: the next reload shows
the same thing again. Since querying pg_file_settings also re-reads
the file, just running SELECT * FROM pg_file_settings is enough to
set pending_restart in that session.

This happens on 17 (the three SLRU buffer settings) and 18 and later
(plus io_max_concurrency). We ran into it in a managed PostgreSQL
service that writes every parameter into postgresql.conf explicitly
and checks pending_restart and pg_file_settings after a reload; it
kept flagging these settings as needing a restart, and restarting
didn't help.

To reproduce, on a fresh cluster:

cat >> $PGDATA/postgresql.conf <<EOF
transaction_buffers = 0
subtransaction_buffers = 0
commit_timestamp_buffers = 0
io_max_concurrency = -1
wal_buffers = -1
EOF
pg_ctl restart
psql -c "SELECT pg_reload_conf()"
psql -c "SELECT name, setting, pending_restart FROM pg_settings
WHERE name IN ('transaction_buffers', 'subtransaction_buffers',
'commit_timestamp_buffers', 'io_max_concurrency',
'wal_buffers')"

The four parameters show pending_restart = t; wal_buffers shows f.

The cause is that at startup the auto-tuned value is written into the
GUC variable itself (with PGC_S_OVERRIDE when the file sets the
parameter). On reload, set_config_option() compares the value from
the file, after the check hook, with the variable, i.e. 0 or -1
against the auto-tuned number, and concludes the setting changed.
wal_buffers avoids this because check_wal_buffers() substitutes the
auto-tuned value once XLOGbuffers is no longer -1.

The attached patch does the same in check_transaction_buffers(),
check_subtrans_buffers(), check_commit_ts_buffers() and
check_io_max_concurrency(), which needs AioChooseMaxConcurrency() to
be exported. ALTER SYSTEM still writes the original string, since it
doesn't use the check hook's result. An actual change between the
auto-tuned value and an explicit value is still reported as pending a
restart.

It also adds a test to test_misc/003_check_guc.pl that sets the five
parameters to auto, restarts, and checks pg_file_settings.applied and
pg_settings.pending_restart. Without the code changes, the test
reports exactly the four parameters above.

The C changes apply as-is to REL_19_STABLE and REL_18_STABLE (only the
test hunk needs adjusting on 18). For 17, only the three SLRU check
hooks apply; I can send back-branch versions if that helps.

Related: Andres described the same comparison producing a bogus
message for postmaster parameters given with -c [1]. Also, there is a
recent patch that changes how CLOGShmemBuffers() auto-tunes
transaction_buffers [2]; if that goes in, check_transaction_buffers()
needs to follow it, as it calls the same function.

There is also a patch in the commitfest, "PGC_S_ARGV vs pg_file_settings
and pg_settings" [3], that makes set_config_option() skip the
pending_restart check when the current value comes from a source with
higher priority than the file. That would hide this symptom as well,
because an auto-tuned value whose parameter is set in the file has
source PGC_S_OVERRIDE. But it also hides real changes: with that
patch applied to master, changing transaction_buffers from 0 to 64,
io_max_concurrency from -1 to 8 and wal_buffers from -1 to 1024 in
postgresql.conf and reloading leaves pending_restart = f for all three,
although a restart would change their values. With the attached
patch, those three are reported as pending restart, and the unchanged
auto-tuned settings are not. So I think the auto-tuned case should be
handled in the check hooks either way.

[1] https://postgr.es/m/20190727013756.eeed74fqcmf7gz2h@alap3.anarazel.de
[2] https://postgr.es/m/dff1f13f-0c69-4adb-8b9b-3f3363f2b0d6@postgrespro.ru
[3] https://postgr.es/m/20261029115142.79da9dc3@karst

Regards,
Jiho Lee

Attachment Content-Type Size
v1-0001-Don-t-report-unchanged-auto-tuned-settings-as-nee.patch application/octet-stream 7.7 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Nisha Moond 2026-11-25 05:43:38 Re: Proposal: Conflict log history table for Logical Replication