postgres

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LongQueryCount added in v0.6.4

func LongQueryCount(ctx context.Context, pool *pgxpool.Pool, minSeconds int) (int, error)

LongQueryCount returns backends in state 'active' whose current query has been running longer than minSeconds (based on query_start). Excludes this session (pg_backend_pid).

func MaxConnections

func MaxConnections(ctx context.Context, pool *pgxpool.Pool) (int, error)

MaxConnections returns the server's max_connections setting.

func Pool

func Pool(ctx context.Context, dsn string) (*pgxpool.Pool, error)

Pool creates a connection pool for the given DSN.

func StaleCount

func StaleCount(ctx context.Context, pool *pgxpool.Pool, maxAgeSeconds int) (int, error)

StaleCount returns the number of connections that have been open longer than maxAgeSeconds (based on backend_start). Use this to detect connections that stay open and never close.

Types

type ConnectionStats

type ConnectionStats struct {
	Total  int
	Active int
	Idle   int
}

ConnectionStats holds counts from pg_stat_activity.

func Stats

func Stats(ctx context.Context, pool *pgxpool.Pool) (ConnectionStats, error)

Stats returns connection counts (total, active, idle) from the database.

Jump to

Keyboard shortcuts

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