From: | Japin Li <japinli(at)hotmail(dot)com> |
---|---|
To: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Re-archive the WAL on standby with archive_mode=always? |
Date: | 2025-07-23 01:45:08 |
Message-ID: | ME0P300MB044574FF061A408F288083BBB65FA@ME0P300MB0445.AUSP300.PROD.OUTLOOK.COM |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, 23 Jul 2025 at 09:24, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Mon, Jul 21, 2025 at 2:38 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>>
>>
>> Hi, hackers,
>>
>> I was recently reviewing the KeepFileRestoredFromArchive() function and came
>> across a section that raised a question for me:
>>
>> /*
>> * Create .done file forcibly to prevent the restored segment from being
>> * archived again later.
>> */
>> if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
>> XLogArchiveForceDone(xlogfname);
>> else
>> XLogArchiveNotify(xlogfname);
>>
>> My understanding is that the WAL segment in this context has just been
>> restored from the archive.
>>
>> However, for archive_mode=always, the code calls XLogArchiveNotify(xlogfname),
>> which, if I understand correctly, signals the archiver to re-archive this
>> already-archived WAL segment.
>>
>> Is there a specific scenario or benefit I'm overlooking?
>
> One possible scenario is when the archive directory used by restore_command
> is different from the one used by archive_command. For example, the primary
> and standby servers might each have their own separate archive directories,
> with archive_command configured to archive WAL files to their
> respective directories.
> Meanwhile, the standby’s restore_command might be set up to fetch WAL files
> from the primary’s archive directory. This kind of setup can be used
> when there’s
> no shared archive directory between the primary and standby. In such cases,
> even WAL files restored on the standby might need to be archived again.
>
Thanks for your explanation.
Yes, I've encountered this exact scenario: when promoting a standby and then
re-joining the old primary, they maintain separate WAL archive directories.
I've attached a script to reproduce this.
I've observed that WalReceiverMain() archives WALs upon receipt, and
StartupXLOG() subsequently restores them from the archive directory, and then
re-archives them via KeepFileRestoredFromArchive().
--
Regards,
Japin Li
Attachment | Content-Type | Size |
---|---|---|
re-archive-demo.sh | text/x-sh | 1.7 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Munro | 2025-07-23 02:44:29 | Re: Optimize LISTEN/NOTIFY |
Previous Message | Joel Jacobson | 2025-07-23 01:39:30 | Re: Optimize LISTEN/NOTIFY |