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.96) (envelope-from ) id 1w0jmG-002ALp-2r for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 17:24:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0jmF-00G5xr-0u for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 17:24:51 +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.96) (envelope-from ) id 1w0jmE-00G5xj-2t for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 17:24:51 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0jmD-00000001njZ-1gVX for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 17:24:50 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-66f747175d8so721556eaf.0 for ; Thu, 12 Mar 2026 10:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773336289; cv=none; d=google.com; s=arc-20240605; b=Kj0bJDf71TCPkSUwJU6hGA59nzVtyKr6WC9P3WJ42KjXIp1sGcHQ3rs6MJrL2+tpv7 WxPwfTPmVfyI6E3oybFwx3x7fJpQ0Tawwd+y/2s+XmfTzQTKOBlqzvJceN1IcmOFdbRE UPNnrcr9LuHImcvJH4JvoQ8K72+YGokVSW4Yv6kYTMt0ZDtirp3EqTP5PGvXZ280B8wD gnfijQtfGpg3PUCmi0DqXJzE+xjNvDXJnssSGJfzu8Sxw4Vlr8KgqWcJEQ9vogqdIsar 7q2fQ8p1hsggAzbp8Gl3yBn8MD4GXx9boMkedpKGFOhKUh+PxbjmacX95QqS7cA9y/01 FxEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WPKC0wK+FKNPu3MyKk+MS6yY/d3H+yVt/44H3aUyXLk=; fh=5NYY5C9OxlVU2a9T6sg3ycgImBESveLBha6+VTt5udQ=; b=kOpG1KZXyXwkhOR2ABBLgVxRaQItYhHbqjPpTDv5ZdNxakmv0hc9IJl9T1hokWxioP u1XtcydMMEzmjOtalaNb71h0PIbeIMr+AQusMz/ORKMStshP/dt3KVGGr3xPfcmvn6jv vSQItyYiAT3PSFRj1Pr3np8Bl87nIoCTtsm1yocnlBLS34aoti+W7bhxFW37OJoFkk+9 x1QYG/SH/ZgxCZutHNhGnNhHdMrXAlSDpz89wwnnhjmrALC0IYBdKJRcdhF5/wKhZ/vV VCGkgwmiaIBhBx0XFYy/mm3NxGsLaRaDoHQHs/jsi16iQ0HwcbfzNDP7+UhLC4fBb7Zi hXxA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773336289; x=1773941089; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WPKC0wK+FKNPu3MyKk+MS6yY/d3H+yVt/44H3aUyXLk=; b=QnR/+gvG0Dxjnp6nfUE7VNYyd6PW5W/v8XhcYnwrisjKgQNmuKHe1VWyZohSVHadi1 6wV/mDnwgLvmqaDPcFZDZKsgUEuQeaCRlTIoNYiTpbe4Bp683NzOn2aTcdh36xMqRKx+ rtjaOHzDXFOD/D2QyYnb8hkl9hIFlKWgXu/NKoBUX4oG0yg1Lh2LBx8xccRE78Vx7FWn kajA6AcKA6ftBnRf9fW82MQDi0DWRM2MQZDDUNlyqxQbeubaJb7EkT1uSdw3f7AW+MS2 4wxyy0ZXqeznWZNjUJyd83g3/Grd1c4ZNAgnhIYN1TZbX4EM8OojreQ/Neqt1KY43mVu sf6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773336289; x=1773941089; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WPKC0wK+FKNPu3MyKk+MS6yY/d3H+yVt/44H3aUyXLk=; b=n/Lokue3WD0mjwJp4SsXkoxHtfMSblObJHSrZU6/a/Qdniwv/ob4Pp6+oZ7KR7GQOG 69QeXDbkOJkqlbA+8F5YEp3sDhTwdQ9qzkgkMgl/oEZ977He40LOqEQRaz0MlNZ4RVWX So7F40/q5GR1KdW3DPKFBpB1KX+S2MpyBxJFLht6hficSEGXS3zwYOO+CbQpeh4q8BHZ kBNdZgBhpDcug3TrNlLyQ4mqavL+WOxolwe91K/hq6wePhv/owNHiYr+QXg+xMZBgYO5 AAILN/fUOjwiErERDYGU02FK3WjhisgjTfFxg3a2fhlD5qFwN8U8uFPBYGfqhulhnHbn 4Pqw== X-Forwarded-Encrypted: i=1; AJvYcCWRoJ/cGAA3B4p9QiEqLytyyYNO/bjesY5wVBs78SwSbdw37E4PhgSF5uDVR/Cs+PtP062lDjTDpiGM/eVD@postgresql.org X-Gm-Message-State: AOJu0YwIU5BXJJSVwTH2dxZ3Mm3T5/1KoVZahfT2ra+G2IfYGyyWUV4W aozmvDLEB7qFOeUgwcb440pj31DOEJbIyLUZQtRZCy/qy6PfoMu+tmX1OEL8Ij1XIqVw/+1CT33 /z+L46Rhi4JaBx/Iayiakqh1HxlqAef97ngkX X-Gm-Gg: ATEYQzwSj91gYp0f60LKrW4KYVyb7fGASi7Cw1tx9G/cCe+tFOlizflHP+I81BJwXAI qk/ThqbsWQDC85D2ZTvgAykjxUYuaGZeDY0znOWR+T+IRlemsKCqTKSf3BMLuVeloVtUijXw4Qj 6UB2nmB1m/mFXTPfo8OcenQdOuJJLsRvKersUu5dywqaGJwd38Vv36AcM6WwhmfC6ZsDrt10aqe fIA3h1f4PwEx4IJhdrDzX8nC0gg4IZRnaTCnNGQ0DmFlbs8DaSlqSvGe7mhfu2ggqjFMzJx9rgJ lypKYnWL//P/S5BnE7Hdmaw6J/b4wMib0VAFAczOsA== X-Received: by 2002:a05:6820:829:b0:679:f16a:622b with SMTP id 006d021491bc7-67bda97acf9mr130054eaf.7.1773336288821; Thu, 12 Mar 2026 10:24:48 -0700 (PDT) MIME-Version: 1.0 References: <2631a3c3-5e60-4a1a-9e20-377024322602@gmail.com> In-Reply-To: From: Fujii Masao Date: Fri, 13 Mar 2026 02:24:36 +0900 X-Gm-Features: AaiRm53qHNKsIImZlQ2lnA_eehcpKmURuiP5q7C_6qqxBB3lZTubBoTwzGpthkQ Message-ID: Subject: Re: Shutdown indefinitely stuck due to unflushed FPI_FOR_HINT record To: Anthonin Bonnefoy Cc: Andres Freund , Alexander Lakhin , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 12, 2026 at 11:08=E2=80=AFPM Anthonin Bonnefoy wrote: > > On Tue, Mar 10, 2026 at 6:11=E2=80=AFPM Andres Freund wrote: > > I'm pretty sure this is not correct as-is, it suffers from the same iss= ue as > > https://postgr.es/m/vf4hbwrotvhbgcnknrqmfbqlu75oyjkmausvy66ic7x7vuhafx%= 40e4rvwavtjswo > > I.e. it is not safe to use GetXLogInsertRecPtr() to determine up to whe= re to > > flush to, due to page boundaries. Thanks for the report! > I've managed to reproduce this issue by ensuring the FPI_FOR_HINT > record finishes at the end of a page with the following script (might > need some adjustment if the record sizes are different): > > DROP TABLE IF EXISTS test_insert_rec_ptr; > CREATE TABLE test_insert_rec_ptr(aid int, data text) WITH > (autovacuum_enabled =3D false); > INSERT INTO test_insert_rec_ptr SELECT *, repeat('a', 100) FROM > generate_series(0, 57); > -- This should tag the page as full > BEGIN; UPDATE test_insert_rec_ptr SET aid=3D2 where aid=3D1; ROLLBACK; > CHECKPOINT; > -- Start with a fresh file > SELECT pg_switch_wal(); > -- Our FPI_FOR_HINT writes 8193 bytes > -- With the long header, the first page has 8152 bytes available > -- With the short header, the second page has 8168 bytes available > -- We want our FPI_FOR_HINT to finish at the end of the second page > (+/- 8 bytes of alignment) > -- We need to write the first 25 bytes (or 32 with alignment) in the firs= t page > -- For that, we need to write 8120 bytes of WAL records > BEGIN; > -- 264 bytes of FPW > INSERT INTO test_insert_rec_ptr VALUES(1); > -- 74 * 104 bytes > INSERT INTO test_insert_rec_ptr SELECT *, repeat('a', 44) FROM > generate_series(1, 74); > -- 108 bytes > INSERT INTO test_insert_rec_ptr VALUES(1, repeat('a', 48)); > -- 46 bytes > COMMIT; > -- 264 + 74 * 104 + 46 + 108 =3D 8114 bytes, which will round up to 8120 > with alignment > -- FPI_FOR_HINT record should be at 0x1FE0 > BEGIN; SELECT * FROM test_insert_rec_ptr WHERE aid=3D2; ROLLBACK; > > As far as I can tell, the only impact it has is to complain about the > write request being too far: > LOG: request to flush past end of generated WAL; request 0/01604018, > current position 0/01604000 > ERROR: xlog flush request 0/01604018 is not satisfied --- flushed > only to 0/01604000 > > To avoid this issue, it sounds like we need something to use > XLogBytePosToEndRecPtr instead of XLogBytePosToRecPtr to convert the > byte position? With XLogBytePosToRecPtr(), the flush request would > stop at 01604000 instead of going to the next page with 01604018. > > In the attached patch, I've added a GetXLogInsertEndRecPtr() function > which is similar to GetXLogInsertRecPtr(), except it uses > XLogBytePosToEndRecPtr() to stop at the page boundary. > There was also another XLogFlush(GetXLogWriteRecPtr()) call in > syncutils.c, so I replaced both calls with > XLogFlush(GetXLogInsertEndRecPtr()). Thanks for investigating the issue and making the patch! It looks good to me. Andres, Do you have any comments on the proposed patch? Regards, --=20 Fujii Masao