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 1vhpMa-006vca-03 for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 13:32:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vhpLZ-00DNQP-2r for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Jan 2026 13:31:10 +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 1vhpLZ-00DNQH-1c for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 13:31:09 +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.96) (envelope-from ) id 1vhpLX-001LL6-0b for pgsql-hackers@lists.postgresql.org; Mon, 19 Jan 2026 13:31:09 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b87f00ec06aso69478666b.1 for ; Mon, 19 Jan 2026 05:31:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768829461; cv=none; d=google.com; s=arc-20240605; b=FMS9fMLCOHZZt/PTFKzuDn6OBPGyGwSXjLyooPYBm0rIjbz+fwOnhXDc7LCDWB0ZpK I+vMrZurERPbBwyXr77OVfRW0B6WGqwMZlxfO6kui6RCCAbkRBXKCLtM5nDFKFR02zmn KPiL4JAbxLWxfK2C7ZC//ODou9XB/EQXDRAJsxN73/W1OM1+WYSOJAxGvlEXb0uPRx0E wtAtynoZfQzqFWFpRPAMNImlVmIsKgfpEOFw/beDRFBjwM3oG/bXRKh1kaAkjULFWYxf z9ER6P0V6O7oG5n6WRAKp+m13a0CxfpMrh2hVxP8Rm7sZLI70WuRpSdGLqgkfgbXQ+GM dBiw== 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=unhlj0ToI9jLxu4bQOrMcN1n4Q9+2wDBaH7660+c8Ws=; fh=a5tYjcsR+7/T4pMt5rxcz0YZXJbnAynrrT/8UYKTa0A=; b=JJg1W2Tguz4exCwLTKUOB3IVrIP+cJfY5dj47vlMFwjjpOBDiLjH14ImGa7oB8lZ0f gB1v6jIcx+OkQUxnTnWVXlnO7veunPGRQjqbHUrans3x016xp3Qy6LxKJU1it9orJIgv 5FoXUvuq0pahQ4y7y+leJeW3CL7KcFlX9jJjcBGaKGsclsFQLiW7amgXVlIv6yTOrMGy rlWa8dn3BUSXQfbqAR/FJ+YWCWGXHTlpGNqN2cvF/MwZo4Wz+uannbAc+RZDVLBt6Xpi h/BDl5kDceYvbt+yEMgfNeFit7kFAwRF7OW/fcZYu9xJgMrdcQbBDDDR+dBFY2ewal6H CDtw==; 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=20230601; t=1768829461; x=1769434261; darn=lists.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=unhlj0ToI9jLxu4bQOrMcN1n4Q9+2wDBaH7660+c8Ws=; b=PtywbVFmtrp5oM2hedW33itc0d4K33AFFRqPGF/mBbaV3jGxvmamj/4G/kj55Xq/QC GfEn0liP/63+6xbrbVnE2LnMd/UCRv2T3RqHy3jEztzkN3A75tyi+X2ob9V0nofSPIj2 Cx45BPgQgYBPLOt9WfXYQ54iu5Wxib4/4moDdNU3zgmI+p1r2cM7efG4ZhjiLfZr3w3i vFSj8gvoMnfoV3MRIOvS3VaTigP6d/Cs8otL4FR3BYn6hjuOflqJ6FbftL2QWPwTq3wZ kQszTDv5AgVKcFz1vqhciQmTGYHaFdkE7/92mkiPpZiKAZj6tBJc6MSyhhSjKzbqJ+21 jhWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768829461; x=1769434261; 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=unhlj0ToI9jLxu4bQOrMcN1n4Q9+2wDBaH7660+c8Ws=; b=TA/yKYjnzVxcXcBv3tObzwp8o5K/lDujtaVV2psybjw2WvdP6SKigs0m07QzWqwchY 4wXe/F0OMBn+9xTDjBuMLik6OGTf2qpSCLyv0uwRjjEoDVHXIFIUBtrHYLDMx+K6Kaoq 0jsaDpC5cNv37jZ5+iftX7r5XAAUlFHcdCimOpOcUcLiwyxv8ViOgRZ5m/Kx0KtaTSn6 61T8eHiQpI0UcSOty4tcQj2x/FlMPlXpUG6EsI2QBBvqWP0X7N2EOmq1jxWyaHQYI649 qzDbF5xcbf2WqjAhw/liPOIwmW0sEGL915lANLnti4wf1VGhSarjwPHxvHNXR3mwidAi Yjog== X-Forwarded-Encrypted: i=1; AJvYcCXgvRILu095425V1wIxM23HvxMBJBtTGvLb5Bx0wFEbJzbRjn1xdh9cU548Q/TB/Vq4fk/+ubBpyy7nvaht@lists.postgresql.org X-Gm-Message-State: AOJu0YxNOPUNISVjecyFrNVxr9c8tOLlWZTiY7FFoOoWujykHADH0/f6 ETO0njCgeYq3/h4ixuWl0LgSh6D9HtuJTCgdW25/RoGABNVVJRmscw3OE7mEdXuu2emS8dt1SJ+ gmAJ7S/2d0KDDYcML3AuC6pq9KRvG3+g= X-Gm-Gg: AY/fxX7R0upr8CPl/p7CoONPo+nO2XfkJz+gf/hsbWPtiMBiqi6eBUDkiC5oS2QW2FM HwbyOMvh3vIMZ4G10BiOlAT0fTESr8VhfkCdg8UMeb9Pvo82dOemBigwbAKdnXfvYUZ5V54QEMp P3a2JVVJ9KxQ6GhkYUh05/8/xJ9IW2JyMlu1qlS1ZJIkdCF1wv8bkIFI7TnM/g3uXOa4kcMZAzY sf84OVnFucdPBVgZn1UWxmTqmBk1nDQC21SWCTo1NhEgAvBDo8fRjkrG3gsFwlCGqD5yITzrxWW HMNgW/OizP5xemEfdgV/p+xfQYk= X-Received: by 2002:a17:906:c141:b0:b72:58b6:b263 with SMTP id a640c23a62f3a-b8793028e7amr1003423166b.60.1768829460549; Mon, 19 Jan 2026 05:31:00 -0800 (PST) MIME-Version: 1.0 References: <731ADE6F-01C5-4996-BAEE-5851DFC3F502@gmail.com> In-Reply-To: From: Robert Haas Date: Mon, 19 Jan 2026 08:30:48 -0500 X-Gm-Features: AZwV_QgBFjGV9kXaXPykTszKGK1EQAPjVMnN1x70_d2ohSuGMeznLxgkUnyIbrc Message-ID: Subject: Re: pg_waldump: support decoding of WAL inside tarfile To: Amul Sul Cc: Chao Li , Jakub Wartak , 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 Mon, Jan 19, 2026 at 6:14=E2=80=AFAM Amul Sul wrote: > We previously tried having the astreamer function perform all > necessary checks (e.g., TLI and segment number), but this became > problematic in init_archive_reader when we needed to read a single WAL > page just to determine the WAL segment size without any validation. To > bypass those checks, I initially used a READ_ANY_WAL() macro, but it > felt like a hack. > > In the current design, the archive streamer is responsible only for > reading and copying data to the buffer. To optimize this and avoid > unnecessary memcpy and data buffering for WAL files that aren't > needed, we set privateInfo->cur_wal to NULL, signaling the streamer > code to skip those operations. Hmm. In that case, the code definitely deserves a comment, as that was not at all clear to me. > But, I am thinking that instead of setting privateInfo->cur_wal to > NULL, we could simply discard the buffer data at that place and let > memcpy in astreamer_content copy if it would be that much of an issue. I don't think doing unnecessary copying is the right way forward. The copying itself could be expensive, but I am a little concerned about the memory utilization of this code. Suppose the user has increased the WAL segment size to 1GB or even higher. It seems like we could buffer a whole segment or maybe even more in some scenarios. If we avoid copying data we don't need, then we also avoid buffering it in memory. In terms of the separation of concerns, we could view setting privateInfo->cur_wal =3D NULL as a form of signaling, a way for this code to tell the astreamer that it doesn't need the data buffering. However, I think it might be better to make the signaling more explicit. Instead of having the caller directly set the buffer to NULL, or directly trim data out of the buffer, maybe it should set some value in privateInfo that tells the astreamer what to do. For instance, suppose it sets the oldest LSN that it might still care about in privateInfo, and then the astreamer is free to do skip copying of any data prior to that LSN, and discard any that it already has. Especially if properly commented, I think this might be more clear than what you have now. I am not 100% sure that's the right idea, though. I just think right now it's a bit murky who does what and why the division of responsibilities is what it is. For example, read_archive_wal_page() currently has some responsibility for discarding data, but is that because it is the right place to discard data, or is that just because that's where we have an LSN available that tells us what we can discard? I don't know, but an explicit signaling mechanism like what I describe in the previous paragraph can make it possible for those two things to happen in different places. > In the earlier version, we had only one buffer where we copied > streamed data, but a problem (previously discussed [1]) arose when the > archive streamer reads data from two WAL files -- i.e., one is ending > and the next is starting. We have to keep track of where the previous > file ends and the next one starts, along with the WAL segment > information that each belongs to. Hmm, interesting. My first thought was that if we were starting a new WAL file, isn't it time to flush the data from the old one to a spill file? But maybe it's not, if the WAL reader can reread records, and a record can span file boundaries. But probably we need some comment so that the next reader is not confused, and we definitely need to make sure that the structure members in ArchivedWALEntry are well-chosen and well-documented. > > + if (strstr(member->pathname, "PaxHeaders.")) > > + return false; > > > > There is no way that a filename containing the string "PaxHeaders." > > could ever pass the IsXLogFileName test just above. We shouldn't need > > this. > > > > This checks the directory name (e.g., > x_dir/y_dir/PaxHeaders.NNNN/wal_file_name). The name of that metadata > file is exactly the same as the WAL file name, which is why > IsXLogFileName() doesn't help here. I think this code should only be considering files in the toplevel directory, and skipping over any directories it finds. I absolutely promise I am not going to commit anything that is specifically looking for PaxHeaders. Nothing we've ever done with tar files up to now has required that, and I don't think this should, either. --=20 Robert Haas EDB: http://www.enterprisedb.com