Re: pg_rewind with cascade standby doesn't work well

Поиск
Список
Период
Сортировка
От Kuwamura Masaki
Тема Re: pg_rewind with cascade standby doesn't work well
Дата
Msg-id CAMyC8qpq9dkh79oHsJ9-DjVovWDOQSk7Q+bFCq_a2nXQqJe9ig@mail.gmail.com
обсуждение исходный текст
Ответ на pg_rewind with cascade standby doesn't work well  (Kuwamura Masaki <kuwamura@db.is.i.nagoya-u.ac.jp>)
Ответы Re: pg_rewind with cascade standby doesn't work well  (Aleksander Alekseev <aleksander@timescale.com>)
Список pgsql-hackers
> Consider a scenario like this,

> Server A: primary
> Server B :replica of A
> Server C :replica of B

> and somehow A down ,so B gets promoted.
> Server A: down
> Server B :new primary
> Server C :replica of B

> In this case, pg_rewind can be used to reconstruct the cascade; the source is C and the target is A.
> However, we get error as belows by running pg_rewind.

>  ```
>  pg_rewind: fetched file "global/pg_control", length 8192
>  pg_rewind: source and target cluster are on the same timeline
>  pg_rewind: no rewind required
>  ```

To fix the above mentioned behavior of pg_rewind, I suggest to change the cascade standby's (i.e. server C's) minRecoveryPointTLI when it receives the new timeline information from the new primary (i.e. server B).

When server B is promoted, it creates an end-of-recovery record by calling CreateEndOfRecoveryRecord(). (in xlog.c)
And also updates B's minRecoveryPoint and minRecoveryPointTLI.
```
/*
      * Update the control file so that crash recovery can follow the timeline
      * changes to this point.
      */
     LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
     ControlFile->minRecoveryPoint = recptr;
     ControlFile->minRecoveryPointTLI = xlrec.ThisTimeLineID;
     UpdateControlFile();
     LWLockRelease(ControlFileLock);
```
Since C is a replica of B, the end-of-recovery record is replicated from B to C, so the record is replayed in C by xlog_redo().
The attached patch updates minRecoveryPoint and minRecoveryPointTLI at this point by mimicking CreateEndOfRecoveryRecord().
With this patch, you can run pg_rewind with cascade standby immediately. (without waiting for checkpointing)

Thoughts?

Masaki Kuwamura
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Lepikhov Andrei"
Дата:
Сообщение: Re: MergeJoin beats HashJoin in the case of multiple hash clauses
Следующее
От: Amit Kapila
Дата:
Сообщение: Re: persist logical slots to disk during shutdown checkpoint