logical

command module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 6 Imported by: 0

README

logical

golang GitHub release GitHub go.mod Go version Github report GitHub stars GitHub forks GitHub issues

logical is tool for synchronizing from PostgreSQL to custom handler through replication slot

Required

requires Go 1.24 or greater.

Postgresql 10.0+

Howto

Config
  1. change postgresql.conf
wal_level = 'logical';  # minimal, replica, or logical. postgres default replica, It determines how much information is written to the wal
max_replication_slots = 10; # max number of replication slots, The value should be greater than 1
  1. change pg_hba.conf
# Add a new line below `replication`, $ is a variable
host $dbname $user $address md5  # example: `host webstore itmeng 192.168.0.1/24 md5`
Install
go get github.com/atopx/logical
Example

example

package main

import (
	"context"
	"fmt"

	"github.com/atopx/logical/client"
	"github.com/atopx/logical/logger"
	"github.com/atopx/logical/model"
	"go.uber.org/zap"
)

type Consumer struct{}

func (h *Consumer) Deal(records []*model.Waldata) {
	for _, record := range records {
		// consumer data
		fmt.Println(record)
	}
}

func main() {
	err := logger.Setup(zap.InfoLevel.String())
	if err != nil {
		panic(err)
	}

	var handler Consumer

	c := client.New(&client.Config{
		Host:     "127.0.0.1",
		Port:     5432,
		User:     "postgres",
		Password: "postgres_logical",
		Database: "webstore",
		Table:    "book",
		Slot:     "book_cache_slot",
	}, &handler)

	logger.Info("start postgresql logical replication client")

	if err = c.Start(context.Background()); err != nil {
		logger.Panic(err.Error())
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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