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 1vAa4U-003SVM-D7 for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Oct 2025 20:32:05 +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 1vAa4Q-00CI6w-TQ for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Oct 2025 20:32:01 +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 1vAa4Q-00CI6o-Kx for pgsql-bugs@lists.postgresql.org; Sun, 19 Oct 2025 20:32:01 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vAa4N-0036Ux-0L for pgsql-bugs@lists.postgresql.org; Sun, 19 Oct 2025 20:32:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 59JKVtnD051148; Sun, 19 Oct 2025 16:31:55 -0400 From: Tom Lane To: Casey & Gina cc: =?utf-8?Q?=C3=81lvaro_Herrera?= , pgsql-bugs@lists.postgresql.org Subject: Re: Issues with blocksize smaller than 8KB In-reply-to: <38A83DA6-15FF-4FF2-9EB0-C53E63611162@osss.net> References: <30951.1760899735@sss.pgh.pa.us> <38A83DA6-15FF-4FF2-9EB0-C53E63611162@osss.net> Comments: In-reply-to Casey & Gina message dated "Sun, 19 Oct 2025 15:42:23 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <51007.1760905838.0@sss.pgh.pa.us> Date: Sun, 19 Oct 2025 16:31:55 -0400 Message-ID: <51147.1760905915@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="UTF-8" Content-ID: <51007.1760905838.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Casey & Gina writes: > On Oct 19, 2025, at 2:48=E2=80=AFPM, Tom Lane wrote: >> Incautious use of --with-segsize could perhaps result in RELSEG_SIZE >> being too big for an int ... > This must have been it, though the same --with-segsize value worked for = larger blocksizes. > Perhaps configure could throw an error if too large of a value were to b= e used, but happy for the explanation... I was able to reproduce this error precisely by doing ./configure ... --with-blocksize=3D1 --with-segsize=3D10000 so I guess that's what you did (and you must have ignored the boatload of compiler warnings that ensued). configure does try to notice an overflow, but it seems to expect that expr(1) will complain about a larger-than-int result: AC_MSG_CHECKING([for segment size]) if test $segsize_blocks -eq 0; then # this expression is set up to avoid unnecessary integer overflow # blocksize is already guaranteed to be a factor of 1024 RELSEG_SIZE=3D`expr '(' 1024 / ${blocksize} ')' '*' ${segsize} '*' 1024` test $? -eq 0 || exit 1 AC_MSG_RESULT([${segsize}GB]) else RELSEG_SIZE=3D$segsize_blocks AC_MSG_RESULT([${RELSEG_SIZE} blocks]) fi At least on my Linux box, there's no complaint, you just get back the correct value of 10485760000. So that's not great, and it's even less great that --with-segsize-blocks isn't checked at all. The natural way to deal with this would be to add a test like if test $RELSEG_SIZE -le 0 -o $RELSEG_SIZE -gt 2147483647; then ... fail ... but this assumes a fact not in evidence, that test(1) will do wider-than-int arithmetic sanely. (Just because expr(1) does doesn't prove a lot about test(1), IMO.) I'm even less sure that I want to rely on meson to do it right. So I think we'd better leave it to the C compiler, as attached. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="assert-that-RELSEG_SIZE-is-sane.patch"; charset="us-ascii" Content-ID: <51007.1760905838.2@sss.pgh.pa.us> Content-Description: assert-that-RELSEG_SIZE-is-sane.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transa= m/xlog.c index eceab341255..2e1da5c714b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -39,6 +39,7 @@ #include "postgres.h" = #include +#include #include #include #include @@ -202,6 +203,15 @@ const struct config_enum_entry archive_mode_options[]= =3D { {NULL, 0, false} }; = +/* + * RELSEG_SIZE must fit into BlockNumber; but since we expose its value + * as an integer GUC, it actually needs to fit in signed int. It's worth + * having a cross-check for this since configure's --with-segsize options + * could let people select insane values. + */ +StaticAssertDecl(RELSEG_SIZE > 0 && RELSEG_SIZE <=3D INT_MAX, + "RELSEG_SIZE must fit in an integer"); + /* * Statistics for current checkpoint are collected in this global struct. * Because only the checkpointer or a stand-alone backend can perform ------- =_aaaaaaaaaa0--