Question

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 && \
    zcat $0 > $NAME && \
    truncate -s16M $NAME && \
    mv $NAME $DEST \
' '{}' \;

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top