postgres

package
v0.0.0-...-1d3b984 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package postgres provides the shared PostgreSQL driver implementation. Individual PostgreSQL-based backends (paradedb, postgres) import this package and register themselves separately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(connString string) (backends.Driver, error)

New creates a new PostgreSQL driver.

Types

type ConfigQuery

type ConfigQuery struct {
	Key   string // Config map key for single-column results (e.g., "paradedb_version")
	Query string // SQL to execute (e.g., "SELECT paradedb.version_info()::text")
}

ConfigQuery is a custom SQL query whose result is captured during CaptureConfig. A query returning a single text column stores its first row under Key. A query returning two text columns is treated as (name, value) rows; each name is grouped into a config section by its dot-prefix, the same way GUCs are (e.g., "paradedb.segments_at_run_start.idx" lands in the "paradedb" section).

type Driver

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

Driver implements the backends.Driver interface for PostgreSQL.

func (*Driver) AddTelemetryQueries

func (d *Driver) AddTelemetryQueries(queries ...TelemetryQuery)

func (*Driver) CaptureConfig

func (d *Driver) CaptureConfig(ctx context.Context, backendName string)

CaptureConfig captures database configuration and registers it with metrics.

func (*Driver) Close

func (d *Driver) Close() error

Close closes the connection pool.

func (*Driver) Exec

func (d *Driver) Exec(ctx context.Context, statements string) error

Exec executes SQL statements separated by semicolons.

func (*Driver) Insert

func (d *Driver) Insert(ctx context.Context, table string, cols []string, rows [][]any) (int, error)

Insert bulk inserts rows using COPY.

func (*Driver) Pool

func (d *Driver) Pool() *pgxpool.Pool

Pool returns the underlying connection pool for custom queries.

func (*Driver) Query

func (d *Driver) Query(ctx context.Context, query string, args ...any) (int, error)

Query executes a query and returns the hit count.

func (*Driver) ReadTelemetry

func (d *Driver) ReadTelemetry(ctx context.Context) ([]metrics.TelemetryPoint, error)

ReadTelemetry executes every configured query. A failed optional PostgreSQL view does not discard series returned by the other queries.

func (*Driver) ReloadTypes

func (d *Driver) ReloadTypes(ctx context.Context) error

ReloadTypes re-establishes pooled connections so AfterConnect type registration sees extensions created after the pool first connected.

func (*Driver) SetExtraGUCPrefixes

func (d *Driver) SetExtraGUCPrefixes(prefixes []string)

SetExtraGUCPrefixes sets GUC prefixes to capture wholesale in CaptureConfig. Every pg_settings entry under "<prefix>." is captured into a section named after the prefix (e.g., "paradedb" -> all "paradedb.*" GUCs).

func (*Driver) SetExtraGUCs

func (d *Driver) SetExtraGUCs(gucs []string)

SetExtraGUCs sets additional GUCs to capture in CaptureConfig. GUCs are grouped by prefix (e.g., "paradedb.xxx" -> "paradedb" section).

func (*Driver) SetExtraQueries

func (d *Driver) SetExtraQueries(queries []ConfigQuery)

SetExtraQueries sets additional SQL queries to run during CaptureConfig. See ConfigQuery for the supported result shapes.

func (*Driver) SetExtraQueriesWithColumnNames

func (d *Driver) SetExtraQueriesWithColumnNames(queries []ConfigQuery)

SetExtraQueriesWithColumnNames opts into deriving empty query keys from SQL column names. SetExtraQueries retains its legacy empty-key behavior.

func (*Driver) SetTelemetryQueries

func (d *Driver) SetTelemetryQueries(queries ...TelemetryQuery)

func (*Driver) TelemetryEnabled

func (d *Driver) TelemetryEnabled() bool

func (*Driver) Update

func (d *Driver) Update(ctx context.Context, table string, keyCols []string, cols []string, rows [][]any) (int, error)

Update upserts rows using INSERT ... ON CONFLICT DO UPDATE. keyCols are the conflict target columns, cols is all columns (keys first, then values).

type TelemetryQuery

type TelemetryQuery struct {
	Name  string
	Kind  metrics.TelemetryKind
	Query string
	Args  []any
}

TelemetryQuery is the repeating counterpart to ConfigQuery. Its SQL returns (series text, value double precision, unit text, labels jsonb) rows.

func IndexIOTelemetryQueries

func IndexIOTelemetryQueries(accessMethods ...string) []TelemetryQuery

IndexIOTelemetryQueries reports block reads and buffer hits for indexes using the selected PostgreSQL access methods.

func StandardTelemetryQueries

func StandardTelemetryQueries() []TelemetryQuery

StandardTelemetryQueries returns PostgreSQL WAL, database, writer, I/O, and activity series. Version-specific views are separate so unsupported views are reported without suppressing the remaining telemetry.

Jump to

Keyboard shortcuts

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