How to deal with `.partial` WAL segments generated by Postgres `pg_receivewal` command? pg_receivewal creates a .partial file for incomplete WAL segment. My question is how to deal with this file during recovery. If I just leave it as it is, last transactions don't recover. If I rename the file removing .partial post-fix, the recovery procedure crashes with the error:

FATAL:  archive file "000000010000000C00000080" has wrong size: 152 instead of 16777216


The only way I found is to remove this .partial segment after the previous recovery crash and start the procedure again. This way db seems fully recovered.

What the proper way to deal with these .partial segments?

My db version is 11.5.

Update:

Following Laurenz advice I ended up with running next command right before starting the recovery.


it testes if there's no another version of the partial segment
decompresses it (as I use pg_receivewal with --compress flag)
augments it with nulls
and copies the fixed segment into pg_wal folder


find /backup/wal -name "*.partial" -exec sh -c ' \
    NAME=`basename "$0" .gz.partial`; \
    DEST=$PGDATA/pg_wal/$NAME; \
    test ! -f $DEST &amp;&amp; \
    zcat $0 &gt; $NAME &amp;&amp; \
    truncate -s16M $NAME &amp;&amp; \
    mv $NAME $DEST \
' '{}' \;


Notice it's relying on $PGDATA environment variable which usually isn't set.
Hmm, good question.

I suggest that you rename it and fill it with zeros at the end, for example using

dd if=/dev/zero of=000000010000000C00000080 oflag=append conv=notrunc bs=1024 count=16416


This could be part of your restore_command.