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 1wDnBa-003NEV-25 for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 17:40:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDnBY-00AjIL-1O for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 17:40:56 +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.96) (envelope-from ) id 1wDnBY-00AjID-0L for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 17:40:56 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDnBV-00000001gvs-33jD for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 17:40:55 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b8d7f22d405so166953166b.0 for ; Fri, 17 Apr 2026 10:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776447652; cv=none; d=google.com; s=arc-20240605; b=dUblXkpbamVEkR+OofgJ4QQXdk31y0+o8FWeLQ/7OnpHXlSXznQeRHQpZxQUY8Rd3J pfeomlCzL+aKttmf/+d2vYP209b0F+oMoTla4KlyIY7Q19I0BBW0Sv8R6kkXORTqh+Oq P+0eMWdrCPaPN3jP5Lf1s227Z5/nUnjDFIc7FPsBf3qtBRNwxgXqHAwK9Fl5II3jq8TG 9kxC6SGvSRU2dJk5dNcCGPD3whw/kTGRgi5ynTFW808mR4HqqKowPKbXn4rGgd4i3Hox 9ilP2bkGAGKXXEm9GBfVrFjNqGQsZatJT1AqbGphyWJVyhjgyF15Ruf1FPae4relK1Lg /76w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=NiFKDs67fWyx9odK9qANoz4xOjJO178uTaBRkkwf29A=; fh=BDLOwSorg+Pb8ccao84oo5D81G/LVIM9s15XsR7Sjhg=; b=h7ou+HCxn2KiVLCSjEQ3CygVj1bsc2TmRXv191/rakizp4NZ9KEGg76NUYDTZP4CBV 1aZuHObCbiQJUCkfFlSc2Sp46qftHbmfD/PJ+Fo18PyVICAeIMURgCyT2yVg+OoxD4l9 q7QHu1LvcXEIBh/v4/bWflZwZGoIDw5Bh6zXDIBePFnEgLUhemi2r5c2pGar90BSj/fB a2ZqnWxwFSYKT7ZQlK/G35GjvhGZlCWrom8OAjt0dL2QKgp9swAC2DjW5uIOEyozLa+t Ye8LeMUHdYWaOQuJMdVWQUYBPaN+Wx7VcbFgwPrCAaQr37mbTj4kQCcTjyQq20XiMmBF qK1w==; darn=lists.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=20251104; t=1776447652; x=1777052452; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NiFKDs67fWyx9odK9qANoz4xOjJO178uTaBRkkwf29A=; b=XlQ/MKthigygbk93j1D6sM59syboiq/dkje6dv5oahOE8qFcs/k56PNA4RbOcaJvyL tXaIZrCMTucYxcqB2wwC72tukwZ9QTn2V3SNtS8rMW+561mWjXHyMddO2evjkkbaKd3u we94nr7e+sVCjwWlt9RphWP3bgrbMDAptSfowho8rZZkqhQ3Y3Z+ZkWn+2fOf6RTsX7i NE+Mq1j76gFQi7OERUrJMb97fQf4aM/c+mGtJ1yLwhZ+YqhTCfQPJsvRRltGNkB+buOF J2gfG+CqM9awVOuVMPqykJ28nvCYoJWTQx836msl9yKJFMQMN4EeVhtFHdXM0PHjNKI+ uBOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776447652; x=1777052452; h=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=NiFKDs67fWyx9odK9qANoz4xOjJO178uTaBRkkwf29A=; b=DxuhdB82DbROhmXZBWF6Uzm7/RAurKXVtTV5NdwWQ2episyW7gFkBtcqxdM9w5WSEp bo1F5EwTFD43JEV0EIzmYI29BuUJE0whJqNyuO+oRPEzT8e8NFPsy2YCPabJAJ9pdw6Z WLQ7QZOBQjndQ1sGUq5lNobUTJDenarp403c4rN+kSekXXgLmHzmZUZR/ctVrAqX+YZ7 didPEFsnV+LJtVzfN4f01hlI8DqLn5qnX5Xo2VzgktC0O3p1AFuZSmdF10zacyY30OOO aITmeInkyoocTd7k93ycwo/qMErJtDq8lJ9H9gvU0BjWSi+MtR48ZfelQBJNV5sJew+d dccw== X-Gm-Message-State: AOJu0YyUwIk/1rjlteHKCWKCif6PQE3bbhAQ5djm5QKjvOqub6scf4o8 lKF2T1+GFRq9pK+Og5Kx7/XqJ04zAjonopsyRkamm+eQw/Fpw0v1JbTcva1GGovGBp+9JGPOcUM omL+yQ8PV7oi+IEAltqNbgvKvdtgI0A6U9w== X-Gm-Gg: AeBDietmLiFkyvJ3UeNxsgyq9ZS2vlYPGMOeh4u6vfvgyikkXgaz+E6CiEQXddgU5h/ GR9sn7SSUvQcWvVDJbZlc+7ziTgyDBdug2gawr5cFUw6mGxlAsHiyC9qq58tGRmFEkE1QcDSkgK aBAcd/LkzVgZNixLfmlV4/0tiHYFVTLHQKiAdOl42ajTTw+dcl+B3Cl4QLeRegzPh+hmPPKyu/G rWmvkI++coVMl6JgK8S6n2M+MGtk/ocTYTCxI3qJmD8WJJx2awJCQXG1faujSUV1VzYCSvIBE8l Wfjyip5MjM5Wy3U433Rir86shekm X-Received: by 2002:a17:906:478a:b0:ba5:4f56:69a3 with SMTP id a640c23a62f3a-ba54f566b84mr3472266b.27.1776447652084; Fri, 17 Apr 2026 10:40:52 -0700 (PDT) MIME-Version: 1.0 References: <52301.1776440752@localhost> In-Reply-To: <52301.1776440752@localhost> From: SATYANARAYANA NARLAPURAM Date: Fri, 17 Apr 2026 10:40:39 -0700 X-Gm-Features: AQROBzAwetOuCW8ttK4KvnmESwjKkMvSE6BW45vhc3Y_yNpEWjlLqOLJB9CUfec Message-ID: Subject: Re: [PATCH] Compressed TOAST data corruption with REPACK CONCURRENTLY To: Antonin Houska Cc: PostgreSQL Hackers , alvherre@kurilemu.de Content-Type: multipart/alternative; boundary="00000000000043c064064fab730b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000043c064064fab730b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi On Fri, Apr 17, 2026 at 8:45=E2=80=AFAM Antonin Houska wro= te: > SATYANARAYANA NARLAPURAM wrote: > > > restore_tuple() in repack.c uses SET_VARSIZE() to reconstruct the > varlena header when > > reading back external attributes from the spill file. In this process, > looks like the flag > > SET_VARSIZE_COMPRESSED is silently lost. Because of this, when REPACK > CONCURRENTLY > > run any concurrently updated column whose value was TOAST-compressed > ends up with raw > > compressed bytes behind an "uncompressed" header returning garbled data > on subsequent reads. > > It appears that existing tests are using random chars which are > uncompressable. > > > > Please find the attached > 0001-Fix-restore_tuple-losing-varlena-compression-flag.patch to fix this. > > Additionally I updated the existing repack_toast test to include the > scenario I was talking about. > > Good catch, thanks! > > I'd slightly prefer to fix it w/o checking the varlena type, as > attached. However, your test fails to reproduce the issue here, so I'm no= t > able to verify the fix. I'll take a closer look early next week. > I started with that but tried to follow the existing code pattern. This LGTM. Please add a comment as well. > > -- > Antonin Houska > Web: https://www.cybertec-postgresql.com > > --00000000000043c064064fab730b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Fri, Apr 17, 2= 026 at 8:45=E2=80=AFAM Antonin Houska <ah@cybertec.at> wrote:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> wrote:
> restore_tuple() in repack.c uses SET_VARSIZE() to reconstruct the varl= ena header when
> reading back external attributes from the spill file. In this process,= looks like the flag
> SET_VARSIZE_COMPRESSED is silently lost. Because of this, when REPACK = CONCURRENTLY
> run=C2=A0 any concurrently updated column whose value was TOAST-compre= ssed ends up with raw
> compressed bytes behind an "uncompressed" header returning g= arbled data on subsequent reads.
> It appears that existing tests are using random chars which are uncomp= ressable.
>
> Please find the attached 0001-Fix-restore_tuple-losing-varlena-compres= sion-flag.patch to fix this.
> Additionally I updated the existing repack_toast test to include the s= cenario I was talking about.

Good catch, thanks!

I'd slightly prefer to fix it w/o checking the varlena type, as
attached. However, your test fails to reproduce the issue here, so I'm = not
able to verify the fix. I'll take a closer look early next week.

I started with that but tried to follow the e= xisting code pattern. This LGTM.
Please add a comment as well.
=C2=A0

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

--00000000000043c064064fab730b--