db

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db provides database connection and management for PostgreSQL nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBManager

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

DBManager manages database connections to multiple PostgreSQL nodes.

func NewDBManager

func NewDBManager(nodes []schema.Node) *DBManager

NewDBManager creates a new DBManager with the given nodes.

func (*DBManager) ApplySchema

func (m *DBManager) ApplySchema(ctx context.Context, node *schema.Node, schemaSQL string) error

ApplySchema applies SQL schema to a node within a transaction. It also configures the pgconverge.node_name GUC so HLC triggers know which node they are running on.

func (*DBManager) ApplySchemaFromFile

func (m *DBManager) ApplySchemaFromFile(ctx context.Context, node *schema.Node, filePath string) error

ApplySchemaFromFile applies schema from a file to a node.

func (*DBManager) ApplySchemaFromFileToAll

func (m *DBManager) ApplySchemaFromFileToAll(ctx context.Context, filePath string) map[string]error

ApplySchemaFromFileToAll applies schema from a file to all nodes.

func (*DBManager) ApplySchemaToAll

func (m *DBManager) ApplySchemaToAll(ctx context.Context, schemaSQL string) map[string]error

ApplySchemaToAll applies SQL schema to all nodes.

func (*DBManager) CheckReplicationHealth

func (m *DBManager) CheckReplicationHealth(ctx context.Context) (healthy bool, issues []string)

CheckReplicationHealth checks the health of replication across all nodes.

func (*DBManager) Close

func (m *DBManager) Close()

Close closes all connection pools.

func (*DBManager) Connect

func (m *DBManager) Connect(ctx context.Context, node *schema.Node) (*pgxpool.Pool, error)

Connect establishes a connection to the specified node.

func (*DBManager) CreatePublication

func (m *DBManager) CreatePublication(ctx context.Context, node *schema.Node) error

CreatePublication creates a publication on a node.

func (*DBManager) CreateReplicationSlot

func (m *DBManager) CreateReplicationSlot(ctx context.Context, publisherNode *schema.Node, slotName string) error

CreateReplicationSlot creates a replication slot on a publisher node.

func (*DBManager) CreateSubscription

func (m *DBManager) CreateSubscription(ctx context.Context, subscriberNode, publisherNode *schema.Node) error

CreateSubscription creates a subscription from subscriber to publisher.

func (*DBManager) GetAllNodeStatuses

func (m *DBManager) GetAllNodeStatuses(ctx context.Context) []NodeStatus

GetAllNodeStatuses returns the status of all nodes.

func (*DBManager) GetNode

func (m *DBManager) GetNode(name string) *schema.Node

GetNode returns a node by name, or nil if not found.

func (*DBManager) GetNodeStatus

func (m *DBManager) GetNodeStatus(ctx context.Context, node *schema.Node) NodeStatus

GetNodeStatus returns the status of a specific node.

func (*DBManager) GetNodes

func (m *DBManager) GetNodes() []schema.Node

GetNodes returns all configured nodes.

func (*DBManager) GetPool

func (m *DBManager) GetPool(ctx context.Context, nodeName string) (*pgxpool.Pool, error)

GetPool returns a connection pool for the specified node.

func (*DBManager) Ping

func (m *DBManager) Ping(ctx context.Context, nodeName string) error

Ping tests connectivity to a node.

func (*DBManager) SetupBidirectionalReplication

func (m *DBManager) SetupBidirectionalReplication(ctx context.Context) []ReplicationResult

SetupBidirectionalReplication sets up bidirectional replication between all nodes.

func (*DBManager) SetupReplicationForNode

func (m *DBManager) SetupReplicationForNode(ctx context.Context, nodeName string) []ReplicationResult

SetupReplicationForNode sets up replication for a specific node.

type NodeStatus

type NodeStatus struct {
	Name             string
	Host             string
	Port             int
	External         bool
	Reachable        bool
	Error            error
	Warnings         []string
	Version          string
	WalLevel         string
	Publications     []PublicationInfo
	Subscriptions    []SubscriptionInfo
	ReplicationSlots []ReplicationSlotInfo
}

NodeStatus represents the status of a PostgreSQL node.

type PublicationInfo

type PublicationInfo struct {
	Name      string
	AllTables bool
}

PublicationInfo represents a PostgreSQL publication.

type ReplicationResult

type ReplicationResult struct {
	NodeName string
	Success  bool
	Message  string
	Error    error
}

ReplicationResult represents the result of a replication operation.

type ReplicationSlotInfo

type ReplicationSlotInfo struct {
	Name     string
	SlotType string
	Active   bool
}

ReplicationSlotInfo represents a PostgreSQL replication slot.

type SubscriptionInfo

type SubscriptionInfo struct {
	Name     string
	Enabled  bool
	SlotName string
}

SubscriptionInfo represents a PostgreSQL subscription.

Jump to

Keyboard shortcuts

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