MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / PostgreSQLParameters

Function PostgreSQLParameters

internal/pgbackrest/postgres.go:15–71  ·  view source on GitHub ↗

PostgreSQLParameters populates outParameters with any settings needed to run pgBackRest.

(
	inCluster *v1beta1.PostgresCluster,
	outParameters *postgres.Parameters,
	backupsEnabled bool,
)

Source from the content-addressed store, hash-verified

13
14// PostgreSQLParameters populates outParameters with any settings needed to run pgBackRest.
15func PostgreSQLParameters(
16 inCluster *v1beta1.PostgresCluster,
17 outParameters *postgres.Parameters,
18 backupsEnabled bool,
19) {
20 if outParameters.Mandatory == nil {
21 outParameters.Mandatory = postgres.NewParameterSet()
22 }
23 if outParameters.Default == nil {
24 outParameters.Default = postgres.NewParameterSet()
25 }
26
27 // Send WAL files to all configured repositories when not in recovery.
28 // - https://pgbackrest.org/user-guide.html#quickstart/configure-archiving
29 // - https://pgbackrest.org/command.html#command-archive-push
30 // - https://www.postgresql.org/docs/current/runtime-config-wal.html
31 outParameters.Mandatory.Add("archive_mode", "on")
32 if backupsEnabled {
33 archive := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-push "%p"`
34 outParameters.Mandatory.Add("archive_command", archive)
35 } else {
36 // If backups are disabled, keep archive_mode on (to avoid a Postgres restart)
37 // and throw away WAL.
38 outParameters.Mandatory.Add("archive_command", `true`)
39 }
40
41 // archive_timeout is used to determine at what point a WAL file is switched,
42 // if the WAL archive has not reached its full size in # of transactions
43 // (16MB). This has ramifications for log shipping, i.e. it ensures a WAL file
44 // is shipped to an archive every X seconds to help reduce the risk of data
45 // loss in a disaster recovery scenario. For standby servers that are not
46 // connected using streaming replication, this also ensures that new data is
47 // available at least once a minute.
48 //
49 // PostgreSQL documentation considers an archive_timeout of 60 seconds to be
50 // reasonable. There are cases where you may want to set archive_timeout to 0,
51 // for example, when the remote archive (pgBackRest repo) is unavailable; this
52 // is to prevent WAL accumulation on your primary.
53 // - https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-ARCHIVE-TIMEOUT
54 outParameters.Default.Add("archive_timeout", "60s")
55
56 // Fetch WAL files from any configured repository during recovery.
57 // - https://pgbackrest.org/command.html#command-archive-get
58 // - https://www.postgresql.org/docs/current/runtime-config-wal.html
59 restore := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-get %f "%p"`
60 outParameters.Mandatory.Add("restore_command", restore)
61
62 if inCluster.Spec.Standby != nil && inCluster.Spec.Standby.Enabled && inCluster.Spec.Standby.RepoName != "" {
63
64 // Fetch WAL files from the designated repository. The repository name
65 // is validated by the Kubernetes API, so it does not need to be quoted
66 // nor escaped.
67 repoName := inCluster.Spec.Standby.RepoName
68 restore += " --repo=" + strings.TrimPrefix(repoName, "repo")
69 outParameters.Mandatory.Add("restore_command", restore)
70 }
71}

Callers 2

TestPostgreSQLParametersFunction · 0.70

Calls 2

NewParameterSetFunction · 0.92
AddMethod · 0.45

Tested by 1

TestPostgreSQLParametersFunction · 0.56