Re: Allowing pg_recvlogical to create temporary replication slots - Mailing list pgsql-hackers

From Torsten Förtsch
Subject Re: Allowing pg_recvlogical to create temporary replication slots
Date
Msg-id CAKkG4_m+DwWVDCX7S34_L9y=JoGAiGDeyj5XEXSNzvv8J2HHHQ@mail.gmail.com
Whole thread Raw
In response to Re: Allowing pg_recvlogical to create temporary replication slots  (Dickson Guedes <guedes@guedesoft.net>)
Responses Re: Allowing pg_recvlogical to create temporary replication slots
List pgsql-hackers
Hi Dickson,

While reviewing your patch for pg_recvlogical, I’m curious about the
expected behavior when using --if-not-exists in conjunction with --temporary-slot.

If an existing slot is reused under these options, will it behave as
a temporary slot and be removed when the connection ends? Or the
existing slot should remain persistent despite the --temporary-slot flag?

 If the slot did not exist before, it is created as a temporary slot. If subsequently the connection drops and pg_recvlogical reconnects (no -n option), the slot is created again as a temporary slot. That means changes happening in between will not be captured. 

If the slot existed before, the existing slot will be used, no error is generated. In that case the slot will keep existing when the connection is dropped.

The following situation can happen:
- the slot does not exist and is created as a temporary slot
- the connection drops and pg_recvlogical tries to reconnect after a few seconds
- in that period a permanent slot by the same name is created but no reader is connected to it
- pg_recvlogical reconnects and finds the existing slot

In this case, the now existing slot is simply used. It will remain when the connection is dropped.

Thanks for reviewing.

Basically, --if-not-exists flag tells pg_recvlogical to ignore the error it would get when creating a slot with a name that's already there. The new flag does not change that.

This is the relevant code in src/bin/pg_basebackup/streamutil.c checking the result of the CREATE_REPLICATION_SLOT command.

if (slot_exists_ok &&
    sqlstate &&
    strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
{
    ...
    return true;
}

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: explain plans for foreign servers
Next
From: vignesh C
Date:
Subject: Re: Parallel heap vacuum