pgproxy

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pgproxy is a Postgres wire-protocol router. Clients connect with database=dbname@branch; the proxy reads the startup message, resolves the branch to its backend address, rewrites the database param back to the real dbname, replays the startup to the branch backend, and then relays bytes transparently in both directions (SCRAM auth flows untouched).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchResolver

type BranchResolver interface {
	ResolveBranch(name string) (addr string, err error)
}

BranchResolver maps a branch name to the "host:port" address of its Postgres instance. Implementations must only resolve branches that can accept connections.

type Proxy

type Proxy struct {
	Resolver BranchResolver
	// DialTimeout bounds the backend dial. Defaults to 5s.
	DialTimeout time.Duration
	// StartupTimeout bounds the entire startup phase (SSL/GSS negotiation +
	// StartupMessage). A client that connects and dribbles bytes — or sends
	// nothing — is dropped after this, freeing the goroutine+fd it pins.
	// Defaults to 10s; the deadline is cleared once relaying begins.
	StartupTimeout time.Duration
	// MaxConns caps the number of connections handled concurrently. When the
	// cap is reached, further accepts are refused fast (connection closed)
	// rather than queued unbounded. Defaults to 256.
	MaxConns int
	// IdleTimeout closes a relayed session that has seen no bytes in either
	// direction for this long, reclaiming abandoned-but-open connections.
	// Defaults to 15m.
	IdleTimeout time.Duration
	// TLSConfig, when set, makes the proxy answer SSLRequest with 'S' and
	// upgrade the client connection via a server-side TLS handshake before
	// the startup message. When nil (default) SSLRequest is answered 'N' and
	// the session stays plaintext. Backend dials are always plaintext
	// (branches are local/cluster-internal).
	TLSConfig *tls.Config
}

func New

func New(r BranchResolver) *Proxy

func (*Proxy) Serve

func (p *Proxy) Serve(ctx context.Context, lis net.Listener) error

Serve accepts connections until ctx is cancelled (which closes the listener) or Accept fails. Each connection is handled in its own goroutine.

type RegistryResolver

type RegistryResolver struct {
	Reg *registry.Registry
}

RegistryResolver adapts the registry: only ready branches resolve.

func (*RegistryResolver) ResolveBranch

func (r *RegistryResolver) ResolveBranch(name string) (string, error)

Jump to

Keyboard shortcuts

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