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 1wDlOK-003LEz-1a for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 15:46:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDlOI-00AaHj-1F for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2026 15:45:58 +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 1wDlOI-00AaHa-0D for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 15:45:58 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDlOF-00000001g6M-2Ffj for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2026 15:45:57 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-488971db0fdso9113095e9.0 for ; Fri, 17 Apr 2026 08:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1776440754; x=1777045554; darn=lists.postgresql.org; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=yKNeqdVM7gKwLik8H/F9Vo+AhdcUQ4G+PUGgvEzeAZM=; b=pNvAMQz9iYtighnkOFSvr+c7WGweM5SJhoiR9Xfy7Suso5qe/+49FaYQKWy1kmBe57 FGbrnIIR1zUMZF4s6IE0YqaxftB1354OF4cbsWdQiy/aDe7xPtbN2FgoVprm7x1qp/T8 ilnxXhjEp1+7yl3vSChX+CUV0TUSk4kRBqDtZPLtfYB1858XBQFFlEVLRGAs/YSqMqrC oc4fE4uv58w6WoHe6QUeWsTjoUJHNrOvDnqkqzs+gPfzWM43XOOUGS8PyY4OZieoxDDB deS0HbEha0ujDOWlgJO44DG4V/lPTXX1/S3cxio0sWkU5lImoZkVZj8rh3y64tyOAWDD AV8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776440754; x=1777045554; h=message-id:date:mime-version:comments:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=yKNeqdVM7gKwLik8H/F9Vo+AhdcUQ4G+PUGgvEzeAZM=; b=srVu11WqBuxCDhsQXyjy9YpqFHp3FbIBEF5YLMCBDnfq7aAT71JQXQMGP+KtfgqeLC QgH4yeoA/YNpJPfdQKTThoTLQexbTY/qBe9dQyDaaOSfMbQVArKMVcw9Tzv74Np97KLD l1TJ1berrUaMyCHpxtdxR8eHPbpz/PPhUBIxQUWZeE/ZVACHoNXeCyqeHYsGYeEO0dhG TqV+F53o6BnqHf0ZTsN0MD9tgwyuipChqHm0/JnxlRTBi7xt3o8JpF+5Pe2NJcQ5/2pt 1Pt/K3tmWTxySXtOtVAFWay9McoDeteiqXre1j0mza/cpx6LO9lOywDy0eYPHUURqR72 B76g== X-Gm-Message-State: AOJu0YzRtsOSoPkCllENhVRCjvaFdZVfctJaNNm/UhNtGFMMuigifWH6 U3kpgbxdKOElbDTSCaUefs+1tnJXmTbvtXRzgKIDn8WAGUgadEsTjXATyLmyefk5t0M= X-Gm-Gg: AeBDiesqnhofBWCQHRMTZKZURwRZWgqJ6l+CPnKsqfOFKZDgrmZd9ce6B9cirybqAaP mpkODRVXNHGLoyup8cEnpBzTY7lQXbXErts0G6qk5CIvoWOBhFyn4d4RRANiIF4EEJs4cNnYMbJ GG/p4A3gJ1DozUJC6PBeAKzMQyV40S3taFrItvxk2ZKpDzue6QYwX+UZrmOUr+IM4/tOFU/Qecc //jfJvQtsm9KKIUOVUq+rif0rPKKhzuGHV4r4mMYJ5v3yTr/oRhRe0j92o5FIU13hlvwFCNuhTX Zv0GANZFo/AeFVyhB3nK5HgbCa8lKfA5w+o7hdf2MDv0tdyB7KROknhEMi4KSfD6VjRatwcxbWs p+HqzNa4x+2sEx6n3u24qT4VtD36jeGFTJZwghosW5BVmHq6ZZPkrmtD9WpTqzy/CpMYx1SUsQp n6UmPv/veMjq9fb1XQSRwrnxN24bnAeWV4ey1vOoAhVF9lYqw= X-Received: by 2002:a05:600c:4895:b0:488:ffad:6728 with SMTP id 5b1f17b1804b1-488ffad67f4mr2659105e9.19.1776440753634; Fri, 17 Apr 2026 08:45:53 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fc1c0354sm47216525e9.11.2026.04.17.08.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 08:45:53 -0700 (PDT) From: Antonin Houska To: SATYANARAYANA NARLAPURAM cc: PostgreSQL Hackers , alvherre@kurilemu.de Subject: Re: [PATCH] Compressed TOAST data corruption with REPACK CONCURRENTLY In-reply-to: References: Comments: In-reply-to SATYANARAYANA NARLAPURAM message dated "Wed, 15 Apr 2026 23:13:42 -0700." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Fri, 17 Apr 2026 17:45:52 +0200 Message-ID: <52301.1776440752@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain 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 not able to verify the fix. I'll take a closer look early next week. -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=fix_restore_tuple.diff diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c index e2600a8888d..3c07e44d649 100644 --- a/src/backend/commands/repack.c +++ b/src/backend/commands/repack.c @@ -2736,7 +2736,7 @@ restore_tuple(BufFile *file, Relation relation, TupleTableSlot *slot) varlensz = VARSIZE_ANY(&chunk_header); value = palloc(varlensz); - SET_VARSIZE(value, VARSIZE_ANY(&chunk_header)); + memcpy(value, &chunk_header, VARHDRSZ); BufFileReadExact(file, (char *) value + VARHDRSZ, varlensz - VARHDRSZ); slot->tts_values[i] = PointerGetDatum(value); --=-=-=--