Hi, While looking at BUG #19890 [1], I ran into another issue with pg_receivewal. When it restarts and resumes into an existing compressed .partial segment, it can leave old data at the end of the file. With LZ4, every later start fails with ERROR_frameType_unknown until you remove the segment. With gzip, pg_receivewal skips the segment at startup with an incorrect uncompressed size warning.
dir_open_for_write() reopens the .partial file without O_TRUNC. So the new compressed stream overwrites from offset 0, and if it ends up shorter than what was already on disk (for example with --synchronous, where live flushes compress worse than catching up after a restart), the tail of the old file stays even after the segment is renamed. IIUC, compressed segments are never padded and are always written from the start, so we can just pass O_TRUNC for them. Attached 0001 does that (I could repro it on all supported versions, so it seems worth backpatching down to v15). 0002 is a TAP test that reproduces the failure, not meant for commit. Thoughts? [1] https://postgr.es/m/[email protected] Regards, Ayush
v1-0001-pg_receivewal-Truncate-compressed-WAL-files-when-.patch
Description: Binary data
v1-0002-Add-a-test-for-resuming-into-a-compressed-partial.patch
Description: Binary data
