From bae2b1a860cf67237f7147bb20d25861fc252e12 Mon Sep 17 00:00:00 2001 From: Jiho Lee Date: Wed, 25 Nov 2026 14:43:09 +0900 Subject: [PATCH v1] Don't report unchanged auto-tuned settings as needing a restart transaction_buffers, subtransaction_buffers, commit_timestamp_buffers and io_max_concurrency are PGC_POSTMASTER parameters whose default value (0, or -1 for io_max_concurrency) requests auto-tuning. At startup the auto-tuned value is stored in the GUC variable itself, with PGC_S_OVERRIDE if the setting came from the configuration file. When the configuration file is re-read, whether on SIGHUP or by querying pg_file_settings, set_config_option() compares the value from the file, after the check hook, with the current value of the variable. For these parameters, that compares 0 (or -1) with the auto-tuned value. So, if the default is written explicitly in postgresql.conf, every reload logs "parameter ... cannot be changed without restarting the server" and sets pending_restart in pg_settings, and pg_file_settings shows the entries as not applied, even though a restart would not change anything. wal_buffers doesn't have this problem, because check_wal_buffers() substitutes the auto-tuned value once it is known. Do the same in the check hooks of the other four parameters. This requires exporting AioChooseMaxConcurrency(). Add a test to test_misc/003_check_guc.pl. --- src/backend/access/transam/clog.c | 9 +++++ src/backend/access/transam/commit_ts.c | 9 +++++ src/backend/access/transam/subtrans.c | 9 +++++ src/backend/storage/aio/aio.c | 7 +++- src/backend/storage/aio/aio_init.c | 2 +- src/include/storage/aio_internal.h | 3 ++ src/test/modules/test_misc/t/003_check_guc.pl | 36 +++++++++++++++++++ 7 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c index ab84c34554..098734c3b4 100644 --- a/src/backend/access/transam/clog.c +++ b/src/backend/access/transam/clog.c @@ -832,6 +832,15 @@ CLOGShmemInit(void *arg) bool check_transaction_buffers(int *newval, void **extra, GucSource source) { + /* + * 0 requests auto-tuning. If that has already been done at startup, + * substitute the auto-tuned value, as in CLOGShmemBuffers(), so that an + * unchanged setting re-read from the configuration file is not reported + * as requiring a restart. + */ + if (*newval == 0 && transaction_buffers != 0) + *newval = SimpleLruAutotuneBuffers(512, 1024); + return check_slru_buffers("transaction_buffers", newval); } diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c index 9e6fd5d465..3cc96016ea 100644 --- a/src/backend/access/transam/commit_ts.c +++ b/src/backend/access/transam/commit_ts.c @@ -586,6 +586,15 @@ CommitTsShmemInit(void *arg) bool check_commit_ts_buffers(int *newval, void **extra, GucSource source) { + /* + * 0 requests auto-tuning. If that has already been done at startup, + * substitute the auto-tuned value, as in CommitTsShmemBuffers(), so that + * an unchanged setting re-read from the configuration file is not + * reported as requiring a restart. + */ + if (*newval == 0 && commit_timestamp_buffers != 0) + *newval = SimpleLruAutotuneBuffers(512, 1024); + return check_slru_buffers("commit_timestamp_buffers", newval); } diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c index b79e648b89..44213ab133 100644 --- a/src/backend/access/transam/subtrans.c +++ b/src/backend/access/transam/subtrans.c @@ -271,6 +271,15 @@ SUBTRANSShmemInit(void *arg) bool check_subtrans_buffers(int *newval, void **extra, GucSource source) { + /* + * 0 requests auto-tuning. If that has already been done at startup, + * substitute the auto-tuned value, as in SUBTRANSShmemBuffers(), so that + * an unchanged setting re-read from the configuration file is not + * reported as requiring a restart. + */ + if (*newval == 0 && subtransaction_buffers != 0) + *newval = SimpleLruAutotuneBuffers(512, 1024); + return check_slru_buffers("subtransaction_buffers", newval); } diff --git a/src/backend/storage/aio/aio.c b/src/backend/storage/aio/aio.c index 8f7e26607b..7b9bf2e996 100644 --- a/src/backend/storage/aio/aio.c +++ b/src/backend/storage/aio/aio.c @@ -1344,8 +1344,13 @@ check_io_max_concurrency(int *newval, void **extra, GucSource source) { /* * Auto-tuning will be applied later during startup, as auto-tuning - * depends on the value of various GUCs. + * depends on the value of various GUCs. If that has already + * happened, substitute the auto-tuned value, so that an unchanged + * setting re-read from the configuration file is not reported as + * requiring a restart. */ + if (io_max_concurrency != -1) + *newval = AioChooseMaxConcurrency(); return true; } else if (*newval == 0) diff --git a/src/backend/storage/aio/aio_init.c b/src/backend/storage/aio/aio_init.c index de50e6a8a3..2221aa3943 100644 --- a/src/backend/storage/aio/aio_init.c +++ b/src/backend/storage/aio/aio_init.c @@ -101,7 +101,7 @@ AioHandleDataShmemSize(void) * On the upper end, apply a cap too - just because shared_buffers is large, * it doesn't make sense have millions of buffers undergo IO concurrently. */ -static int +int AioChooseMaxConcurrency(void) { uint32 max_backends; diff --git a/src/include/storage/aio_internal.h b/src/include/storage/aio_internal.h index 9ca4087aa7..6f193991b8 100644 --- a/src/include/storage/aio_internal.h +++ b/src/include/storage/aio_internal.h @@ -346,6 +346,9 @@ extern const char *pgaio_io_get_state_name(PgAioHandle *ioh); const char *pgaio_result_status_string(PgAioResultStatus rs); extern void pgaio_shutdown(int code, Datum arg); +/* aio_init.c */ +extern int AioChooseMaxConcurrency(void); + /* aio_callback.c */ extern void pgaio_io_call_stage(PgAioHandle *ioh); extern void pgaio_io_call_complete_shared(PgAioHandle *ioh); diff --git a/src/test/modules/test_misc/t/003_check_guc.pl b/src/test/modules/test_misc/t/003_check_guc.pl index 8b9ef19198..3c88cc55fb 100644 --- a/src/test/modules/test_misc/t/003_check_guc.pl +++ b/src/test/modules/test_misc/t/003_check_guc.pl @@ -132,4 +132,40 @@ foreach my $param (@lines_with_tabs) print("found tab in line $param in postgresql.conf.sample\n"); } +# Auto-tuned PGC_POSTMASTER parameters explicitly set to their auto-tuning +# value in the configuration file must not be reported as changed when the +# file is re-read without changes. Querying pg_file_settings re-reads the +# file in the current session, so check both views in the same session. +my $autotuned_params = + "'commit_timestamp_buffers', 'io_max_concurrency', " + . "'subtransaction_buffers', 'transaction_buffers', 'wal_buffers'"; +$node->append_conf( + 'postgresql.conf', qq( +commit_timestamp_buffers = 0 +io_max_concurrency = -1 +subtransaction_buffers = 0 +transaction_buffers = 0 +wal_buffers = -1 +)); +$node->restart; + +my $not_applied = $node->safe_psql( + 'postgres', + "SELECT coalesce(string_agg(name, ', ' ORDER BY name), 'none') + FROM pg_file_settings + WHERE name IN ($autotuned_params) AND NOT applied"); +my $pending_restart = $node->safe_psql( + 'postgres', + "SELECT count(*) FROM pg_file_settings; + SELECT coalesce(string_agg(name, ', ' ORDER BY name), 'none') + FROM pg_settings + WHERE name IN ($autotuned_params) AND pending_restart"); +# Only keep the output of the last query. +$pending_restart = (split("\n", $pending_restart))[-1]; + +is($not_applied, 'none', + 'auto-tuned parameters set to auto-tune are applied in pg_file_settings'); +is($pending_restart, 'none', + 'auto-tuned parameters set to auto-tune are not pending restart'); + done_testing(); -- 2.50.1 (Apple Git-155)