utils

package
v1.30.0-rc1 Latest Latest
Warning

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

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

Documentation

Overview

Package utils holds generic utils about postgres instances

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBToFloat64

func DBToFloat64(t interface{}) (float64, bool)

DBToFloat64 convert a dynamic value to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte types are mapped as NaN and !ok

func DBToString

func DBToString(t interface{}) (string, bool)

DBToString convert a dynamic type to string for Prometheus labels. Null types are mapped to empty strings.

func DBToUint64

func DBToUint64(t interface{}) (uint64, bool)

DBToUint64 convert a dynamic type to uint64 for Prometheus consumption. Null types are mapped to 0. string and []byte types are mapped as 0 and !ok

func DisableSuperuserPassword added in v1.18.5

func DisableSuperuserPassword(db *sql.DB) error

DisableSuperuserPassword disables the password for the `postgres` user

func EnsureEncryptedPassword

func EnsureEncryptedPassword(p string) (string, error)

EnsureEncryptedPassword returns p unchanged if PostgreSQL would recognize it as already encrypted; otherwise it SCRAM-SHA-256 encodes it using PostgreSQL's default parameters.

It is used before emitting "ALTER ROLE ... PASSWORD '...'" so the literal in the statement is never cleartext.

func ExecWithSuppressedLogging added in v1.27.4

func ExecWithSuppressedLogging(ctx context.Context, db *sql.DB, statement string) error

ExecWithSuppressedLogging executes a SQL statement within a transaction that suppresses PostgreSQL statement logging, preventing passwords from appearing in server logs.

func GetAllAccessibleDatabases

func GetAllAccessibleDatabases(tx *sql.Tx, whereClause string) (databases []string, errors []error)

GetAllAccessibleDatabases returns the list of all the accessible databases using the superuser

func GetMajorVersionFromPgData added in v1.26.0

func GetMajorVersionFromPgData(pgData string) (int, error)

GetMajorVersionFromPgData read the PG_VERSION file in the data directory returning the major version of the database

func GetPgVersion

func GetPgVersion(db *sql.DB) (*semver.Version, error)

GetPgVersion returns the version of postgres in a semantic format or an error

func SetUserPassword added in v1.18.5

func SetUserPassword(
	ctx context.Context,
	username string,
	password string,
	passthrough bool,
	db *sql.DB,
) error

SetUserPassword changes the password of a user in the PostgreSQL database. Cleartext passwords are SCRAM-SHA-256 encoded before being sent so the literal in the ALTER ROLE statement is never cleartext, unless passthrough is true, in which case the value is forwarded verbatim and PostgreSQL encodes it according to its own password_encryption setting.

Types

This section is empty.

Jump to

Keyboard shortcuts

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