Documentation
¶
Overview ¶
Package utils holds generic utils about postgres instances
Index ¶
- func DBToFloat64(t interface{}) (float64, bool)
- func DBToString(t interface{}) (string, bool)
- func DBToUint64(t interface{}) (uint64, bool)
- func DisableSuperuserPassword(db *sql.DB) error
- func EnsureEncryptedPassword(p string) (string, error)
- func ExecWithSuppressedLogging(ctx context.Context, db *sql.DB, statement string) error
- func GetAllAccessibleDatabases(tx *sql.Tx, whereClause string) (databases []string, errors []error)
- func GetMajorVersionFromPgData(pgData string) (int, error)
- func GetPgVersion(db *sql.DB) (*semver.Version, error)
- func SetUserPassword(ctx context.Context, username string, password string, passthrough bool, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DBToFloat64 ¶
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 ¶
DBToString convert a dynamic type to string for Prometheus labels. Null types are mapped to empty strings.
func DBToUint64 ¶
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
DisableSuperuserPassword disables the password for the `postgres` user
func EnsureEncryptedPassword ¶
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
ExecWithSuppressedLogging executes a SQL statement within a transaction that suppresses PostgreSQL statement logging, preventing passwords from appearing in server logs.
func GetAllAccessibleDatabases ¶
GetAllAccessibleDatabases returns the list of all the accessible databases using the superuser
func GetMajorVersionFromPgData ¶ added in v1.26.0
GetMajorVersionFromPgData read the PG_VERSION file in the data directory returning the major version of the database
func GetPgVersion ¶
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.