Temporary WAL segments files not cleaned up after an instance crash - Mailing list pgsql-hackers

From Michael Paquier
Subject Temporary WAL segments files not cleaned up after an instance crash
Date
Msg-id 20180514054955.GF1528@paquier.xyz
Whole thread Raw
Responses Re: Temporary WAL segments files not cleaned up after an instancecrash  (Yugo Nagata <nagata@sraoss.co.jp>)
List pgsql-hackers
Hi all,

While playing with a standby as follows I noticed that xlogtemp.*
generated in pg_wal may stay around when entering crash recovery.  The
test I was conducting is pretty simple:
- Use a primary and a standby.
- Run pgbench on the primary.
- Then restart the standby with -m immediate and force WAL segment
switch on the primary in a loop.  Depending on the timing, one can see
that those xlogtemp files stay around.  Those files are here when
creating a new segment from scratch and append the PID of the process
creating them.  Any previous file existing with the same name is
unlinked.

The problem is that if an instance is not really stable for a reason or
another and starts crash recovery periodically, then there is a risk of
accumulating those temporary files.  If pg_wal is on its own partition,
tuned by max_wal_size, then there is a risk to run into ENOSPC and take
PostgreSQL down as new WAL segments cannot be created.

Shouldn't those files be cleaned up at the beginning of crash recovery?
Attached is a proposal of patch doing so.

Thoughts?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Incorrect comment in get_partition_dispatch_recurse
Next
From: Amit Khandekar
Date:
Subject: Re: Needless additional partition check in INSERT?