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 1s80hW-008w1B-PX for pgsql-hackers@arkaria.postgresql.org; Fri, 17 May 2024 16:45:00 +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 1s80hW-00FW4A-Qc for pgsql-hackers@arkaria.postgresql.org; Fri, 17 May 2024 16:44:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s80hW-00FW42-HB for pgsql-hackers@lists.postgresql.org; Fri, 17 May 2024 16:44:58 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s80hT-000gpU-QT for pgsql-hackers@postgresql.org; Fri, 17 May 2024 16:44:57 +0000 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-36c8f521122so3486825ab.0 for ; Fri, 17 May 2024 09:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715964295; x=1716569095; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=KmwZLFVID+ErXk4lKjk3rP7AcDUHzRnpZrPSG78uECU=; b=IPHw9UvWLmeoGk6h83/uBoj00kzFC1ORCdAt1z5huAAg3LtwLpQTB+KLnFSRNnf4f4 ypizwcYcpa7XNI5WBZTGkjuryXSSR7je60MgBmDX5lshmU9DUjvsRFJZKh9d02ree5Hj F6+3k/NOH7RDp//5Q5iSWOD6DGMgZ+DFLnKvbYV7tHu0Vn4pHVh0rts/DjjlvotWMvV4 XB9Xry5pjs9UT4fouq744VQVQbrmfqo6NEEAF/j5e1g7FlVQgMEz5IibI3KSbb9GpXQM xLQYsdiXR2FdxnLKzxfs3/FnwoNxmLRRGfkz81MDZiRLrhpCQDe8KTd872OfP1fBS9CF 2MRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715964295; x=1716569095; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KmwZLFVID+ErXk4lKjk3rP7AcDUHzRnpZrPSG78uECU=; b=bt0+BQ+PLzLQ77sOMYTIWyfox7bKDY2VgO8bsOVE0pCz+ma0K+gAy7GqvNPrVdCmSe Ah8gWlbScbggEiLFHnQqp3cB2euVrO5V6mTTFjRJQBSz3USL8eusghI5Bo+KHoglSRxU 5EKDitUyOQ6b17B5Va2Y3bEG3DdtPwhXPp1tqRpFRnqi8Q/cOL35BLxycsTEmYL29Wtx llGlqWX3DDjWcC5wOAV+Dvwvauy2rsgpokfOd6oiaotpQm8b5l9IS6UDrT9+xLonvuUM JiFMmaV6Go1SV6lqgv7r36/7A6MZArNSvadVy9/AhEz8MNqVpq3+UyVUZ1avRDCT2gHC AlUA== X-Forwarded-Encrypted: i=1; AJvYcCWAqJeYdKa1GQdeQ0BttTzskU97LoEp64WXAGtOwmF/sjg2CGS5NVDS4vDN4sUvGqve8PpvJz2nXwKTbydnABWBp4vyudW+AqLsZGzc X-Gm-Message-State: AOJu0Yz2IxwGVa6nq/Q4XsUCV+LAWDof+KBa/4Fn9GSh4O3dXAkKUs4C QyS3PD5hSeG3dgzThsYeY7GbDBdW8vvgp2zeutqJ9bDVRIrbRPhr X-Google-Smtp-Source: AGHT+IGCVC5UtfWRSIm6J4kxawvkIgcHLoG8e4Yk5U5daiQPf1YP0b3np1PV4MynM1QXhpFn7lDB1g== X-Received: by 2002:a05:6e02:1aad:b0:36c:7eb2:50d5 with SMTP id e9e14a558f8ab-36cc149a3a6mr272595365ab.25.1715964294966; Fri, 17 May 2024 09:44:54 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-36cb9d69d02sm43301535ab.20.2024.05.17.09.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 09:44:54 -0700 (PDT) Date: Fri, 17 May 2024 11:44:52 -0500 From: Nathan Bossart To: "Imseih (AWS), Sami" Cc: Justin Pryzby , "pgsql-hackers@postgresql.org" Subject: problems with "Shared Memory and Semaphores" section of docs Message-ID: <20240517164452.GA1914161@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk (moving to a new thread) On Thu, May 16, 2024 at 09:16:46PM -0500, Nathan Bossart wrote: > On Thu, May 16, 2024 at 04:37:10PM +0000, Imseih (AWS), Sami wrote: >> Also, Not sure if I am mistaken here, but the "+ 5" in the existing docs >> seems wrong. >> >> If it refers to NUM_AUXILIARY_PROCS defined in >> include/storage/proc.h, it should a "6" >> >> #define NUM_AUXILIARY_PROCS 6 >> >> This is not a consequence of this patch, and can be dealt with >> In a separate thread if my understanding is correct. > > Ha, I think it should actually be "+ 7"! The value is calculated as > > MaxConnections + autovacuum_max_workers + 1 + max_worker_processes + max_wal_senders + 6 > > Looking at the history, this documentation tends to be wrong quite often. > In v9.2, the checkpointer was introduced, and these formulas were not > updated. In v9.3, background worker processes were introduced, and the > formulas were still not updated. Finally, in v9.6, it was fixed in commit > 597f7e3. Then, in v14, the archiver process was made an auxiliary process > (commit d75288f), making the formulas out-of-date again. And in v17, the > WAL summarizer was added. > > On top of this, IIUC you actually need even more semaphores if your system > doesn't support atomics, and from a quick skim this doesn't seem to be > covered in this documentation. A couple of other problems I noticed: * max_wal_senders is missing from this sentence: When using System V semaphores, PostgreSQL uses one semaphore per allowed connection (), allowed autovacuum worker process () and allowed background process (), in sets of 16. * AFAICT the discussion about the formulas in the paragraphs following the table doesn't explain the reason for the constant. * IMHO the following sentence is difficult to decipher, and I can't tell if it actually matches the formula in the table: The maximum number of semaphores in the system is set by SEMMNS, which consequently must be at least as high as max_connections plus autovacuum_max_workers plus max_wal_senders, plus max_worker_processes, plus one extra for each 16 allowed connections plus workers (see the formula in ). At a bare minimum, we should probably fix the obvious problems, but I wonder if we could simplify this section a bit, too. If the exact values are important, maybe we could introduce more GUCs like shared_memory_size_in_huge_pages that can be consulted (instead of requiring users to break out their calculators). -- Nathan Bossart Amazon Web Services: https://aws.amazon.com