On Tue, May 5, 2015 at 5:53 PM, Andres Freund <andres@anarazel.de> wrote:
> Was there any consideration for initializing restart_lsn to the latest > WAL write pointer when a slot is created? Or for allowing an optional > parameter in pg_create_(physical|logical)_replication_slot() for > specifying the restart_lsn at slot creation?
I've been wondering about allowing for the latter alternative. I could have used it a couple times. The former doesn't make much sense to me, it could be too far *ahead* in many cases actually. A patch for this would be fairly trivial.
Attached is the patch that takes the former approach (initialize restart_lsn when the slot is created). I think it's better than the latter approach (depend on user to specify an LSN) because the LSN user specifies may have already been recycled. 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.
The function pg_create_physical_replication_slot() now has an additional boolean parameter 'activate' which user can use to allocate restart_lsn as part of the creation process.