Documentation
¶
Overview ¶
Package postgres contains the function about starting up, shutting down and managing a PostgreSQL instance. These functions are primarily used by the instance manager
Index ¶
- Constants
- Variables
- func ClonePgData(ctx context.Context, connectionString, targetPgData, walDir string) error
- func GetReadyWALFiles() (fileNames []string, err error)
- func GetServerPort() int
- func GetSocketDir() string
- func GetWALArchiveCounters() (ready, done int, err error)
- func InstallPgDataFileContent(ctx context.Context, pgdata, contents, destinationFile string) (bool, error)
- func LoadEnforcedParametersFromCluster(cluster *apiv1.Cluster) (map[string]int, error)
- func LoadEnforcedParametersFromPgControldata(pgData string) (map[string]int, error)
- func PatchBackupStatusAndRetry(ctx context.Context, cli client.Client, backup *apiv1.Backup) error
- func PgIsReady() error
- func UpdateReplicaConfiguration(pgData, primaryConnInfo, slotName string) (changed bool, err error)
- type BackupCommand
- type InitInfo
- func (info InitInfo) Bootstrap(ctx context.Context) error
- func (info InitInfo) ConfigureInstanceAfterRestore(ctx context.Context, cluster *apiv1.Cluster, env []string) error
- func (info InitInfo) ConfigureNewInstance(instance *Instance) error
- func (info InitInfo) CreateDataDirectory() error
- func (info InitInfo) EnsureTargetDirectoriesDoNotExist(ctx context.Context) error
- func (info InitInfo) GetInstance() *Instance
- func (info InitInfo) GetPrimaryConnInfo() string
- func (info InitInfo) Join(ctx context.Context, cluster *apiv1.Cluster) error
- func (info InitInfo) Restore(ctx context.Context, cli client.Client) error
- func (info InitInfo) RestoreSnapshot(ctx context.Context, cli client.Client, immediate bool) error
- func (info InitInfo) WriteInitialPostgresqlConf(ctx context.Context, cluster *apiv1.Cluster) error
- func (info InitInfo) WriteRestoreHbaConf(ctx context.Context) error
- type Instance
- func (instance *Instance) CanCheckReadiness() bool
- func (instance *Instance) CheckForExistingPostmaster(postgresExecutables ...string) (*os.Process, error)
- func (instance *Instance) CheckHasDiskSpaceForWAL(ctx context.Context) (bool, error)
- func (instance *Instance) CleanUpStalePid() error
- func (instance *Instance) ConfigureSlotReplicator(config *apiv1.ReplicationSlotsConfiguration)
- func (instance *Instance) ConnectionPool() *pool.ConnectionPool
- func (instance *Instance) Demote(ctx context.Context, cluster *apiv1.Cluster) error
- func (instance *Instance) DropConnections() error
- func (instance *Instance) GeneratePostgresqlHBA(cluster *apiv1.Cluster, ldapBindPassword string) (string, error)
- func (instance *Instance) GetClusterName() string
- func (instance *Instance) GetDecreasedSensibleSettings(superUserDB *sql.DB) (map[string]int, error)
- func (instance *Instance) GetInstanceCommandChan() <-chan InstanceCommand
- func (instance *Instance) GetNamespaceName() string
- func (instance *Instance) GetPgControldata() (string, error)
- func (instance *Instance) GetPgVersion() (semver.Version, error)
- func (instance *Instance) GetPodName() string
- func (instance *Instance) GetPostmasterPidFromFile(pidFile string) ([]byte, int, error)
- func (instance *Instance) GetPrimaryConnInfo() string
- func (instance *Instance) GetStatus() (result *postgres.PostgresqlStatus, err error)
- func (instance *Instance) GetSuperUserDB() (*sql.DB, error)
- func (instance *Instance) GetTemplateDB() (*sql.DB, error)
- func (instance *Instance) HandleInstanceCommandRequests(ctx context.Context, req InstanceCommand) (restartNeeded bool, err error)
- func (instance *Instance) IsFenced() bool
- func (instance *Instance) IsPrimary() (bool, error)
- func (instance *Instance) IsServerHealthy() error
- func (instance *Instance) IsWALReceiverActive() (bool, error)
- func (instance *Instance) LogPgControldata(ctx context.Context, reason string)
- func (instance *Instance) MightBeUnavailable() bool
- func (instance *Instance) PrimaryConnectionPool() *pool.ConnectionPool
- func (instance *Instance) PromoteAndWait(ctx context.Context) error
- func (instance *Instance) RefreshConfigurationFilesFromCluster(ctx context.Context, cluster *apiv1.Cluster, preserveUserSettings bool) (bool, error)
- func (instance *Instance) RefreshPGHBA(ctx context.Context, cluster *apiv1.Cluster, ldapBindPassword string) (postgresHBAChanged bool, err error)
- func (instance *Instance) RefreshPGIdent(ctx context.Context, additionalLines []string) (postgresIdentChanged bool, err error)
- func (instance *Instance) RefreshReplicaConfiguration(ctx context.Context, cluster *apiv1.Cluster, cli client.Client) (changed bool, err error)
- func (instance *Instance) Reload(ctx context.Context) error
- func (instance *Instance) RequestAndWaitFencingOff(ctx context.Context, timeout time.Duration) error
- func (instance *Instance) RequestAndWaitRestartSmartFast(ctx context.Context, timeout time.Duration) error
- func (instance *Instance) RequestFastImmediateShutdown()
- func (instance *Instance) RequestFencingOn()
- func (instance *Instance) Rewind(ctx context.Context, postgresVersion version.Data) error
- func (instance *Instance) RoleSynchronizerChan() <-chan *apiv1.ManagedConfiguration
- func (instance *Instance) Run() (*execlog.StreamingCmd, error)
- func (instance *Instance) SetCanCheckReadiness(enabled bool)
- func (instance *Instance) SetFencing(enabled bool)
- func (instance *Instance) SetMightBeUnavailable(enabled bool)
- func (instance *Instance) SetPostgreSQLAutoConfWritable(writeable bool) error
- func (instance *Instance) Shutdown(ctx context.Context, options shutdownOptions) error
- func (instance *Instance) ShutdownConnections()
- func (instance *Instance) SlotReplicatorChan() <-chan *apiv1.ReplicationSlotsConfiguration
- func (instance *Instance) Startup() error
- func (instance *Instance) TablespaceSynchronizerChan() <-chan map[string]apiv1.TablespaceConfiguration
- func (instance *Instance) TriggerRoleSynchronizer(config *apiv1.ManagedConfiguration)
- func (instance *Instance) TriggerTablespaceSynchronizer(config map[string]apiv1.TablespaceConfiguration)
- func (instance *Instance) TryGetPgStatWAL() (*PgStatWal, error)
- func (instance *Instance) TryShuttingDownFastImmediate(ctx context.Context) error
- func (instance *Instance) TryShuttingDownSmartFast(ctx context.Context) error
- func (instance *Instance) VerifyPgDataCoherence(ctx context.Context) error
- func (instance *Instance) WaitForConfigReload(ctx context.Context) (*postgres.PostgresqlStatus, error)
- func (instance *Instance) WaitForPrimaryAvailable(ctx context.Context) error
- func (instance *Instance) WaitForSuperuserConnectionAvailable(ctx context.Context) error
- func (instance *Instance) WithActiveInstance(inner func() error) error
- func (instance *Instance) WithClusterName(clusterName string) *Instance
- func (instance *Instance) WithNamespace(namespace string) *Instance
- func (instance *Instance) WithPodName(podName string) *Instance
- type InstanceCommand
- type PgStatWal
Constants ¶
const PostgresqlPidFile = "postmaster.pid" //wokeignore:rule=master
PostgresqlPidFile is the name of the file which contains the PostgreSQL PID file
Variables ¶
var ( // ErrPgRejectingConnection postgres is alive, but rejecting connections ErrPgRejectingConnection = fmt.Errorf("server is alive but rejecting connections") // ErrNoConnectionEstablished postgres is alive, but rejecting connections ErrNoConnectionEstablished = fmt.Errorf("could not establish connection") )
var ( // ErrInstanceInRecovery is raised while PostgreSQL is still in recovery mode ErrInstanceInRecovery = fmt.Errorf("instance in recovery") // RetryUntilRecoveryDone is the default retry configuration that is used // to wait for a restored cluster to promote itself RetryUntilRecoveryDone = wait.Backoff{ Duration: 5 * time.Second, Steps: math.MaxInt32, } )
var RetryUntilServerAvailable = wait.Backoff{ Duration: 5 * time.Second, Steps: math.MaxInt32, }
RetryUntilServerAvailable is the default retry configuration that is used to wait for a successful connection to a certain server
Functions ¶
func ClonePgData ¶
ClonePgData clones an existing server, given its connection string, to a certain data directory
func GetReadyWALFiles ¶
GetReadyWALFiles returns an array containing the list of all the WAL files that are marked as ready to be archived.
func GetServerPort ¶
func GetServerPort() int
GetServerPort gets the port where the postmaster will be listening using the environment variable or, when empty, the default one
func GetSocketDir ¶
func GetSocketDir() string
GetSocketDir gets the name of the directory that will contain the Unix socket for the PostgreSQL server. This is detected using the PGHOST environment variable or using a default
func GetWALArchiveCounters ¶
GetWALArchiveCounters returns the number of WAL files with status ready, and the number of those in status done.
func InstallPgDataFileContent ¶
func InstallPgDataFileContent(ctx context.Context, pgdata, contents, destinationFile string) (bool, error)
InstallPgDataFileContent installs a file in PgData, returning true/false if the file has been changed and an error state
func LoadEnforcedParametersFromCluster ¶ added in v1.21.6
LoadEnforcedParametersFromCluster loads the enforced parameters which defined in cluster spec
func LoadEnforcedParametersFromPgControldata ¶ added in v1.21.6
LoadEnforcedParametersFromPgControldata will parse the output of pg_controldata in order to get the values of all the hot standby sensible parameters
func PatchBackupStatusAndRetry ¶ added in v1.18.3
func PatchBackupStatusAndRetry( ctx context.Context, cli client.Client, backup *apiv1.Backup, ) error
PatchBackupStatusAndRetry updates a certain backup's status in the k8s database, retries when error occurs TODO: this method does not belong here, it should be moved to api/v1/backup_types.go
func PgIsReady ¶ added in v1.16.4
func PgIsReady() error
PgIsReady gets the status from the pg_isready command
func UpdateReplicaConfiguration ¶
UpdateReplicaConfiguration updates the override.conf or recovery.conf file for the proper version of PostgreSQL, using the specified connection string to connect to the primary server
Types ¶
type BackupCommand ¶
type BackupCommand struct {
Cluster *apiv1.Cluster
Backup *apiv1.Backup
Client client.Client
Recorder record.EventRecorder
Env []string
Log log.Logger
Instance *Instance
Capabilities *barmanCapabilities.Capabilities
// contains filtered or unexported fields
}
BackupCommand represent a backup command that is being executed
func NewBarmanBackupCommand ¶ added in v1.23.0
func NewBarmanBackupCommand( cluster *apiv1.Cluster, backup *apiv1.Backup, client client.Client, recorder record.EventRecorder, instance *Instance, log log.Logger, ) (*BackupCommand, error)
NewBarmanBackupCommand initializes a BackupCommand object, taking a physical backup using Barman Cloud
type InitInfo ¶
type InitInfo struct {
// The data directory where to generate the new cluster
PgData string
// the data directory where to store the WAL
PgWal string
// The name of the database to be generated for the applications
ApplicationDatabase string
// The name of the role to be generated for the applications
ApplicationUser string
// The parent node, used to fill primary_conninfo
ParentNode string
// The current node, used to fill application_name
PodName string
// The cluster name to assign to
ClusterName string
// The namespace where the cluster will be installed
Namespace string
// The list options that should be passed to initdb to
// create the cluster
InitDBOptions []string
// The list of queries to be executed just after having
// configured a new instance
PostInitSQL []string
// The list of queries to be executed just after having
// the application database created
PostInitApplicationSQL []string
// The list of queries to be executed inside the template1
// database just after having configured a new instance
PostInitTemplateSQL []string
// Whether it is a temporary instance that will never contain real data.
Temporary bool
// PostInitApplicationSQLRefsFolder is the folder which contains a bunch
// of SQL files to be executed inside the application database right after
// having configured a new instance
PostInitApplicationSQLRefsFolder string
// PostInitSQLRefsFolder is the folder which contains a bunch of SQL files
// to be executed inside the `postgres` database right after having configured a new instance
PostInitSQLRefsFolder string
// PostInitTemplateSQLRefsFolder is the folder which contains a bunch of SQL files
// to be executed inside the `template1` database right after having configured a new instance
PostInitTemplateSQLRefsFolder string
// BackupLabelFile holds the content returned by pg_stop_backup. Needed for a hot backup restore
BackupLabelFile []byte
// TablespaceMapFile holds the content returned by pg_stop_backup. Needed for a hot backup restore
TablespaceMapFile []byte
}
InitInfo contains all the info needed to bootstrap a new PostgreSQL instance
func (InitInfo) ConfigureInstanceAfterRestore ¶
func (info InitInfo) ConfigureInstanceAfterRestore(ctx context.Context, cluster *apiv1.Cluster, env []string) error
ConfigureInstanceAfterRestore changes the superuser password of the instance to be coherent with the one specified in the cluster. This function also ensures that we can really connect to this cluster using the password in the secrets
func (InitInfo) ConfigureNewInstance ¶
ConfigureNewInstance creates the expected users and databases in a new PostgreSQL instance. If any error occurs, we return it
func (InitInfo) CreateDataDirectory ¶
CreateDataDirectory creates a new data directory given the configuration
func (InitInfo) EnsureTargetDirectoriesDoNotExist ¶ added in v1.23.6
EnsureTargetDirectoriesDoNotExist ensures that the target data and WAL directories do not exist. This is a safety check we do before initializing a new instance.
If the PGDATA directory already exists and contains a valid PostgreSQL control file, the function moves the contents to uniquely named directories. If no valid control file is found, the function assumes the directory is the result of a failed initialization attempt and removes it.
By moving rather than deleting the existing data, we use more disk space than necessary. However, this approach is justified for two reasons:
The PostgreSQL control file is the last file written by pg_basebackup. So the only chance to trigger this protection is if the "join" Pod is interrupted shortly after writing the control file but before the Pod terminates. This is a very short time window, and it is extremely unlikely that it happens.
If the PGDATA directory wasn't created by us, renaming preserves potentially important user data. This is particularly relevant when using static provisioning of PersistentVolumeClaims (PVCs), as it prevents accidental overwriting of a valid data directory that may exist in the PersistentVolumes (PVs).
func (InitInfo) GetInstance ¶
GetInstance gets the PostgreSQL instance which correspond to these init information
func (InitInfo) GetPrimaryConnInfo ¶ added in v1.18.0
GetPrimaryConnInfo returns the DSN to reach the primary
func (InitInfo) Restore ¶
Restore restores a PostgreSQL cluster from a backup into the object storage
func (InitInfo) RestoreSnapshot ¶ added in v1.20.3
RestoreSnapshot restores a PostgreSQL cluster from a volumeSnapshot
func (InitInfo) WriteInitialPostgresqlConf ¶
WriteInitialPostgresqlConf resets the postgresql.conf that there is in the instance using a new bootstrapped instance as reference
func (InitInfo) WriteRestoreHbaConf ¶
WriteRestoreHbaConf writes basic pg_hba.conf and pg_ident.conf allowing access without password from localhost. This is needed to set the PostgreSQL password after the postgres server is started and active
type Instance ¶
type Instance struct {
// The data directory
PgData string
// The socket directory
SocketDirectory string
// The environment variables that will be used to start the instance
Env []string
// Command line options to pass to the postgres process, see the
// '-c' option of pg_ctl for an useful example
StartupOptions []string
// The sha256 of the config. It is computed on the config string, before
// adding the PostgreSQL CNPGConfigSha256 parameter
ConfigSha256 string
// PgCtlTimeoutForPromotion specifies the maximum number of seconds to wait when waiting for promotion to complete
PgCtlTimeoutForPromotion int32
// specifies the maximum number of seconds to wait when shutting down for a switchover
MaxSwitchoverDelay int32
// InstanceManagerIsUpgrading tells if there is an instance manager upgrade in process
InstanceManagerIsUpgrading atomic.Bool
// PgRewindIsRunning tells if there is a `pg_rewind` process running
PgRewindIsRunning bool
// MaxStopDelay is the current MaxStopDelay of the cluster
MaxStopDelay int32
// SmartStopDelay is used to control PostgreSQL smart shutdown timeout
SmartStopDelay int32
// RequiresDesignatedPrimaryTransition indicates if this instance is a primary that needs to become
// a designatedPrimary
RequiresDesignatedPrimaryTransition bool
// StatusPortTLS enables TLS on the status port used to communicate with the operator
StatusPortTLS bool
// MetricsPortTLS enables TLS on the port used to publish metrics over HTTP/HTTPS
MetricsPortTLS bool
// ServerCertificate is the certificate we use to serve https connections
ServerCertificate *tls.Certificate
// contains filtered or unexported fields
}
Instance represent a PostgreSQL instance to be executed in the current environment
func NewInstance ¶
func NewInstance() *Instance
NewInstance creates a new Instance object setting the defaults
func (*Instance) CanCheckReadiness ¶
CanCheckReadiness checks whether the instance should be checked for readiness
func (*Instance) CheckForExistingPostmaster ¶
func (instance *Instance) CheckForExistingPostmaster(postgresExecutables ...string) (*os.Process, error)
CheckForExistingPostmaster checks if a postmaster process is running on the PGDATA volume. If it is, it returns its process entry.
To do that, this function will read the PID file from the data directory and check the existence of the relative process. If the process exists, then that process entry is returned. If it doesn't exist then the PID file is stale and is removed.
We are requiring a list of PostgreSQL executables that is used to check if the process with the ID read from the PID file is really a postmaster. This isn't really needed per se, but allows this function to be easier to test.
func (*Instance) CheckHasDiskSpaceForWAL ¶ added in v1.24.0
CheckHasDiskSpaceForWAL checks if we have enough disk space to store two WAL files, and returns true if we have free disk space for 2 WAL segments, false otherwise
func (*Instance) CleanUpStalePid ¶
CleanUpStalePid cleans up the files left around by a crashed PostgreSQL instance. It removes the default PostgreSQL pid file and the content of the socket directory.
func (*Instance) ConfigureSlotReplicator ¶ added in v1.18.0
func (instance *Instance) ConfigureSlotReplicator(config *apiv1.ReplicationSlotsConfiguration)
ConfigureSlotReplicator sends the configuration to the slot replicator
func (*Instance) ConnectionPool ¶
func (instance *Instance) ConnectionPool() *pool.ConnectionPool
ConnectionPool gets or initializes the connection pool for this instance
func (*Instance) DropConnections ¶ added in v1.15.5
DropConnections drops all the connections of backend_type 'client backend'
func (*Instance) GeneratePostgresqlHBA ¶
func (instance *Instance) GeneratePostgresqlHBA(cluster *apiv1.Cluster, ldapBindPassword string) (string, error)
GeneratePostgresqlHBA generates the pg_hba.conf content with the LDAP configuration if configured.
func (*Instance) GetClusterName ¶ added in v1.23.5
GetClusterName returns the name of the cluster where this instance belongs
func (*Instance) GetDecreasedSensibleSettings ¶
GetDecreasedSensibleSettings tries to get all decreased hot standby sensible parameters from the instance. Returns a map containing all the decreased hot standby sensible parameters with their new value. See https://www.postgresql.org/docs/current/hot-standby.html#HOT-STANDBY-ADMIN for more details.
func (*Instance) GetInstanceCommandChan ¶
func (instance *Instance) GetInstanceCommandChan() <-chan InstanceCommand
GetInstanceCommandChan is the channel where the lifecycle manager will wait for the operations requested on the instance
func (*Instance) GetNamespaceName ¶ added in v1.23.5
GetNamespaceName returns the name of the namespace where this instance is running
func (*Instance) GetPgControldata ¶ added in v1.21.0
GetPgControldata returns the output of pg_controldata and any errors encountered
func (*Instance) GetPgVersion ¶
GetPgVersion queries the postgres instance to know the current version, parses it and memoize it for future uses
func (*Instance) GetPodName ¶ added in v1.23.5
GetPodName returns the name of the pod where this instance is running
func (*Instance) GetPostmasterPidFromFile ¶ added in v1.15.1
GetPostmasterPidFromFile reads the given postmaster pid file, parse it and return its content and the actual pid
func (*Instance) GetPrimaryConnInfo ¶ added in v1.18.0
GetPrimaryConnInfo returns the DSN to reach the primary
func (*Instance) GetStatus ¶
func (instance *Instance) GetStatus() (result *postgres.PostgresqlStatus, err error)
GetStatus Extract the status of this PostgreSQL database
func (*Instance) GetSuperUserDB ¶
GetSuperUserDB gets a connection to the "postgres" database on this instance
func (*Instance) GetTemplateDB ¶
GetTemplateDB gets a connection to the "template1" database on this instance
func (*Instance) HandleInstanceCommandRequests ¶ added in v1.19.5
func (instance *Instance) HandleInstanceCommandRequests( ctx context.Context, req InstanceCommand, ) (restartNeeded bool, err error)
HandleInstanceCommandRequests execute a command requested by the reconciliation loop.
func (*Instance) IsPrimary ¶
IsPrimary check if the data directory belongs to a primary server or to a secondary one by looking for a "standby.signal" file inside the data directory. IMPORTANT: this method also works when the instance is not started up
func (*Instance) IsServerHealthy ¶
IsServerHealthy check if the instance is healthy
func (*Instance) IsWALReceiverActive ¶
IsWALReceiverActive check if the WAL receiver process is active by looking at the number of records in the `pg_stat_wal_receiver` table
func (*Instance) LogPgControldata ¶
LogPgControldata logs the content of PostgreSQL control data, for debugging and tracing
func (*Instance) MightBeUnavailable ¶
MightBeUnavailable checks whether we expect the instance to be down
func (*Instance) PrimaryConnectionPool ¶ added in v1.18.0
func (instance *Instance) PrimaryConnectionPool() *pool.ConnectionPool
PrimaryConnectionPool gets or initializes the primary connection pool for this instance
func (*Instance) PromoteAndWait ¶
PromoteAndWait promotes this instance, and wait DefaultPgCtlTimeoutForPromotion seconds for it to happen
func (*Instance) RefreshConfigurationFilesFromCluster ¶
func (instance *Instance) RefreshConfigurationFilesFromCluster( ctx context.Context, cluster *apiv1.Cluster, preserveUserSettings bool, ) (bool, error)
RefreshConfigurationFilesFromCluster receives a cluster object, then generates the PostgreSQL configuration and rewrites the file in the PGDATA if needed. This function will return "true" if the configuration has been really changed.
func (*Instance) RefreshPGHBA ¶
func (instance *Instance) RefreshPGHBA(ctx context.Context, cluster *apiv1.Cluster, ldapBindPassword string) ( postgresHBAChanged bool, err error, )
RefreshPGHBA generates and writes down the pg_hba.conf file
func (*Instance) RefreshPGIdent ¶ added in v1.20.6
func (instance *Instance) RefreshPGIdent( ctx context.Context, additionalLines []string, ) (postgresIdentChanged bool, err error)
RefreshPGIdent generates and writes down the pg_ident.conf file given a set of additional pg_ident lines that is usually taken from the Cluster configuration
func (*Instance) RefreshReplicaConfiguration ¶ added in v1.19.4
func (instance *Instance) RefreshReplicaConfiguration( ctx context.Context, cluster *apiv1.Cluster, cli client.Client, ) (changed bool, err error)
RefreshReplicaConfiguration writes the PostgreSQL correct replication configuration for connecting to the right primary server, depending on the cluster replica mode
func (*Instance) RequestAndWaitFencingOff ¶
func (instance *Instance) RequestAndWaitFencingOff(ctx context.Context, timeout time.Duration) error
RequestAndWaitFencingOff will request to remove the fencing and wait for the instance to be restarted
func (*Instance) RequestAndWaitRestartSmartFast ¶
func (instance *Instance) RequestAndWaitRestartSmartFast(ctx context.Context, timeout time.Duration) error
RequestAndWaitRestartSmartFast requests the lifecycle manager to restart the postmaster, and wait for the postmaster to be restarted
func (*Instance) RequestFastImmediateShutdown ¶
func (instance *Instance) RequestFastImmediateShutdown()
RequestFastImmediateShutdown request the lifecycle manager to shut down PostgreSQL using the fast strategy and then the immediate strategy.
func (*Instance) RequestFencingOn ¶
func (instance *Instance) RequestFencingOn()
RequestFencingOn request the lifecycle manager to shut down postgres and enable fencing
func (*Instance) Rewind ¶
Rewind uses pg_rewind to align this data directory with the contents of the primary node. If postgres major version is >= 13, add "--restore-target-wal" option
func (*Instance) RoleSynchronizerChan ¶ added in v1.20.0
func (instance *Instance) RoleSynchronizerChan() <-chan *apiv1.ManagedConfiguration
RoleSynchronizerChan returns the communication channel to the role synchronizer
func (*Instance) Run ¶
func (instance *Instance) Run() (*execlog.StreamingCmd, error)
Run this instance returning an OS process needed to control the instance execution
func (*Instance) SetCanCheckReadiness ¶
SetCanCheckReadiness marks whether the instance should be checked for readiness
func (*Instance) SetFencing ¶
SetFencing marks whether the instance is fenced, if enabling, marks also any down to be tolerated
func (*Instance) SetMightBeUnavailable ¶
SetMightBeUnavailable marks whether the instance being down should be tolerated
func (*Instance) SetPostgreSQLAutoConfWritable ¶ added in v1.20.6
SetPostgreSQLAutoConfWritable allows or deny writes to the `postgresql.auto.conf` file in PGDATA
func (*Instance) Shutdown ¶
Shutdown shuts down a PostgreSQL instance which was previously started with Startup. This function will return an error whether PostgreSQL is still up after the shutdown request.
func (*Instance) ShutdownConnections ¶
func (instance *Instance) ShutdownConnections()
ShutdownConnections tears down database connections
func (*Instance) SlotReplicatorChan ¶ added in v1.18.0
func (instance *Instance) SlotReplicatorChan() <-chan *apiv1.ReplicationSlotsConfiguration
SlotReplicatorChan returns the communication channel to the slot replicator
func (*Instance) Startup ¶
Startup starts up a PostgreSQL instance and wait for the instance to be started
func (*Instance) TablespaceSynchronizerChan ¶ added in v1.22.0
func (instance *Instance) TablespaceSynchronizerChan() <-chan map[string]apiv1.TablespaceConfiguration
TablespaceSynchronizerChan returns the communication channel to the tablespace synchronizer
func (*Instance) TriggerRoleSynchronizer ¶ added in v1.20.0
func (instance *Instance) TriggerRoleSynchronizer(config *apiv1.ManagedConfiguration)
TriggerRoleSynchronizer sends the configuration to the role synchronizer
func (*Instance) TriggerTablespaceSynchronizer ¶ added in v1.22.0
func (instance *Instance) TriggerTablespaceSynchronizer(config map[string]apiv1.TablespaceConfiguration)
TriggerTablespaceSynchronizer sends the configuration to the tablespace synchronizer
func (*Instance) TryGetPgStatWAL ¶ added in v1.15.1
TryGetPgStatWAL retrieves pg_wal_stat on pg version 14 and further
func (*Instance) TryShuttingDownFastImmediate ¶ added in v1.19.5
TryShuttingDownFastImmediate first tries to shut down the instance with mode fast, then in case of failure or the given timeout expiration, it will issue an immediate shutdown request and wait for it to complete. N.B. immediate shutdown can cause data loss.
func (*Instance) TryShuttingDownSmartFast ¶ added in v1.19.5
TryShuttingDownSmartFast first tries to shut down the instance with mode smart, then in case of failure or the given timeout expiration, it will issue a fast shutdown request and wait for it to complete.
func (*Instance) VerifyPgDataCoherence ¶ added in v1.20.3
VerifyPgDataCoherence checks the PGDATA is correctly configured in terms of file rights and users
func (*Instance) WaitForConfigReload ¶ added in v1.19.4
func (instance *Instance) WaitForConfigReload(ctx context.Context) (*postgres.PostgresqlStatus, error)
WaitForConfigReload returns the postgresqlStatus and any error encountered
func (*Instance) WaitForPrimaryAvailable ¶
WaitForPrimaryAvailable waits until we can connect to the primary
func (*Instance) WaitForSuperuserConnectionAvailable ¶
WaitForSuperuserConnectionAvailable waits until we can connect to this instance using the superuser account
func (*Instance) WithActiveInstance ¶
WithActiveInstance execute the internal function while this PostgreSQL instance is running
func (*Instance) WithClusterName ¶ added in v1.23.5
WithClusterName specifies the name of the cluster this Instance belongs to
func (*Instance) WithNamespace ¶ added in v1.23.5
WithNamespace specifies the namespace for this Instance
func (*Instance) WithPodName ¶ added in v1.23.5
WithPodName specifies the pod name for this Instance
type InstanceCommand ¶
type InstanceCommand string
InstanceCommand are commands for the goroutine managing postgres
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package archiver contains the logic of the CloudNativePG WAL archiver
|
Package archiver contains the logic of the CloudNativePG WAL archiver |
|
Package constants provides the needed constants in the postgres package
|
Package constants provides the needed constants in the postgres package |
|
Package logicalimport contains the logic needed to import a logical snapshot
|
Package logicalimport contains the logic needed to import a logical snapshot |
|
Package logpipe implements reading csv logs from PostgreSQL logging_collector (https://www.postgresql.org/docs/current/runtime-config-logging.html) and convert them to JSON.
|
Package logpipe implements reading csv logs from PostgreSQL logging_collector (https://www.postgresql.org/docs/current/runtime-config-logging.html) and convert them to JSON. |
|
Package metrics enables to expose a set of metrics and collectors on a given postgres instance
|
Package metrics enables to expose a set of metrics and collectors on a given postgres instance |
|
histogram
Package histogram contain histogram-metrics related functions
|
Package histogram contain histogram-metrics related functions |
|
Package pool contain an implementation of a connection pool to multiple database pointing to the same instance
|
Package pool contain an implementation of a connection pool to multiple database pointing to the same instance |
|
Package readiness contains the code needed to check if PostgreSQL is ready to accept client connections.
|
Package readiness contains the code needed to check if PostgreSQL is ready to accept client connections. |
|
Package utils holds generic utils about postgres instances
|
Package utils holds generic utils about postgres instances |
|
Package webserver contains the web server powering probes, backups and metrics
|
Package webserver contains the web server powering probes, backups and metrics |
|
client/common
Package common provides common utilities for the webserver client.
|
Package common provides common utilities for the webserver client. |
|
client/local
Package local provides a client to interact with the local webserver endpoints.
|
Package local provides a client to interact with the local webserver endpoints. |
|
client/remote
Package remote contains the client capable of querying the webserver remote endpoint.
|
Package remote contains the client capable of querying the webserver remote endpoint. |
|
metricserver
Package metricserver contains the web server powering metrics
|
Package metricserver contains the web server powering metrics |