Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sK0cG-007qCA-EL for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 19:05:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sK0cE-005C0b-6F for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 19:05:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sK0cD-005Bz3-Qd for pgsql-hackers@lists.postgresql.org; Wed, 19 Jun 2024 19:05:06 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sK0cB-002WFP-VV for pgsql-hackers@postgresql.org; Wed, 19 Jun 2024 19:05:06 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7eb6aedcabcso1214939f.0 for ; Wed, 19 Jun 2024 12:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718823901; x=1719428701; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=VryxuQdor9pwuhhsr35cc59I4jpa/qnc6cMEbWU412M=; b=Q1smCBfgu+6NZHIX5a1HnALktcjsoksNDh0j3Hjxc+6aD/1CR4SQ+Wd7nSr4kX4F7j 9eDU7ig+Sas/dg8YVOvauK4vVsD7THXjCMYHLRp91U3Ltk+y9xNDNIzHPRLUkUtrgSs4 DJNolRIjDx/v8JaRk2TAOoLzP1bhIi0S22BRNOAGylZvLMCsTqNQl1JVusvIgrgvh0uS CmBT1JhGv+nWNiCP9JiaTdqrPEDtFUwRrqR4bhEgLABtahyrF0OwO7hoHqdKC6x5g/QD aKXyNkZrxg/yTBRi+XT2E4g2078YSA0wKJ4WctahSvewrWQ4qsCk/YZJVi3kSfdIPwga h3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718823901; x=1719428701; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VryxuQdor9pwuhhsr35cc59I4jpa/qnc6cMEbWU412M=; b=hQXbRHNMbSEMQ4xgUJjpq5OSfm7NeeWrpCyrDj57IjVEnKwmHz409EhtSMqbGngUKB hzOFJ9MU5uftKZh0juBZz3jroYhNWlaw72STEHDNKnzheDbb0jIuDJHswOASI3he5rfJ JBFyhqPxmy9W9NHBFnCqbUuCw6s6QPpyCPduHJgELkWcTxzDm6qymdSQvYVO6BDkPpKy oa2fFGUY6DeXpJsY1meVn+J4pzCQNZ+0oyOiDwWIFB/9sNzaDRr5dnYlUS06pLlLStAn VgoXafpBCOj7oIxXpZ92Spwy5ndsIYykDsXcFHCEe3x6v1sj3yQV1CWz9TS/7e8xC5+Y yjNQ== X-Gm-Message-State: AOJu0YzvIsNkaTk1qT4TeCQAZyu7GhZa8d9tLwG85tovjQGeru6b+IZz AuAcY7B1BHJ5SSgBNVRRshk6jQexkMbgU9oanzWMvdfkfxo6aE6EBP9W+LEe X-Google-Smtp-Source: AGHT+IGI3eKVTDIFleJU8vzz218Am42pst2wLYrH2JFD7po3XfoU/IkKezpiroIOTxiE8s0p1zeC2w== X-Received: by 2002:a05:6602:1602:b0:7eb:8ba3:2b81 with SMTP id ca18e2360f4ac-7f13edafa9dmr397021439f.3.1718823900710; Wed, 19 Jun 2024 12:05:00 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-7ebdba3d211sm340394039f.17.2024.06.19.12.05.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 12:05:00 -0700 (PDT) Date: Wed, 19 Jun 2024 14:04:58 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: remove check hooks for GUCs that contribute to MaxBackends Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="4rSPnp6/pm7uSOZW" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4rSPnp6/pm7uSOZW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline While working on an idea from another thread [0], I noticed that each of max_connections, max_worker_process, max_autovacuum_workers, and max_wal_senders have a check hook that verifies the sum of those GUCs does not exceed a certain value. Then, in InitializeMaxBackends(), we do the same check once more. Not only do the check hooks seem redundant, but I think they might sometimes be inaccurate since some values might not yet be initialized. Furthermore, the error message is not exactly the most descriptive: $ pg_ctl -D . start -o "-c max_connections=262100 -c max_wal_senders=10000" FATAL: invalid value for parameter "max_wal_senders": 10000 The attached patch removes these hooks and enhances the error message to look like this: FATAL: too many backends configured DETAIL: "max_connections" (262100) plus "autovacuum_max_workers" (3) plus "max_worker_processes" (8) plus "max_wal_senders" (10000) must be less than 262142. The downside of this change is that server startup progresses a little further before it fails, but that might not be too concerning given this _should_ be a relatively rare occurrence. Thoughts? [0] https://postgr.es/m/20240618213331.ef2spg3nasksisbi%40awork3.anarazel.de -- nathan --4rSPnp6/pm7uSOZW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-remove-check-hooks-for-GUCs-that-contribute-to-Ma.patch" From 2ab34581879d2122f03be0e3f9d0d15edb501a7c Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 19 Jun 2024 13:39:18 -0500 Subject: [PATCH v1 1/1] remove check hooks for GUCs that contribute to MaxBackends --- src/backend/utils/init/postinit.c | 57 ++++------------------------- src/backend/utils/misc/guc_tables.c | 8 ++-- src/include/utils/guc_hooks.h | 6 --- 3 files changed, 11 insertions(+), 60 deletions(-) diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 0805398e24..8a629982c4 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -580,57 +580,14 @@ InitializeMaxBackends(void) MaxBackends = MaxConnections + autovacuum_max_workers + 1 + max_worker_processes + max_wal_senders; - /* internal error because the values were all checked previously */ if (MaxBackends > MAX_BACKENDS) - elog(ERROR, "too many backends configured"); -} - -/* - * GUC check_hook for max_connections - */ -bool -check_max_connections(int *newval, void **extra, GucSource source) -{ - if (*newval + autovacuum_max_workers + 1 + - max_worker_processes + max_wal_senders > MAX_BACKENDS) - return false; - return true; -} - -/* - * GUC check_hook for autovacuum_max_workers - */ -bool -check_autovacuum_max_workers(int *newval, void **extra, GucSource source) -{ - if (MaxConnections + *newval + 1 + - max_worker_processes + max_wal_senders > MAX_BACKENDS) - return false; - return true; -} - -/* - * GUC check_hook for max_worker_processes - */ -bool -check_max_worker_processes(int *newval, void **extra, GucSource source) -{ - if (MaxConnections + autovacuum_max_workers + 1 + - *newval + max_wal_senders > MAX_BACKENDS) - return false; - return true; -} - -/* - * GUC check_hook for max_wal_senders - */ -bool -check_max_wal_senders(int *newval, void **extra, GucSource source) -{ - if (MaxConnections + autovacuum_max_workers + 1 + - max_worker_processes + *newval > MAX_BACKENDS) - return false; - return true; + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("too many backends configured"), + errdetail("\"max_connections\" (%d) plus \"autovacuum_max_workers\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.", + MaxConnections, autovacuum_max_workers, + max_worker_processes, max_wal_senders, + MAX_BACKENDS - 1))); } /* diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 46c258be28..07b575894d 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -2207,7 +2207,7 @@ struct config_int ConfigureNamesInt[] = }, &MaxConnections, 100, 1, MAX_BACKENDS, - check_max_connections, NULL, NULL + NULL, NULL, NULL }, { @@ -2923,7 +2923,7 @@ struct config_int ConfigureNamesInt[] = }, &max_wal_senders, 10, 0, MAX_BACKENDS, - check_max_wal_senders, NULL, NULL + NULL, NULL, NULL }, { @@ -3153,7 +3153,7 @@ struct config_int ConfigureNamesInt[] = }, &max_worker_processes, 8, 0, MAX_BACKENDS, - check_max_worker_processes, NULL, NULL + NULL, NULL, NULL }, { @@ -3387,7 +3387,7 @@ struct config_int ConfigureNamesInt[] = }, &autovacuum_max_workers, 3, 1, MAX_BACKENDS, - check_autovacuum_max_workers, NULL, NULL + NULL, NULL, NULL }, { diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h index d64dc5fcdb..6304f0679b 100644 --- a/src/include/utils/guc_hooks.h +++ b/src/include/utils/guc_hooks.h @@ -29,8 +29,6 @@ extern bool check_application_name(char **newval, void **extra, GucSource source); extern void assign_application_name(const char *newval, void *extra); extern const char *show_archive_command(void); -extern bool check_autovacuum_max_workers(int *newval, void **extra, - GucSource source); extern bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source); extern bool check_vacuum_buffer_usage_limit(int *newval, void **extra, @@ -84,13 +82,9 @@ extern const char *show_log_timezone(void); extern bool check_maintenance_io_concurrency(int *newval, void **extra, GucSource source); extern void assign_maintenance_io_concurrency(int newval, void *extra); -extern bool check_max_connections(int *newval, void **extra, GucSource source); -extern bool check_max_wal_senders(int *newval, void **extra, GucSource source); extern bool check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source); extern void assign_max_wal_size(int newval, void *extra); -extern bool check_max_worker_processes(int *newval, void **extra, - GucSource source); extern bool check_max_stack_depth(int *newval, void **extra, GucSource source); extern void assign_max_stack_depth(int newval, void *extra); extern bool check_multixact_member_buffers(int *newval, void **extra, -- 2.39.3 (Apple Git-146) --4rSPnp6/pm7uSOZW--