Class PgOutputConnectionExtensions
- Namespace
- Npgsql.Replication
- Assembly
- Npgsql.dll
Extension methods to use LogicalReplicationConnection with the pg_output logical decoding plugin.
public static class PgOutputConnectionExtensions
- Inheritance
-
PgOutputConnectionExtensions
- Inherited Members
Methods
CreatePgOutputReplicationSlot(LogicalReplicationConnection, string, bool, LogicalSlotSnapshotInitMode?, bool, CancellationToken)
Creates a LogicalReplicationSlot class that wraps a replication slot using the "pgoutput" logical decoding plugin and can be used to start streaming replication via the logical streaming replication protocol.
public static Task<PgOutputReplicationSlot> CreatePgOutputReplicationSlot(this LogicalReplicationConnection connection, string slotName, bool temporarySlot = false, LogicalSlotSnapshotInitMode? slotSnapshotInitMode = null, bool twoPhase = false, CancellationToken cancellationToken = default)
Parameters
connection
LogicalReplicationConnectionThe LogicalReplicationConnection to use for creating the replication slot
slotName
stringThe name of the slot to create. Must be a valid replication slot name (see https://www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-SLOTS-MANIPULATION).
temporarySlot
booltrue if this replication slot shall be temporary one; otherwise false. Temporary slots are not saved to disk and are automatically dropped on error or when the session has finished.
slotSnapshotInitMode
LogicalSlotSnapshotInitMode?A LogicalSlotSnapshotInitMode to specify what to do with the snapshot created during logical slot initialization. Export, which is also the default, will export the snapshot for use in other sessions. This option can't be used inside a transaction. Use will use the snapshot for the current transaction executing the command. This option must be used in a transaction, and Use must be the first command run in that transaction. Finally, NoExport will just use the snapshot for logical decoding as normal but won't do anything else with it.
twoPhase
boolIf true, this logical replication slot supports decoding of two-phase transactions. With this option, two-phase commands like PREPARE TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED are decoded and transmitted. The transaction will be decoded and transmitted at PREPARE TRANSACTION time. The default is false.
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
- Task<PgOutputReplicationSlot>
A LogicalReplicationSlot that wraps the newly-created replication slot.
Remarks
See https://www.postgresql.org/docs/current/protocol-logical-replication.html and https://www.postgresql.org/docs/current/protocol-logicalrep-message-formats.html for more information.
StartReplication(LogicalReplicationConnection, PgOutputReplicationSlot, PgOutputReplicationOptions, CancellationToken, NpgsqlLogSequenceNumber?)
Instructs the server to start the Logical Streaming Replication Protocol (pgoutput logical decoding plugin),
starting at WAL location walLocation
or at the slot's consistent point if walLocation
isn't specified.
The server can reply with an error, for example if the requested section of the WAL has already been recycled.
public static IAsyncEnumerable<PgOutputReplicationMessage> StartReplication(this LogicalReplicationConnection connection, PgOutputReplicationSlot slot, PgOutputReplicationOptions options, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null)
Parameters
connection
LogicalReplicationConnectionThe LogicalReplicationConnection to use for starting replication
slot
PgOutputReplicationSlotThe replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby.
options
PgOutputReplicationOptionsThe collection of options passed to the slot's logical decoding plugin.
cancellationToken
CancellationTokenThe token to monitor for stopping the replication.
walLocation
NpgsqlLogSequenceNumber?The WAL location to begin streaming at.
Returns
- IAsyncEnumerable<PgOutputReplicationMessage>
A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of PgOutputReplicationMessage instances.