Re: Streaming replication failover/failback - Mailing list pgsql-general

From Jehan-Guillaume de Rorthais
Subject Re: Streaming replication failover/failback
Date
Msg-id 20161117093904.52fa4de3@firost
Whole thread Raw
In response to Streaming replication failover/failback  (Israel Brewster <israel@ravnalaska.net>)
Responses Re: Streaming replication failover/failback
List pgsql-general
On Wed, 16 Nov 2016 15:51:26 -0900
Israel Brewster <israel@ravnalaska.net> wrote:

> I've been playing around with streaming replication, and discovered that the
> following series of steps *appears* to work without complaint:
>
> - Start with master on server A, slave on server B, replicating via streaming
> replication with replication slots.
> - Shut down master on A
> - Promote slave on B to master
> - Create recovery.conf on A pointing to B
> - Start (as slave) on A, streaming from B
>
> After those steps, A comes up as a streaming replica of B, and works as
> expected. In my testing I can go back and forth between the two servers all
> day using the above steps.
>
> My understanding from my initial research, however, is that this shouldn't be
> possible - I should need to perform a new basebackup from B to A after
> promoting B to master before I can restart A as a slave. Is the observed
> behavior then just a "lucky fluke" that I shouldn't rely on?

No, it's not a "lucky fluke".

See
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=985bd7d49726c9f178558491d31a570d47340459

The only thing you should really pay attention is that the standby was in
Streaming Rep when you instructed the master to shut down, and that it stays
connected until the full stop of the master.

If you really want to check everything, use pg_xlogdump on the standby and make
sure the standby received the "shutdown checkpoint" from the master and wrote
it in its WAL.

> Or is it expected behavior and my understanding about the need for a new
> basebackup is simply off?

This is expected, but taking a new basebackup was a requirement for some time.

> Does the new pg_rewind feature of 9.5 change things? If so, how?

pg_rewind helps if your standby was not connected when you lost/stopped your
master. It reverts the last transactions the master received and that was not
streamed to the promoted standby.

Regards,


pgsql-general by date:

Previous
From: "Charles Clavadetscher"
Date:
Subject: Re: Request to share information regarding deadlock in postgresql-9.3.6
Next
From: Mark Anns
Date:
Subject: Re: How the Planner in PGStrom differs from PostgreSQL?