postgres

package
v1.25.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package postgres provides functions to handle postgres in cnpg clusters

Index

Constants

View Source
const (
	// PGLocalSocketDir is the directory containing the PostgreSQL local socket
	PGLocalSocketDir = "/controller/run"
	// AppUser for app user
	AppUser = "app"
	// PostgresUser for postgres user
	PostgresUser = "postgres"
	// AppDBName database name app
	AppDBName = "app"
	// PostgresDBName database name postgres
	PostgresDBName = "postgres"
	// TablespaceDefaultName is the default tablespace location
	TablespaceDefaultName = "pg_default"
)

Variables

This section is empty.

Functions

func BumpPostgresImageMajorVersion

func BumpPostgresImageMajorVersion(postgresImage string) (string, error)

BumpPostgresImageMajorVersion returns a postgresImage incrementing the major version of the argument (if available)

func CountReplicas

func CountReplicas(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	pod *corev1.Pod,
	retryTimeout int,
) (int, error)

CountReplicas counts the number of replicas attached to an instance

func GetCurrentTimestamp

func GetCurrentTimestamp(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace, clusterName string,
) (string, error)

GetCurrentTimestamp getting current time stamp from postgres server

func RunExecOverForward

func RunExecOverForward(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace,
	clusterName,
	dbname,
	secretSuffix,
	query string,
) (sql.Result, error)

RunExecOverForward runs Exec with a given query, returning the Result of the SQL command

func RunQueryRowOverForward

func RunQueryRowOverForward(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace,
	clusterName,
	dbname,
	secretSuffix,
	query string,
) (*sql.Row, error)

RunQueryRowOverForward runs QueryRow with a given query, returning the Row of the SQL command

Types

type PSQLForwardConnection

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

PSQLForwardConnection manages the creation of a port-forwarding to open a new database connection

func ForwardPSQLConnection

func ForwardPSQLConnection(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace,
	clusterName,
	dbname,
	secretSuffix string,
) (*PSQLForwardConnection, *sql.DB, error)

ForwardPSQLConnection simplifies the creation of forwarded connection to PostgreSQL cluster

func ForwardPSQLConnectionWithCreds

func ForwardPSQLConnectionWithCreds(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace,
	clusterName,
	dbname,
	userApp,
	passApp string,
) (*PSQLForwardConnection, *sql.DB, error)

ForwardPSQLConnectionWithCreds creates a forwarded connection to a PostgreSQL cluster using the given credentials

func ForwardPSQLServiceConnection

func ForwardPSQLServiceConnection(
	ctx context.Context,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	namespace,
	serviceName,
	dbname,
	userApp,
	passApp string,
) (*PSQLForwardConnection, *sql.DB, error)

ForwardPSQLServiceConnection creates a forwarded connection to a PostgreSQL service using the given credentials

func (*PSQLForwardConnection) Close

func (psqlc *PSQLForwardConnection) Close()

Close will stop the port-forwarding and exit

func (*PSQLForwardConnection) GetPooler

func (psqlc *PSQLForwardConnection) GetPooler() pool.Pooler

GetPooler returns the connection Pooler

Jump to

Keyboard shortcuts

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