db

package module
v0.0.0-...-d45acdb Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: AGPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(opts Opts) string

DSN constructs a postgres-compatible connection URI.

Types

type Client

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

Client to PostgreSQL server.

func New

func New(ctx context.Context, opts Opts) (*Client, error)

New instantiates and returns a new DB.

func (*Client) CheckConnection

func (c *Client) CheckConnection(ctx context.Context) error

CheckConnection acquires a connection from the pool and executes an empty sql statement over it.

func (*Client) Select

func (c *Client) Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error

Select executes a statement that fetches rows in a transaction.

func (*Client) SelectPgLocks

func (db *Client) SelectPgLocks(ctx context.Context) ([]*PgLock, error)

SelectPgLocks selects stats on locks held.

func (*Client) SelectPgStatActivity

func (db *Client) SelectPgStatActivity(ctx context.Context) ([]*PgStatActivity, error)

SelectPgStatActivity selects stats on user tables.

func (*Client) SelectPgStatUserTables

func (db *Client) SelectPgStatUserTables(ctx context.Context) ([]*PgStatUserTable, error)

SelectPgStatUserTables selects stats on user tables.

type Opts

type Opts struct {
	//
	Host            string `long:"postgres_host"     env:"POSTGRES_HOST"     default:"localhost" description:"Postgres host"`
	Port            int    `long:"postgres_port"     env:"POSTGRES_PORT"     default:"5432"     description:"Postgres port"`
	User            string `long:"postgres_user"     env:"POSTGRES_USER"     default:"postgres" description:"Postgres username"`
	Password        string `long:"postgres_password" env:"POSTGRES_PASSWORD" default:"postgres" description:"Postgres password"`
	Database        string `long:"postgres_database" env:"POSTGRES_DATABASE" default:"postgres" description:"Postgres database"`
	AuthMechanism   string `` /* 175-byte string literal not displayed */
	ApplicationName string `long:"application_name" env:"APP_NAME" required:"true"`
	// Connection parameters.
	ConnectTimeout       time.Duration `long:"connect_timeout" env:"CONNECT_TIMEOUT" default:"10s" description:"Postgres connection timeout"`
	MaxConnectionRetries int           `` /* 239-byte string literal not displayed */
	// Client connection optional parameters.
	DefaultIsolationLevel           string        `` /* 215-byte string literal not displayed */
	StatementTimeout                time.Duration `` /* 274-byte string literal not displayed */
	LockTimeout                     time.Duration `` /* 489-byte string literal not displayed */
	IdleInTransactionSessionTimeout time.Duration `` /* 446-byte string literal not displayed */
	// Transaction options.
	TotalTransactionTimeout      time.Duration `` /* 202-byte string literal not displayed */
	InitialTransactionRetryDelay time.Duration `` /* 180-byte string literal not displayed */
	BaseTransactionRetryDelay    time.Duration `` /* 166-byte string literal not displayed */
	MaxTransactionAttempts       int           `` /* 194-byte string literal not displayed */
	ReadOnly                     bool          `` /* 128-byte string literal not displayed */
	// pgxpool.ConnConfig
	PoolMaxConns          int           `long:"pool_max_conns" env:"MAX_CONNS" default:"10" description:"Max open connections to the database"`
	PoolMinConns          int           `long:"pool_min_conns" env:"MIN_CONNS" default:"2" description:"Min open connections to the database"`
	PoolMaxConnLifetime   time.Duration `` /* 152-byte string literal not displayed */
	PoolMaxConnIdleTime   time.Duration `` /* 156-byte string literal not displayed */
	PoolHealthCheckPeriod time.Duration `` /* 169-byte string literal not displayed */
	// pgx.ConnConfig
	StatementCacheCapacity int    `` /* 211-byte string literal not displayed */
	StatementCacheMode     string `` /* 459-byte string literal not displayed */
}

Opts specify the configuration for a postgres client.

type PgLock

type PgLock struct {
	DatName string `db:"datname"`
	Mode    string `db:"mode"`
	Count   int    `db:"count"`
}

PgLock contains information on locks held.

type PgStatActivity

type PgStatActivity struct {
	DatName       string  `db:"datname"`
	State         string  `db:"state"`
	Count         int     `db:"count"`
	MaxTxDuration float64 `db:"max_tx_duration"`
}

PgStatActivity contains information on tx state.

type PgStatUserTable

type PgStatUserTable struct {
	DatName          string             `db:"datname"`
	SchemaName       string             `db:"schemaname"`
	RelName          string             `db:"relname"`
	SeqScan          int                `db:"seq_scan"`
	SeqTupRead       int                `db:"seq_tup_read"`
	IndexScan        int                `db:"idx_scan"`
	IndexTupFetch    int                `db:"idx_tup_fetch"`
	NTupInsert       int                `db:"n_tup_ins"`
	NTupUpdate       int                `db:"n_tup_upd"`
	NTupDelete       int                `db:"n_tup_del"`
	NTupHotUpdate    int                `db:"n_tup_hot_upd"`
	NLiveTup         int                `db:"n_live_tup"`
	NDeadTup         int                `db:"n_dead_tup"`
	NModSinceAnalyze int                `db:"n_mod_since_analyze"`
	LastVacuum       pgtype.Timestamptz `db:"last_vacuum"`
	LastAutoVacuum   pgtype.Timestamptz `db:"last_autovacuum"`
	LastAnalyze      pgtype.Timestamptz `db:"last_analyze"`
	LastAutoAnalyze  pgtype.Timestamptz `db:"last_autoanalyze"`
	VacuumCount      int                `db:"vacuum_count"`
	AutoVacuumCount  int                `db:"autovacuum_count"`
	AnalyzeCount     int                `db:"analyze_count"`
	AutoAnalyzeCount int                `db:"autoanalyze_count"`
}

PgStatUserTable contiains information on user tables.

Jump to

Keyboard shortcuts

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