pglogrepl

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pglogrepl provides Debezium-compatible change data capture (CDC) events from PostgreSQL write-ahead logs (WAL). It uses github.com/jackc/pglogrepl to read WAL, and then formats the changes into standardized CDC messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stream

func Stream(ctx context.Context, conn *pgconn.PgConn, cfg *Config) (<-chan cdc.Event, error)

Stream starts logical replication and returns a channel of CDC events.

Types

type Config

type Config struct {
	Publication string `json:"publication"`
	Slot        string `json:"slot"`
	Plugin      string `json:"plugin"`
	// Tables to add to publication. Example:
	// ["table_wo_schema", "specific_schema.example_table", "another_schema.*"]
	// ["*"] or ["*.*"] for all tables in all schemas
	Tables                []string      `json:"tables"`
	Ops                   []Op          `json:"ops"`
	PartitionRoot         bool          `json:"partitionRoot"`
	StandbyUpdateInterval time.Duration `json:"standbyUpdateInterval"`
	// ReplicaIdentity configures how much old row data is captured for each table.
	// not functional yet. manually execute sql to alter DEFAULT (streams primary key columns)
	ReplicaIdentity map[string]ReplicaIdentity `json:"relreplident"`
	BufferSize      int                        `json:"bufferSize"`
}

Config holds replication configuration.

func DefaultConfig

func DefaultConfig() *Config

type Op

type Op string

Op represents a type of database operation to be replicated.

const (
	OpInsert   Op = "insert"
	OpUpdate   Op = "update"
	OpDelete   Op = "delete"
	OpTruncate Op = "truncate"
)

type ReplicaIdentity

type ReplicaIdentity string

ReplicaIdentity specifies what row data Postgres streams during UPDATE/DELETE operations:

  • Default (d): streams primary key columns
  • None (n): streams no old row data
  • Full (f): streams all columns
  • Index (i): streams columns in specified index

Set with: ALTER TABLE table_name REPLICA IDENTITY [DEFAULT|NOTHING|FULL|USING INDEX name]

Query with: SELECT relreplident FROM pg_class WHERE oid = 'schema.table'::regclass;

const (
	// ReplicaIdentityDefault streams only primary key columns
	ReplicaIdentityDefault ReplicaIdentity = "d"

	// ReplicaIdentityNothing streams no old row data
	ReplicaIdentityNothing ReplicaIdentity = "n"

	// ReplicaIdentityFull streams all columns of old rows
	ReplicaIdentityFull ReplicaIdentity = "f"

	// ReplicaIdentityIndex streams columns from a specified unique index
	ReplicaIdentityIndex ReplicaIdentity = "i"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL