Table of Contents

Class PhysicalReplicationConnection

Namespace
Npgsql.Replication
Assembly
Npgsql.dll

Represents a physical replication connection to a PostgreSQL server.

public sealed class PhysicalReplicationConnection : ReplicationConnection, IAsyncDisposable
Inheritance
PhysicalReplicationConnection
Implements
Inherited Members

Constructors

PhysicalReplicationConnection()

Initializes a new instance of PhysicalReplicationConnection.

public PhysicalReplicationConnection()

PhysicalReplicationConnection(string?)

Initializes a new instance of PhysicalReplicationConnection with the given connection string.

public PhysicalReplicationConnection(string? connectionString)

Parameters

connectionString string

The connection used to open the PostgreSQL database.

Methods

CreateReplicationSlot(string, bool, bool, CancellationToken)

Creates a PhysicalReplicationSlot that wraps a PostgreSQL physical replication slot and can be used to start physical streaming replication

public Task<PhysicalReplicationSlot> CreateReplicationSlot(string slotName, bool isTemporary = false, bool reserveWal = false, CancellationToken cancellationToken = default)

Parameters

slotName string

The name of the slot to create. Must be a valid replication slot name (see Section 26.2.6.1).

isTemporary bool

true if this replication slot shall be a temporary one; otherwise false. Temporary slots are not saved to disk and are automatically dropped on error or when the session has finished.

reserveWal bool

If this is set to true this physical replication slot reserves WAL immediately. Otherwise, WAL is only reserved upon connection from a streaming replication client.

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task<PhysicalReplicationSlot>

A Task<TResult> representing a PhysicalReplicationSlot that represents the newly-created replication slot.

ReadReplicationSlot(string, CancellationToken)

Read some information associated to a replication slot. This command is currently only supported for physical replication slots.

public Task<PhysicalReplicationSlot?> ReadReplicationSlot(string slotName, CancellationToken cancellationToken = default)

Parameters

slotName string

The name of the slot to read. Must be a valid replication slot name

cancellationToken CancellationToken

An optional token to cancel the asynchronous operation. The default value is None.

Returns

Task<PhysicalReplicationSlot>

A Task<TResult> representing a PhysicalReplicationSlot or null if the replication slot does not exist.

StartReplication(PhysicalReplicationSlot?, NpgsqlLogSequenceNumber, CancellationToken, uint)

Instructs the server to start streaming the WAL for physical replication, starting at WAL location walLocation. The server can reply with an error, for example if the requested section of the WAL has already been recycled.

public IAsyncEnumerable<XLogDataMessage> StartReplication(PhysicalReplicationSlot? slot, NpgsqlLogSequenceNumber walLocation, CancellationToken cancellationToken, uint timeline = 0)

Parameters

slot PhysicalReplicationSlot

The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby.

walLocation NpgsqlLogSequenceNumber

The WAL location to begin streaming at.

cancellationToken CancellationToken

The token to be used for stopping the replication.

timeline uint

Streaming starts on timeline tli.

Returns

IAsyncEnumerable<XLogDataMessage>

A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of XLogDataMessage instances.

Remarks

If the client requests a timeline that's not the latest but is part of the history of the server, the server will stream all the WAL on that timeline starting from the requested start point up to the point where the server switched to another timeline.

StartReplication(PhysicalReplicationSlot, CancellationToken)

Instructs the server to start streaming the WAL for physical replication, starting at the WAL location and timeline id specified in slot. The server can reply with an error, for example if the requested section of the WAL has already been recycled.

public IAsyncEnumerable<XLogDataMessage> StartReplication(PhysicalReplicationSlot slot, CancellationToken cancellationToken)

Parameters

slot PhysicalReplicationSlot

The replication slot that will be updated as replication progresses so that the server knows which WAL segments are still needed by the standby. The slot must contain a valid RestartLsn to be used for this overload.

cancellationToken CancellationToken

The token to be used for stopping the replication.

Returns

IAsyncEnumerable<XLogDataMessage>

A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of XLogDataMessage instances.

Remarks

If the client requests a timeline that's not the latest but is part of the history of the server, the server will stream all the WAL on that timeline starting from the requested start point up to the point where the server switched to another timeline.

StartReplication(NpgsqlLogSequenceNumber, CancellationToken, uint)

Instructs the server to start streaming the WAL for logical replication, starting at WAL location walLocation. The server can reply with an error, for example if the requested section of WAL has already been recycled.

public IAsyncEnumerable<XLogDataMessage> StartReplication(NpgsqlLogSequenceNumber walLocation, CancellationToken cancellationToken, uint timeline = 0)

Parameters

walLocation NpgsqlLogSequenceNumber

The WAL location to begin streaming at.

cancellationToken CancellationToken

The token to be used for stopping the replication.

timeline uint

Streaming starts on timeline tli.

Returns

IAsyncEnumerable<XLogDataMessage>

A Task<TResult> representing an IAsyncEnumerable<T> that can be used to stream WAL entries in form of XLogDataMessage instances.

Remarks

If the client requests a timeline that's not the latest but is part of the history of the server, the server will stream all the WAL on that timeline starting from the requested start point up to the point where the server switched to another timeline.