Re: pg_receivewal starting position
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Ronan Dunklau <ronan.dunklau@aiven.io>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>, pgsql-hackers@lists.postgresql.org, Masahiko Sawada <sawada.mshk@gmail.com>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: 2021-09-01T00:24:50Z
Lists: pgsql-hackers
On Mon, Aug 30, 2021 at 11:55:42AM +0200, Ronan Dunklau wrote:
> Le vendredi 27 août 2021, 05:44:32 CEST Michael Paquier a écrit :
>> + if (slot == NULL || !slot->in_use)
>>
>> [...] +
>> ereport(ERROR,
>> + (errcode(ERRCODE_UNDEFINED_OBJECT),
>> + errmsg("replication slot \"%s\" does not exist",
>> + cmd->slotname)));
>> [...]
>> + if (PQntuples(res) == 0)
>> + {
>> + pg_log_error("replication slot %s does not exist",
>> slot_name); + PQclear(0);
>> + return false;
>> So, the backend and ReadReplicationSlot() report an ERROR if a slot
>> does not exist but pg_basebackup's GetSlotInformation() does the same
>> if there are no tuples returned. That's inconsistent. Wouldn't it be
>> more instinctive to return a NULL tuple instead if the slot does not
>> exist to be able to check after real ERRORs in frontends using this
>> interface?
>
> The attached patch returns no tuple at all when the replication slot doesn't
> exist. I'm not sure if that's what you meant by returning a NULL tuple ?
Just return a tuple filled only with NULL values. I would tend to
code things so as we set all the flags of nulls[] to true by default,
remove has_value and define the number of columns in a #define, as of:
#define READ_REPLICATION_SLOT_COLS 5
[...]
Datum values[READ_REPLICATION_SLOT_COLS];
bool nulls[READ_REPLICATION_SLOT_COLS];
[...]
MemSet(nulls, true, READ_REPLICATION_SLOT_COLS * sizeof(bool));
Assert(i == READ_REPLICATION_SLOT_COLS); // when filling values.
This would make ReadReplicationSlot() cleaner by removing all the
else{} blocks coded now to handle the NULL values, and that would be
more in-line with the documentation where we state that one tuple is
returned. Note that this is the same kind of behavior for similar
in-core functions where objects are queried if they don't exist.
I would also suggest a reword of some of the docs, say:
+ <listitem>
+ <para>
+ Read the information of a replication slot. Returns a tuple with
+ <literal>NULL</literal> values if the replication slot does not
+ exist.
+ </para>
>
>> A slot in use exists, so the error is a bit confusing here
>> anyway, no?
>
> From my understanding, a slot *not* in use doesn't exist anymore, as such I
> don't really understand this point. Could you clarify ?
Yeah, sorry about that. I did not recall the exact meaning of
in_use. Considering the slot as undefined if the flag is false is the
right thing to do.
> I was thinking that maybe instead of walking back the timeline history from
> where we currently are on the server, we could allow an additional argument
> for the client to specify which timeline it wants. But I guess a replication
> slot can not be present for a past, divergent timeline ? I have removed that
> suggestion.
The parent TLI history is linear, so I'd find that a bit strange in
concept, FWIW.
>> - 'slot0'
>> + 'slot0', '-p',
>> + "$port"
>> Something we are missing here?
>
> The thing we're missing here is a wrapper for command_fails_like. I've added
> this to PostgresNode.pm.
It may be better to apply this bit separately, then.
--
Michael
Commits
-
Add TAP test for pg_receivewal with timeline switch
- 0f9b9938a036 15.0 landed
-
Speed up TAP tests of pg_receivewal
- d680992af540 15.0 landed
-
Allow pg_receivewal to stream from a slot's restart LSN
- f61e1dd2cee6 15.0 landed
-
Add replication command READ_REPLICATION_SLOT
- b4ada4e19fd7 15.0 landed
-
doc: Describe calculation method of streaming start for pg_receivewal
- 438d467a5241 10.19 landed
- e6c5f1b45265 11.14 landed
- fb1aa489e481 12.9 landed
- 7c949f1b3aab 13.5 landed
- affec9f6a2de 14.1 landed
- 1e9475694b0a 15.0 landed
-
Add PostgresNode::command_fails_like()
- de1d4fef71cb 15.0 landed