Re: Speed up the removal of WAL files - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: Speed up the removal of WAL files
Date
Msg-id CAHGQGwHXd+39svrz8KZZwKOY6VdwQqXQbMVaGh2r3cKRwvzgFg@mail.gmail.com
Whole thread Raw
In response to RE: Speed up the removal of WAL files  ("Tsunakawa, Takayuki" <tsunakawa.takay@jp.fujitsu.com>)
Responses Re: Speed up the removal of WAL files  (Michael Paquier <michael.paquier@gmail.com>)
RE: Speed up the removal of WAL files  ("Tsunakawa, Takayuki" <tsunakawa.takay@jp.fujitsu.com>)
List pgsql-hackers
On Fri, Nov 17, 2017 at 5:20 PM, Tsunakawa, Takayuki
<tsunakawa.takay@jp.fujitsu.com> wrote:
> From: Kyotaro HORIGUCHI [mailto:horiguchi.kyotaro@lab.ntt.co.jp]
>> The orinal code recycles some of the to-be-removed files, but the patch
>> removes all the victims.  This may impact on performance.
>
> Yes, I noticed it after submitting the patch and was wondering what to do.  Thinking simply, I think it would be just
enoughto replace durable_unlink/durable_rename in RemoveXLogFile() with unlink/rename, and sync the pg_wal directory
oncein RemoveNonParentXlogFiles() and RemoveOldXlogFiles().  This will benefit the failover time when fast promotion is
notperformed.  What do you think? 

It seems not good idea to just replace durable_rename() with rename()
in RemoveOldXlogFiles()->RemoveXlogFiles()->InstallXLogFileSegment().
Because that change seems to be able to cause the following problem.

1. Checkpoint calls RemoveOldXlogFiles().
2. It recycles the WAL file AAA to BBB. pg_wal directory has not fsync'd yet.
3. Another transaction (TX1) writes its WAL data into the (recycled) file BBB.
4. CRASH and RESTART
5. The WAL file BBB disappears and you can see AAA,   but AAA is not used in recovery. This causes data loss of
transaction by Tx1.

Regards,

--
Fujii Masao


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Consistently catch errors from Python _New() functions
Next
From: Peter Geoghegan
Date:
Subject: Re: Treating work_mem as a shared resource (Was: Parallel Hash take II)