Logical decoding from promoted standby with same replication slot

From: Jeremy Finzel <finzelj(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Logical decoding from promoted standby with same replication slot
Date: 2018-07-13 19:30:58
Message-ID: CAMa1XUhnDJ6qRCbCFScs2gYLa3-MzU9o2crUjw+2UEU=jYFYVg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello -

We are working on several DR scenarios with logical decoding. Although we
are using pglogical the question we have I think is generally applicable to
logical replication.

Say we have need to drop a logical replication slot for some emergency
reason on the master, but we don't want to lose the data permanently. We
can make a point-in-time-recovery snapshot of the master to use in order to
recover the lost data in the slot we are about to drop. Then we drop the
slot on master.

We can then point our logical subscription to pull from the snapshot to get
the lost data, once we promote it.

The question is that after promotion, logical decoding is looking for a
timeline 2 file whereas the file is still at timeline 1.

The WAL file is 00000001000008FD0000003C, for example. After promotion, it
is still 00000001000008FD0000003C in pg_wal. But logical decoding says
ERROR: segment 00000002000008FD0000003C has already been removed (it is
looking for a timeline 2 WAL file). Simply renaming the file actually
allows us to stream from the replication slot accurately and recover the
data.

But all of this begs the question of an easier way to do this - why doesn't
logical decoding know to look for a timeline 1 file? It is really helpful
to have this ability to easily recover logical replicated data from a
snapshot of a replication slot, in case of disaster.

All thoughts very welcome!

Thanks,
Jeremy

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2018-07-13 20:00:04 Re: [HACKERS] Client Connection redirection support for PostgreSQL
Previous Message Heikki Linnakangas 2018-07-13 19:22:42 Re: pgsql: Fix parallel index and index-only scans to fall back to serial.