Re: In-place upgrade with streaming replicas

From: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: richard(at)kojedz(dot)in
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: In-place upgrade with streaming replicas
Date: 2025-02-19 15:54:03
Message-ID: 202502191554.6asefyczl7jn@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On 2025-Feb-19, richard(at)kojedz(dot)in wrote:

> With this, I have the question, that after the shutdown of primary, what is
> the guarantee for replicas having the same checkpoint location? Why does the
> order of shutting down the servers matter? What would be the really exact
> and reliable way to ensure that replicas will have the same checkpoint
> location as the primary?

The replicas can't write WAL by themselves, but they will replay
whatever the primary has sent; by shutting down the primary first and
letting the replicas catch up, you ensure that the replicas will
actually receive the shutdown record and replay it. If you shut down
the replicas first, they can obviously never catch up with the shutdown
checkpoint of the primary.

As I recall, if you do shut down the primary first, one potential danger
is that the primary fails to send the checkpoint record before shutting
down, so the replicas won't receive it and obviously will not replay it;
or simply that they are behind enough that they receive it but don't
replay it.

You could use pg_controldata to read the last checkpoint info from all
nodes. You can run it on the primary after shutting it down, and then
on each replica while it's still running to ensure that the correct
restartpoint has been created.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Someone said that it is at least an order of magnitude more work to do
production software than a prototype. I think he is wrong by at least
an order of magnitude." (Brian Kernighan)

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2025-02-19 16:03:41 Re: Does export operation cancel SQLs?
Previous Message Ron Johnson 2025-02-19 15:42:54 Re: Does export operation cancel SQLs?

Browse pgsql-general by date

  From Date Subject
Next Message Sándor Daku 2025-02-19 16:09:01 Re: ERROR: stack depth limit exceeded
Previous Message Csányi Pál 2025-02-19 15:49:07 Re: ERROR: stack depth limit exceeded