postgres

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ActiveRecordTxnID represents the maximum XID8 value used for active records
	// to avoid XID wraparound issues (instead of using 0)
	ActiveRecordTxnID = uint64(9223372036854775807)
	MaxXID8Value      = "'9223372036854775807'::xid8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MockPQDatabase added in v0.3.8

type MockPQDatabase struct {
	mock.Mock
}

MockPQDatabase simulates the behavior of a real PQDatabase.

func (*MockPQDatabase) Close added in v0.3.8

func (m *MockPQDatabase) Close() error

func (*MockPQDatabase) GetEngineType added in v0.3.8

func (m *MockPQDatabase) GetEngineType() string

func (*MockPQDatabase) IsReady added in v0.3.8

func (m *MockPQDatabase) IsReady(ctx context.Context) (bool, error)

type Option

type Option func(*Postgres)

Option - Option type

func ConnectTimeout added in v1.5.2

func ConnectTimeout(d time.Duration) Option

ConnectTimeout - Defines the maximum time to wait when establishing a new connection

func HealthCheckPeriod added in v1.5.2

func HealthCheckPeriod(d time.Duration) Option

HealthCheckPeriod - Defines the period between health checks on idle connections

func MaxConnectionIdleTime added in v0.2.3

func MaxConnectionIdleTime(d time.Duration) Option

MaxConnectionIdleTime - Defines maximum connection idle for postgresql db

func MaxConnectionLifeTime added in v0.2.3

func MaxConnectionLifeTime(d time.Duration) Option

MaxConnectionLifeTime - Defines maximum connection lifetime for postgresql db

func MaxConnectionLifetimeJitter added in v1.5.2

func MaxConnectionLifetimeJitter(d time.Duration) Option

MaxConnectionLifetimeJitter - Defines the jitter added to MaxConnLifetime to prevent all connections from expiring at once

func MaxConnections added in v1.5.2

func MaxConnections(size int) Option

MaxConnections - Defines maximum number of connections in the pool (maps to pgxpool MaxConns)

func MaxDataPerWrite added in v0.7.9

func MaxDataPerWrite(v int) Option

func MaxIdleConnections added in v0.2.3

func MaxIdleConnections(c int) Option

MaxIdleConnections - Deprecated: use MinConnections instead. Kept for backward compatibility and only used as a fallback for MinConnections when MinConnections is not set (0). MinIdleConns is only honored when explicitly configured.

func MaxOpenConnections added in v0.2.0

func MaxOpenConnections(size int) Option

MaxOpenConnections - Deprecated: use MaxConnections instead for consistency with pgxpool. Kept for backward compatibility and internally forwards to MaxConnections.

func MaxRetries added in v0.7.9

func MaxRetries(v int) Option

func MinConnections added in v1.5.2

func MinConnections(c int) Option

MinConnections - Defines minimum number of connections in the pool If not set (0) and MaxIdleConnections is set, MaxIdleConnections will be used for backward compatibility (old behavior).

func MinIdleConnections added in v1.5.2

func MinIdleConnections(c int) Option

MinIdleConnections - Defines minimum number of idle connections in the pool. This is superior to MinConnections for ensuring idle connections are always available. Note: MaxIdleConnections only affects MinConnections when MinConnections is not set; it does not implicitly set MinIdleConnections.

func WatchBufferSize added in v0.7.9

func WatchBufferSize(v int) Option

type Postgres

type Postgres struct {
	ReadPool  *pgxpool.Pool
	WritePool *pgxpool.Pool

	Builder squirrel.StatementBuilderType
	// contains filtered or unexported fields
}

Postgres - Structure for Postresql instance

func New

func New(uri string, opts ...Option) (*Postgres, error)

New -

func NewWithSeparateURIs added in v0.8.5

func NewWithSeparateURIs(writerUri, readerUri string, opts ...Option) (*Postgres, error)

NewWithSeparateURIs -

func (*Postgres) Close

func (p *Postgres) Close() error

Close - Close postgresql instance

func (*Postgres) GetEngineType

func (p *Postgres) GetEngineType() string

GetEngineType - Get the engine type which is postgresql in string

func (*Postgres) GetMaxDataPerWrite added in v0.7.9

func (p *Postgres) GetMaxDataPerWrite() int

func (*Postgres) GetMaxRetries added in v0.7.9

func (p *Postgres) GetMaxRetries() int

func (*Postgres) GetWatchBufferSize added in v0.7.9

func (p *Postgres) GetWatchBufferSize() int

func (*Postgres) IsReady

func (p *Postgres) IsReady(ctx context.Context) (bool, error)

IsReady - Check if database is ready

func (*Postgres) Repair added in v1.4.4

func (p *Postgres) Repair(ctx context.Context, config *RepairConfig) (*RepairResult, error)

Repair performs XID counter repair to prevent XID wraparound issues This function uses a safe approach: only advance XID counter, don't modify existing data

type RepairConfig added in v1.4.4

type RepairConfig struct {
	BatchSize  int  // batch size for XID advancement
	MaxRetries int  // maximum number of retries
	RetryDelay int  // milliseconds
	DryRun     bool // perform a dry run without making changes
	Verbose    bool // enable verbose logging
}

RepairConfig holds configuration for the XID counter repair operation

func DefaultRepairConfig added in v1.4.4

func DefaultRepairConfig() *RepairConfig

DefaultRepairConfig returns default configuration for XID counter repair

type RepairResult added in v1.4.4

type RepairResult struct {
	CreatedTxIdFixed int // Number of XIDs advanced in counter
	Errors           []error
	Duration         string
}

RepairResult holds the results of the XID counter repair operation

type XID8 added in v1.4.4

type XID8 pguint64

XID8 represents a PostgreSQL xid8 (64-bit transaction ID) type

func (*XID8) AssignTo added in v1.4.4

func (x *XID8) AssignTo(dst interface{}) error

AssignTo assigns the value to the destination

func (*XID8) DecodeBinary added in v1.4.4

func (x *XID8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

DecodeBinary decodes binary format

func (*XID8) DecodeText added in v1.4.4

func (x *XID8) DecodeText(ci *pgtype.ConnInfo, src []byte) error

DecodeText decodes text format

func (XID8) EncodeBinary added in v1.4.4

func (x XID8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

EncodeBinary encodes to binary format

func (XID8) EncodeText added in v1.4.4

func (x XID8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

EncodeText encodes to text format

func (XID8) Get added in v1.4.4

func (x XID8) Get() interface{}

Get returns the underlying value

func (*XID8) Scan added in v1.4.4

func (x *XID8) Scan(src interface{}) error

Scan implements the database/sql Scanner interface

func (*XID8) Set added in v1.4.4

func (x *XID8) Set(src interface{}) error

Set sets the XID8 value from various input types

func (XID8) Value added in v1.4.4

func (x XID8) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface

Jump to

Keyboard shortcuts

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