Re: replication slot restart_lsn initialization - Mailing list pgsql-hackers

From Gurjeet Singh
Subject Re: replication slot restart_lsn initialization
Date
Msg-id CABwTF4VGZu5Gyw0+Ts3hd-rDcRpjKe0TmwD9JJTQSN8H-zq9fQ@mail.gmail.com
Whole thread Raw
In response to Re: replication slot restart_lsn initialization  (Andres Freund <andres@anarazel.de>)
Responses Re: replication slot restart_lsn initialization  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Wed, Jun 10, 2015 at 8:07 AM, Andres Freund <andres@anarazel.de> wrote:
On 2015-06-10 08:00:28 -0700, Gurjeet Singh wrote:

> pg_create_logical_replication_slot() prevents LSN from being
> recycled that by looping (worst case 2 times) until there's no
> conflict with the checkpointer recycling the segment. So I have used
> the same approach.

There's no need to change anything for logical slots? Or do you just
mean that you moved the existing code?

Yes, I turned the code from logical replication into a function and used it from logical and physical replication.
 
>
>  /*
> + * Grab and save an LSN value to prevent WAL recycling past that point.
> + */
> +void
> +ReplicationSlotRegisterRestartLSN()
> +{
... 
> +             /*
> +              * Let's start with enough information if we can, so log a standby
> +              * snapshot and start decoding at exactly that position.
> +              */
> +             if (!RecoveryInProgress())
> +             {
> +                     XLogRecPtr      flushptr;
> +
> +                     /* start at current insert position */
> +                     slot->data.restart_lsn = GetXLogInsertRecPtr();
> +
> +                     /* make sure we have enough information to start */
> +                     flushptr = LogStandbySnapshot();
> +
> +                     /* and make sure it's fsynced to disk */
> +                     XLogFlush(flushptr);
> +             }
> +             else
> +                     slot->data.restart_lsn = GetRedoRecPtr();
> +
 
That doesn't look right to me. Why is this code logging a standby
snapshot for physical slots?

This is the new function I referred to above. The logging of the snapshot is in 'not RecoveryInProgress()' case, meaning it's running in primary and not in a standby.

Best regards,
--

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: s_lock() seems too aggressive for machines with many sockets
Next
From: Robert Haas
Date:
Subject: Re: skipping pg_log in basebackup (was Re: pg_basebackup and pg_stat_tmp directory)