[PATCH] Compressed TOAST data corruption with REPACK CONCURRENTLY

From: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, ah(at)cybertec(dot)at
Subject: [PATCH] Compressed TOAST data corruption with REPACK CONCURRENTLY
Date: 2026-04-16 06:13:42
Message-ID: CAHg+QDeXb9HM2VGKXQedyCp52GzajJK5KOUdNi6oLjsS0nerQw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

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.

Thanks,
Satya

Attachment Content-Type Size
0001-Fix-restore_tuple-losing-varlena-compression-flag.patch application/octet-stream 654 bytes
0002-Add-compressed-TOAST-test-to-repack_toast.patch application/octet-stream 4.7 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Jakub Wartak 2026-04-16 06:09:43 Re: Add errdetail() with PID and UID about source of termination signal