Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6938,6 +6938,9 @@ spec:
required:
- volumeSnapshotClassName
type: object
trackLatestRestorableTime:
description: Enable tracking latest restorable time
type: boolean
type: object
config:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6928,6 +6928,9 @@ spec:
required:
- volumeSnapshotClassName
type: object
trackLatestRestorableTime:
description: Enable tracking latest restorable time
type: boolean
type: object
config:
properties:
Expand Down
3 changes: 3 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36721,6 +36721,9 @@ spec:
required:
- volumeSnapshotClassName
type: object
trackLatestRestorableTime:
description: Enable tracking latest restorable time
type: boolean
type: object
config:
properties:
Expand Down
3 changes: 3 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36721,6 +36721,9 @@ spec:
required:
- volumeSnapshotClassName
type: object
trackLatestRestorableTime:
description: Enable tracking latest restorable time
type: boolean
type: object
config:
properties:
Expand Down
3 changes: 3 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36721,6 +36721,9 @@ spec:
required:
- volumeSnapshotClassName
type: object
trackLatestRestorableTime:
description: Enable tracking latest restorable time
type: boolean
type: object
config:
properties:
Expand Down
26 changes: 15 additions & 11 deletions internal/pgbackrest/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ func PostgreSQL(
// - https://pgbackrest.org/user-guide.html#quickstart/configure-archiving
// - https://pgbackrest.org/command.html#command-archive-push
// - https://www.postgresql.org/docs/current/runtime-config-wal.html

fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"`
extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + ``
validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"`
archive := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-push "%p"`
archive += ` && timestamp=$(pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);`
archive += ` if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi`

// K8SPG-518
if track := inCluster.Spec.Backups.TrackLatestRestorableTime; track != nil && *track {
fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"`
extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + ``
validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"`

archive += ` && timestamp=$(pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);`
archive += ` if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi`

// K8SPG-518: This parameter is required to ensure that the commit timestamp is
// included in the WAL file. This is necessary for the WAL watcher to
// function correctly.
outParameters.Mandatory.Add("track_commit_timestamp", "true")
}

outParameters.Mandatory.Add("archive_mode", "on")

Expand All @@ -46,11 +55,6 @@ func PostgreSQL(
outParameters.Mandatory.Add("archive_command", `true`)
}

// K8SPG-518: This parameter is required to ensure that the commit timestamp is
// included in the WAL file. This is necessary for the WAL watcher to
// function correctly.
outParameters.Mandatory.Add("track_commit_timestamp", "true")

// archive_timeout is used to determine at what point a WAL file is switched,
// if the WAL archive has not reached its full size in # of transactions
// (16MB). This has ramifications for log shipping, i.e. it ensures a WAL file
Expand Down
46 changes: 19 additions & 27 deletions internal/pgbackrest/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"gotest.tools/v3/assert"
"k8s.io/utils/ptr"

"github.com/percona/percona-postgresql-operator/internal/postgres"
"github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
Expand All @@ -20,19 +21,9 @@ func TestPostgreSQLParameters(t *testing.T) {

PostgreSQL(cluster, parameters, true)
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{
"archive_mode": "on",
"archive_command": strings.Join([]string{
`pgbackrest --stanza=db archive-push "%p" `,
`&& timestamp=$(pg_waldump "%p" | `,
`grep -oP "COMMIT \K[^;]+" | `,
`sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | `,
`sed "s/UTC/Z/" | `,
"tail -n 1 | ",
`grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"); `,
"if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi",
}, ""),
"restore_command": `pgbackrest --stanza=db archive-get %f "%p"`,
"track_commit_timestamp": "true",
"archive_mode": "on",
"archive_command": `pgbackrest --stanza=db archive-push "%p"`,
"restore_command": `pgbackrest --stanza=db archive-get %f "%p"`,
})

assert.DeepEqual(t, parameters.Default.AsMap(), map[string]string{
Expand All @@ -53,19 +44,9 @@ func TestPostgreSQLParameters(t *testing.T) {

PostgreSQL(cluster, parameters, true)
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{
"archive_mode": "on",
"archive_command": strings.Join([]string{
`pgbackrest --stanza=db archive-push "%p" `,
`&& timestamp=$(pg_waldump "%p" | `,
`grep -oP "COMMIT \K[^;]+" | `,
`sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | `,
`sed "s/UTC/Z/" | `,
"tail -n 1 | ",
`grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"); `,
"if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi",
}, ""),
"restore_command": "/bin/true",
"track_commit_timestamp": "true",
"archive_mode": "on",
"archive_command": `pgbackrest --stanza=db archive-push "%p"`,
"restore_command": "/bin/true",
})

cluster.Spec.Standby = &v1beta1.PostgresStandbySpec{
Expand All @@ -74,6 +55,17 @@ func TestPostgreSQLParameters(t *testing.T) {
}
cluster.Spec.Patroni.DynamicConfiguration = nil

PostgreSQL(cluster, parameters, true)
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{
"archive_mode": "on",
"archive_command": `pgbackrest --stanza=db archive-push "%p"`,
"restore_command": `pgbackrest --stanza=db archive-get %f "%p" --repo=99`,
})

cluster.Spec.Standby = nil
cluster.Spec.Patroni.DynamicConfiguration = nil
cluster.Spec.Backups.TrackLatestRestorableTime = ptr.To(true)

PostgreSQL(cluster, parameters, true)
assert.DeepEqual(t, parameters.Mandatory.AsMap(), map[string]string{
"archive_mode": "on",
Expand All @@ -87,7 +79,7 @@ func TestPostgreSQLParameters(t *testing.T) {
`grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"); `,
"if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi",
}, ""),
"restore_command": `pgbackrest --stanza=db archive-get %f "%p" --repo=99`,
"restore_command": `pgbackrest --stanza=db archive-get %f "%p"`,
"track_commit_timestamp": "true",
})
}
1 change: 1 addition & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func (b Backups) ToCrunchy(version string) crunchyv1beta1.Backups {
Env: b.PGBackRest.Env,
EnvFrom: b.PGBackRest.EnvFrom,
},
TrackLatestRestorableTime: b.TrackLatestRestorableTime,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ type Backups struct {
// VolumeSnapshot configuration
// +optional
Snapshots *VolumeSnapshots `json:"snapshots,omitempty"`

// Enable tracking latest restorable time
TrackLatestRestorableTime *bool `json:"trackLatestRestorableTime,omitempty"`
}

// PostgresClusterStatus defines the observed state of PostgresCluster
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading