On Tue, Aug 28, 2018 at 08:23:11AM -0400, Stephen Frost wrote:
> * Andres Freund (andres@anarazel.de) wrote:
>> Uh, where is that "control file last" bit coming from?
>
> pg_basebackup copies it last. The comments should probably be improved
> as to *why* but my recollection is that it's, at least in part, to
> ensure the new cluster can't be used until it's actually a complete
> backup.
What we have now is mainly in basebackup.c. See 8366c780 which
introduced that. Stephen has that right, as we cannot rely on an
end-backup record when taking a backup from a standby, copying the
control file last ensures that the consistent point should be late
enough that no other pages are inconsistent. Even with that, I think
that there is still a small race condition but I cannot put my finger on
it now. I agree that the current comments do a bad job as to why this
happens. That's actually something I discovered when discussing what
has resulted in f267c1c2.
--
Michael