mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Allow altering of two_phase option of a SUBSCRIPTION.
The two_phase option is controlled by both the publisher (as a slot option) and the subscriber (as a subscription option), so the slot option must also be modified. Changing the 'two_phase' option for a subscription from 'true' to 'false' is permitted only when there are no pending prepared transactions corresponding to that subscription. Otherwise, the changes of already prepared transactions can be replicated again along with their corresponding commit leading to duplicate data or errors. To avoid data loss, the 'two_phase' option for a subscription can only be changed from 'false' to 'true' once the initial data synchronization is completed. Therefore this is performed later by the logical replication worker. Author: Hayato Kuroda, Ajin Cherian, Amit Kapila Reviewed-by: Peter Smith, Hou Zhijie, Amit Kapila, Vitaly Davydov, Vignesh C Discussion: https://postgr.es/m/8fab8-65d74c80-1-2f28e880@39088166
This commit is contained in:
@ -1407,12 +1407,15 @@ DropReplicationSlot(DropReplicationSlotCmd *cmd)
|
||||
}
|
||||
|
||||
/*
|
||||
* Process extra options given to ALTER_REPLICATION_SLOT.
|
||||
* Change the definition of a replication slot.
|
||||
*/
|
||||
static void
|
||||
ParseAlterReplSlotOptions(AlterReplicationSlotCmd *cmd, bool *failover)
|
||||
AlterReplicationSlot(AlterReplicationSlotCmd *cmd)
|
||||
{
|
||||
bool failover_given = false;
|
||||
bool two_phase_given = false;
|
||||
bool failover;
|
||||
bool two_phase;
|
||||
|
||||
/* Parse options */
|
||||
foreach_ptr(DefElem, defel, cmd->options)
|
||||
@ -1424,23 +1427,24 @@ ParseAlterReplSlotOptions(AlterReplicationSlotCmd *cmd, bool *failover)
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
failover_given = true;
|
||||
*failover = defGetBoolean(defel);
|
||||
failover = defGetBoolean(defel);
|
||||
}
|
||||
else if (strcmp(defel->defname, "two_phase") == 0)
|
||||
{
|
||||
if (two_phase_given)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("conflicting or redundant options")));
|
||||
two_phase_given = true;
|
||||
two_phase = defGetBoolean(defel);
|
||||
}
|
||||
else
|
||||
elog(ERROR, "unrecognized option: %s", defel->defname);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the definition of a replication slot.
|
||||
*/
|
||||
static void
|
||||
AlterReplicationSlot(AlterReplicationSlotCmd *cmd)
|
||||
{
|
||||
bool failover = false;
|
||||
|
||||
ParseAlterReplSlotOptions(cmd, &failover);
|
||||
ReplicationSlotAlter(cmd->slotname, failover);
|
||||
ReplicationSlotAlter(cmd->slotname,
|
||||
failover_given ? &failover : NULL,
|
||||
two_phase_given ? &two_phase : NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user