walreader

package module
v0.0.0-...-dd2c874 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Replication slot lag

SELECT
    slot_name,
    active,
    pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)) AS replication_slot_lag
FROM
    pg_replication_slots

Documentation

Index

Constants

View Source
const (
	Namespace = "walreader"
)

Variables

View Source
var (
	ErrUnknownRelation = errors.New("unknown relation")
	ErrSlotInUse       = errors.New("replication slot in use")
	ErrSlotIsNotExists = errors.New("slot is not exists")
)

Functions

func GetCollectors

func GetCollectors() []prometheus.Collector

Types

type CallbackFn

type CallbackFn func(ctx context.Context, events []*Event) error

type Event

type Event struct {
	ServerTime time.Time      `json:"server_time"`
	Values     map[string]any `json:"values"`
	OldValues  map[string]any `json:"old_values"`
	Type       EventType      `json:"type"`
	Schema     string         `json:"namespace"`
	Table      string         `json:"table"`
	// contains filtered or unexported fields
}

type EventType

type EventType string
const (
	Insert   EventType = "insert"
	Update   EventType = "update"
	Delete   EventType = "delete"
	Truncate EventType = "truncate"
)

func (EventType) String

func (e EventType) String() string

type Info

type Info struct {
	Name              string        `json:"name"`
	WalStatus         string        `json:"walStatus"`
	RestartLSN        pglogrepl.LSN `json:"restartLSN"`
	ConfirmedFlushLSN pglogrepl.LSN `json:"confirmedFlushLSN"`
	CurrentLSN        pglogrepl.LSN `json:"currentLSN"`
	RetainedWALSize   pglogrepl.LSN `json:"retainedWALSize"`
	Lag               pglogrepl.LSN `json:"lag"`
	ActivePID         *int32        `json:"activePID"`
	Active            bool          `json:"active"`
}

type WALReader

type WALReader struct {
	// contains filtered or unexported fields
}

func New

func New(
	conn, helperConn *pgx.Conn,
	publicationName, slotName string,
) (*WALReader, error)

func (*WALReader) AckWait

func (c *WALReader) AckWait() uint64

AckWait return count of pending acknowledgement. Used for tests only.

func (*WALReader) Close

func (c *WALReader) Close(ctx context.Context) error

Close all connections and stop main loop

func (*WALReader) Ready

func (c *WALReader) Ready() chan struct{}

Ready wait for walreader start replication

func (*WALReader) Start

func (c *WALReader) Start(
	ctx context.Context,
	size int,
	timeout time.Duration,
	fn CallbackFn,
) error

Start replication

Directories

Path Synopsis
example
postgresql command
simple command

Jump to

Keyboard shortcuts

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