Fix two timeline handling bugs in pg_receivexlog.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 23 Sep 2013 07:17:52 +0000 (10:17 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 23 Sep 2013 07:40:11 +0000 (10:40 +0300)
commitb882246e3ab4382b3c9f58e5f85dd8c9e3eb594f
tree68f8629a1a84f6d5a2ed0ce93e4294e08ce30d90
parent496439d943565bdb6cb2eef534cce551c30e8a0f
Fix two timeline handling bugs in pg_receivexlog.

When a timeline history file is fetched from server, it is initially created
with a temporary file name, and renamed to place. However, the temporary
file name was constructed using an uninitialized buffer. Usually that meant
that the file was created in current directory instead of the target, which
usually goes unnoticed, but if the target is on a different filesystem than
the current dir, the rename() would fail. Fix that.

The second issue is that pg_receivexlog would not take .partial files into
account when determining when scanning the target directory for existing
WAL files. If the timeline has switched in the server several times in the
last WAL segment, and pg_receivexlog is restarted, it would choose a too
old starting point. That's not a problem as long as the old WAL segment
exists in the server and can be streamed over, but will cause a failure if
it's not.

Backpatch to 9.3, where this timeline handling code was written.

Analysed by Andrew Gierth, bug #8453, based on a bug report on IRC.
src/bin/pg_basebackup/pg_receivexlog.c
src/bin/pg_basebackup/receivelog.c