Skip to main content
Version: 1.9.0

PostgresCdcTrigger

class PostgresCdcTrigger(
conn: PostgresCdcConn,
tables: QualifiedTablesSpec,
start_from: PostgresCdcStartFromSpec,
cdc_format: CdcFormat = CdcFormat(values_format='columns', flatten_values=True),
buffer_max_rows: int = 10000,
buffer_max_bytes: int | None = None,
buffer_max_secs: int = 60,
trigger_max_rows: int | None = None,
trigger_max_bytes: int | None = None,
trigger_max_secs: int = 60,
poll_interval_seconds: int = 1,
blocking_timeout_seconds: int = 1,
replication_slot: str | None = None,
publication_name: str | None = None,
slot_behavior: ReplicationSlotBehaviorSpec = 'reuse',
start: datetime | None = None,
end: datetime | None = None,
)

Bases: CdcTrigger

Categories: trigger

A CdcTrigger that captures changes from a PostgreSQL database using WAL logical replication.

This trigger connects to a PostgreSQL server, reads the write-ahead log via the wal2json output plugin for change data capture events (inserts, updates, deletes) on specified tables, and stages them.

Initialize a PostgresCdcTrigger instance.

Parameters

parameter
conn

The PostgreSQL CDC connection configuration.

parameter
tables

Qualified table names to track for changes.

parameter
start_from

The position to start reading changes from (LSN or relative position).

parameter
cdc_format

The output format specification for CDC data.

parameter
buffer_max_rows

Maximum rows in memory before flushing to the working directory.

parameter
buffer_max_bytes

Maximum bytes in memory before flushing to the working directory.

parameter
buffer_max_secs

Maximum seconds before flushing memory data to the working directory.

parameter
trigger_max_rows

Maximum total rows before staging from working directory to the stage location.

parameter
trigger_max_bytes

Maximum total bytes before staging from working directory to the stage location.

parameter
trigger_max_secs

Maximum seconds before staging from working directory to the stage location.

parameter
poll_interval_seconds

Interval in seconds between polling for new changes.

parameter
blocking_timeout_seconds

Timeout in seconds for blocking reads from the replication stream.

parameter
replication_slot

Optional name of the logical replication slot to use.

parameter
publication_name

Optional name of the PostgreSQL publication to subscribe to.

parameter
slot_behavior

Whether to create a new replication slot or reuse an existing one. Defaults to "reuse".

parameter
start

Optional datetime for the trigger to start working.

parameter
end

Optional datetime for the trigger to stop working.

Properties

property
blocking_timeout_secondsint

Timeout in seconds for blocking reads from the replication stream.

property
buffer_max_bytesint | None

Maximum bytes in memory before flushing to the working directory.

property
buffer_max_rowsint

Maximum rows in memory before flushing to the working directory.

property
buffer_max_secsint

Maximum seconds before flushing memory data to the working directory.

property
cdc_formatCdcFormat

Output format specification for CDC data.

property
connConn

CDC connection configuration.

property
enddatetime | None

property
outdict[int, str] | None

Mapping of table indices to qualified table names.

property
poll_interval_secondsint

Interval in seconds between polling for new changes.

property
publication_namestr | None

Name of the PostgreSQL publication to subscribe to.

property
replication_slotstr | None

Name of the logical replication slot.

property
slot_behaviorReplicationSlotBehaviorSpec

Whether to create a new replication slot or reuse an existing one.

property
startdatetime | None

property
start_fromPostgresCdcStartFromSpec | None

Position to start reading changes from.

property
tableslist[str] | None

Qualified table names being tracked for changes.

property
trigger_max_bytesint | None

Maximum total bytes before staging from working directory to the stage location.

property
trigger_max_rowsint | None

Maximum total rows before staging from working directory to the stage location.

property
trigger_max_secsint

Maximum seconds before staging from working directory to the stage location.

Methods

collect_tables
def collect_tables(
session: Any,
cdc_format: CdcFormat = CdcFormat(values_format='columns', flatten_values=True),
) -> dict[str, TrackedTable]

harvest_tables
def harvest_tables(
session: Any,
cdc_format: CdcFormat = CdcFormat(values_format='columns', flatten_values=True),
) -> dict[str, TrackedTable]