Re: Trap errors from streaming child in pg_basebackup to exit early

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Magnus Hagander <magnus(at)hagander(dot)net>
Subject: Re: Trap errors from streaming child in pg_basebackup to exit early
Date: 2021-09-03 09:53:01
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> On 1 Sep 2021, at 12:28, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
> On Wed, Sep 1, 2021 at 1:56 PM Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>> A v2 with the above fixes is attached.
> Thanks for the updated patch. Here are some comments:
> 1) Do we need to set bgchild = -1 before the exit(1); in the code
> below so that we don't kill(bgchild, SIGTERM); unnecessarily in
> kill_bgchild_atexit?

Good point. We can also inspect bgchild_exited in kill_bgchild_atexit.

> 2) Missing "," after "On Windows, we use a ....."
> + * that time. On Windows we use a background thread which can communicate
> 3) How about "/* Flag to indicate whether or not child process exited
> */" instead of +/* State of child process */?


> 4) Instead of just exiting from the main pg_basebackup process when
> the child WAL receiver dies, can't we think of restarting the child
> process, probably with the WAL streaming position where it left off or
> stream from the beginning? This way, the work that the main
> pg_basebackup has done so far doesn't get wasted. I'm not sure if this
> affects the pg_basebackup functionality. We can restart the child
> process for 1 or 2 times, if it still dies, we can kill the main
> pg_baasebackup process too. Thoughts?

I was toying with the idea, but I ended up not pursuing it. This error is well
into the “really shouldn’t happen, but can” territory and it’s quite likely
that some level of manual intervention is required to make it successfully
restart. I’m not convinced that adding complicated logic to restart (and even
more complicated tests to simulate and test it) will be worthwhile.

Daniel Gustafsson

Attachment Content-Type Size
v3-0001-Quick-exit-on-log-stream-child-exit-in-pg_basebac.patch application/octet-stream 3.3 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Ronan Dunklau 2021-09-03 09:58:27 Re: pg_receivewal starting position
Previous Message Amit Kapila 2021-09-03 09:42:32 Re: Added schema level support for publication.