postgres

package
v5.1.2-bit Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package postgres is a collection of resources that interact with PostgreSQL or provide functionality that makes it easier for other resources to interact with PostgreSQL.

Index

Examples

Constants

View Source
const (

	// SocketDirectory is where to bind and connect to UNIX sockets.
	SocketDirectory = "/tmp/postgres"

	// ReplicationUser is the PostgreSQL role that will be created by Patroni
	// for streaming replication and for `pg_rewind`.
	ReplicationUser = "_crunchyrepl"
)

Variables

This section is empty.

Functions

func AdditionalConfigVolumeMount

func AdditionalConfigVolumeMount() corev1.VolumeMount

AdditionalConfigVolumeMount returns the name and mount path of the additional config files.

func ConfigDirectory

func ConfigDirectory(cluster *v1beta1.PostgresCluster) string

ConfigDirectory returns the absolute path to $PGDATA for cluster. - https://www.postgresql.org/docs/current/runtime-config-file-locations.html

func CreateDatabasesInPostgreSQL

func CreateDatabasesInPostgreSQL(
	ctx context.Context, exec Executor, databases []string,
) error

CreateDatabasesInPostgreSQL calls exec to create databases that do not exist in PostgreSQL.

func DataDirectory

func DataDirectory(cluster *v1beta1.PostgresCluster) string

DataDirectory returns the absolute path to the "data_directory" of cluster. - https://www.postgresql.org/docs/current/runtime-config-file-locations.html

func DataVolumeMount

func DataVolumeMount() corev1.VolumeMount

DataVolumeMount returns the name and mount path of the PostgreSQL data volume.

func DownwardAPIVolumeMount

func DownwardAPIVolumeMount() corev1.VolumeMount

DownwardAPIVolumeMount returns the name and mount path of the DownwardAPI volume.

func Environment

func Environment(cluster *v1beta1.PostgresCluster) []corev1.EnvVar

Environment returns the environment variables required to invoke PostgreSQL utilities.

func InstancePod

func InstancePod(ctx context.Context,
	inCluster *v1beta1.PostgresCluster,
	inInstanceSpec *v1beta1.PostgresInstanceSetSpec,
	inClusterCertificates, inClientCertificates *corev1.SecretProjection,
	inDataVolume, inWALVolume *corev1.PersistentVolumeClaim,
	outInstancePod *corev1.PodSpec,
)

InstancePod initializes outInstancePod with the database container and the volumes needed by PostgreSQL.

func PodSecurityContext

func PodSecurityContext(cluster *v1beta1.PostgresCluster) *corev1.PodSecurityContext

PodSecurityContext returns a v1.PodSecurityContext for cluster that can write to PersistentVolumes.

func WALDirectory

func WALDirectory(
	cluster *v1beta1.PostgresCluster, instance *v1beta1.PostgresInstanceSetSpec,
) string

WALDirectory returns the absolute path to the directory where an instance stores its WAL files. - https://www.postgresql.org/docs/current/wal.html

func WALVolumeMount

func WALVolumeMount() corev1.VolumeMount

WALVolumeMount returns the name and mount path of the PostgreSQL WAL volume.

func WriteUsersInPostgreSQL

func WriteUsersInPostgreSQL(
	ctx context.Context, exec Executor,
	users []v1beta1.PostgresUserSpec, verifiers map[string]string,
) error

WriteUsersInPostgreSQL calls exec to create users that do not exist in PostgreSQL. Once they exist, it updates their options and passwords and grants them access to their specified databases. The databases must already exist.

Types

type Executor

type Executor func(
	ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error

Executor provides methods for calling "psql".

Example (ExecCmd)

This example demonstrates how Executor can work with exec.Cmd.

_ = Executor(func(
	ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
	// #nosec G204 Nothing calls the function defined in this example.
	cmd := exec.CommandContext(ctx, command[0], command[1:]...)
	cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr
	return cmd.Run()
})
Output:

func (Executor) Exec

func (exec Executor) Exec(
	ctx context.Context, sql io.Reader, variables map[string]string,
) (string, string, error)

Exec uses "psql" to execute sql. The sql statement(s) are passed via stdin and may contain psql variables that are assigned from the variables map. - https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES

func (Executor) ExecInAllDatabases

func (exec Executor) ExecInAllDatabases(
	ctx context.Context, sql string, variables map[string]string,
) (string, string, error)

ExecInAllDatabases uses "bash" and "psql" to execute sql in every database that allows connections, including templates. The sql command(s) may contain psql variables that are assigned from the variables map. - https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES

func (Executor) ExecInDatabasesFromQuery

func (exec Executor) ExecInDatabasesFromQuery(
	ctx context.Context, databases, sql string, variables map[string]string,
) (string, string, error)

ExecInDatabasesFromQuery uses "bash" and "psql" to execute sql in every database returned by the databases query. The sql statement(s) may contain psql variables that are assigned from the variables map. - https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES

type HBAs

type HBAs struct{ Mandatory, Default []HostBasedAuthentication }

HBAs is a pairing of HostBasedAuthentication records.

func NewHBAs

func NewHBAs() HBAs

NewHBAs returns HostBasedAuthentication records required by this package.

type HostBasedAuthentication

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

HostBasedAuthentication represents a single record for pg_hba.conf. - https://www.postgresql.org/docs/current/auth-pg-hba-conf.html

func NewHBA

func NewHBA() *HostBasedAuthentication

NewHBA returns an HBA record that matches all databases, networks, and users.

func (*HostBasedAuthentication) AllDatabases

func (hba *HostBasedAuthentication) AllDatabases() *HostBasedAuthentication

AllDatabases makes hba match connections made to any database.

func (*HostBasedAuthentication) AllNetworks

AllNetworks makes hba match connection attempts made from any IP address.

func (*HostBasedAuthentication) AllUsers

AllUsers makes hba match connections made by any user.

func (*HostBasedAuthentication) Database

Database makes hba match connections made to a specific database.

func (*HostBasedAuthentication) Local

Local makes hba match connection attempts using Unix-domain sockets.

func (*HostBasedAuthentication) Method

Method specifies the authentication method to use when a connection matches hba.

func (*HostBasedAuthentication) Network

Network makes hba match connection attempts from a block of IP addresses in CIDR notation.

func (*HostBasedAuthentication) NoSSL

NoSSL makes hba match connection attempts made over TCP/IP without SSL.

func (*HostBasedAuthentication) Options

Options specifies any options for the authentication method.

func (*HostBasedAuthentication) Replication

Replication makes hba match physical replication connections.

func (*HostBasedAuthentication) Role

Role makes hba match connections by users that are members of a specific role.

func (*HostBasedAuthentication) SameNetwork

SameNetwork makes hba match connection attempts from IP addresses in any subnet to which the server is directly connected.

func (HostBasedAuthentication) String

func (hba HostBasedAuthentication) String() string

String returns hba formatted for the pg_hba.conf file without a newline.

func (*HostBasedAuthentication) TCP

TCP makes hba match connection attempts made using TCP/IP, with or without SSL.

func (*HostBasedAuthentication) TLS

TLS makes hba match connection attempts made using TCP/IP with TLS.

func (*HostBasedAuthentication) User

User makes hba match connections by a specific user.

type ParameterSet

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

ParameterSet is a collection of PostgreSQL parameters. - https://www.postgresql.org/docs/current/config-setting.html

func NewParameterSet

func NewParameterSet() *ParameterSet

NewParameterSet returns an empty ParameterSet.

func (*ParameterSet) Add

func (ps *ParameterSet) Add(name, value string)

Add sets parameter name to value.

func (ParameterSet) AsMap

func (ps ParameterSet) AsMap() map[string]string

AsMap returns a copy of ps as a map.

func (*ParameterSet) DeepCopy

func (ps *ParameterSet) DeepCopy() (out *ParameterSet)

DeepCopy returns a copy of ps.

func (ParameterSet) Get

func (ps ParameterSet) Get(name string) (string, bool)

Get returns the value of parameter name and whether or not it was present in ps.

func (ParameterSet) Has

func (ps ParameterSet) Has(name string) bool

Has returns whether or not parameter name is present in ps.

func (ParameterSet) Value

func (ps ParameterSet) Value(name string) string

Value returns empty string or the value of parameter name if it is present in ps.

type Parameters

type Parameters struct{ Mandatory, Default *ParameterSet }

Parameters is a pairing of ParameterSets.

func NewParameters

func NewParameters() Parameters

NewParameters returns ParameterSets required by this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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