Class PgOutputConnectionExtensions
Extension methods to use LogicalReplicationConnection with the pg_output logical decoding plugin.
Inherited Members
Namespace: Npgsql.Replication
Assembly: Npgsql.dll
Syntax
public static class PgOutputConnectionExtensions
Methods
CreatePgOutputReplicationSlot(LogicalReplicationConnection, String, Boolean, Nullable<LogicalSlotSnapshotInitMode>, 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.
Declaration
public static async Task<PgOutputReplicationSlot> CreatePgOutputReplicationSlot(this LogicalReplicationConnection connection, string slotName, bool temporarySlot = false, LogicalSlotSnapshotInitMode? slotSnapshotInitMode = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
LogicalReplicationConnection | connection | The LogicalReplicationConnection to use for creating the replication slot |
String | slotName | The 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). |
Boolean | temporarySlot | true 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. |
Nullable<LogicalSlotSnapshotInitMode> | slotSnapshotInitMode | 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. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
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, Nullable<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.
Declaration
public static IAsyncEnumerable<PgOutputReplicationMessage> StartReplication(this LogicalReplicationConnection connection, PgOutputReplicationSlot slot, PgOutputReplicationOptions options, CancellationToken cancellationToken, NpgsqlLogSequenceNumber? walLocation = null)
Parameters
Type | Name | Description |
---|---|---|
LogicalReplicationConnection | connection | The LogicalReplicationConnection to use for starting replication |
PgOutputReplicationSlot | slot | The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby. |
PgOutputReplicationOptions | options | The collection of options passed to the slot's logical decoding plugin. |
CancellationToken | cancellationToken | The token to monitor for stopping the replication. |
Nullable<NpgsqlLogSequenceNumber> | walLocation | The WAL location to begin streaming at. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<PgOutputReplicationMessage> | A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of PgOutputReplicationMessage instances. |