Skip to content

Commit 671b124

Browse files
committed
K8SPG-628: Allow overriding restore_command
1 parent 576c6ca commit 671b124

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

internal/pgbackrest/postgres.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ func PostgreSQL(
7272
// - https://pgbackrest.org/command.html#command-archive-get
7373
// - https://www.postgresql.org/docs/current/runtime-config-wal.html
7474
restore := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-get %f "%p"`
75+
if inCluster.Spec.Patroni != nil && inCluster.Spec.Patroni.DynamicConfiguration != nil {
76+
postgresql, ok := inCluster.Spec.Patroni.DynamicConfiguration["postgresql"].(map[string]any)
77+
if ok {
78+
params, ok := postgresql["parameters"].(map[string]any)
79+
if ok {
80+
restore_command, ok := params["restore_command"].(string)
81+
if ok {
82+
restore = restore_command
83+
}
84+
}
85+
}
86+
}
7587
outParameters.Mandatory.Add("restore_command", restore)
7688

7789
if inCluster.Spec.Standby != nil && inCluster.Spec.Standby.Enabled && inCluster.Spec.Standby.RepoName != "" {

internal/pgbackrest/postgres_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,40 @@ func TestPostgreSQLParameters(t *testing.T) {
5050
"archive_timeout": "60s",
5151
})
5252

53+
dynamic := map[string]any{
54+
"postgresql": map[string]any{
55+
"parameters": map[string]any{
56+
"restore_command": "/bin/true",
57+
},
58+
},
59+
}
60+
if cluster.Spec.Patroni == nil {
61+
cluster.Spec.Patroni = &v1beta1.PatroniSpec{}
62+
}
63+
cluster.Spec.Patroni.DynamicConfiguration = dynamic
64+
65+
PostgreSQL(cluster, parameters)
66+
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{
67+
"archive_mode": "on",
68+
"archive_command": strings.Join([]string{
69+
`pgbackrest --stanza=db archive-push "%p"`,
70+
` && timestamp=$(pg_waldump "%p" | grep COMMIT | awk '{print $(NF`,
71+
`-2) "T" $(NF-1) " " $(NF)}' | sed -E 's/([0-9]{4}-[0-9]{2}-[0-9]`,
72+
`{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\+\-][0-9]{2})/\`,
73+
`1\2/' | sed 's/UTC/Z/' | tail -n 1 | grep -E '^[0-9]{4}-[0-9]{2}`,
74+
`-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})`,
75+
"$'); if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/l",
76+
"atest_commit_timestamp.txt; fi",
77+
}, ""),
78+
"restore_command": "/bin/true",
79+
"track_commit_timestamp": "true",
80+
})
81+
5382
cluster.Spec.Standby = &v1beta1.PostgresStandbySpec{
5483
Enabled: true,
5584
RepoName: "repo99",
5685
}
86+
cluster.Spec.Patroni.DynamicConfiguration = nil
5787

5888
PostgreSQL(cluster, parameters)
5989
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{

0 commit comments

Comments
 (0)