]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Emit a warning when io_min_workers exceeds io_max_workers
authorMichael Paquier <michael@paquier.xyz>
Mon, 6 Jul 2026 02:37:36 +0000 (11:37 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 6 Jul 2026 02:37:36 +0000 (11:37 +0900)
When io_min_workers is set strictly higher than io_max_workers, the
minimum has no effect since the pool will never grow past
io_max_workers.  Previously this was silently accepted, which could
be confusing for users expecting at least io_min_workers workers to
always be running.

In order to avoid noise in the server logs, the following restrictions
are in place:
- The only process printing the WARNING is the IO worker with ID 0, on
startup and reload, which is we know the only process always running
when using IO workers.
- At reload, the message shows only if one of the bounds has changed.

Note that this commit reuses a log message updated by 7905416eef9b.

Author: Baji Shaik <baji.pgdev@gmail.com>
Reviewed-by: Tristan Partin <tristan@partin.io>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/CA+fm-RO_O7-XThg2qjj=ir35x9nOFbZYu07gttqAbM5T88QB4Q@mail.gmail.com

src/backend/storage/aio/method_worker.c

index 63e34d66690d45b74f646614dc90166c3c1ada30..cf75b2816b72d52ada2e967f15767464d7f8e344 100644 (file)
@@ -662,6 +662,27 @@ pgaio_worker_can_timeout(void)
        return true;
 }
 
+/*
+ * Emit a WARNING if io_min_workers > io_max_workers, since the worker
+ * pool will never exceed io_max_workers regardless of the minimum setting.
+ */
+static void
+check_io_worker_gucs(void)
+{
+       /* Only do the check in one worker, to limit noise */
+       if (MyIoWorkerId != 0)
+               return;
+
+       if (io_min_workers > io_max_workers)
+               ereport(WARNING,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("\"%s\" (%d) should be less than or equal to \"%s\" (%d)",
+                                               "io_min_workers", io_min_workers,
+                                               "io_max_workers", io_max_workers),
+                                errdetail("The I/O worker pool will not exceed \"%s\" (%d) workers.",
+                                                  "io_max_workers", io_max_workers)));
+}
+
 void
 IoWorkerMain(const void *startup_data, size_t startup_data_len)
 {
@@ -694,6 +715,8 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
        /* also registers a shutdown callback to unregister */
        pgaio_worker_register();
 
+       check_io_worker_gucs();
+
        sprintf(cmd, "%d", MyIoWorkerId);
        set_ps_display(cmd);
 
@@ -1011,9 +1034,20 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
 
                if (ConfigReloadPending)
                {
+                       int                     io_max_workers_prev = io_max_workers;
+                       int                     io_min_workers_prev = io_min_workers;
+
                        ConfigReloadPending = false;
                        ProcessConfigFile(PGC_SIGHUP);
 
+                       /*
+                        * Emit a WARNING if io_min_workers > io_max_workers.  If no bound
+                        * has changed, skip this to avoid too many log messages.
+                        */
+                       if (io_min_workers_prev != io_min_workers ||
+                               io_max_workers_prev != io_max_workers)
+                               check_io_worker_gucs();
+
                        /* If io_max_workers has been decreased, exit highest first. */
                        if (MyIoWorkerId >= io_max_workers)
                                break;