Skip to content

Commit 1a64853

Browse files
pchovelonjsilvelamnenciaarmru
authored
fix(targetTime): clarify timestamp formats and UTC interpretation (#8937)
Update the machinery dependency to v0.3.3 to ensure timestamps without timezone (both RFC3339 and PostgreSQL formats) are interpreted as UTC. The documentation has been updated to clarify that targetTime accepts both RFC 3339 and PostgreSQL timestamp formats. Closes #8928 Related: cloudnative-pg/machinery#167 Signed-off-by: Pierrick Chovelon <[email protected]> Signed-off-by: Pierrick <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Jaime Silvela <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
1 parent 25b35a1 commit 1a64853

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎api/v1/cluster_types.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,8 @@ type RecoveryTarget struct {
20212021
// +optional
20222022
TargetLSN string `json:"targetLSN,omitempty"`
20232023

2024-
// The target time as a timestamp in the RFC3339 standard
2024+
// The target time as a timestamp in RFC3339 format or PostgreSQL timestamp format.
2025+
// Timestamps without an explicit timezone are interpreted as UTC.
20252026
// +optional
20262027
TargetTime string `json:"targetTime,omitempty"`
20272028

‎config/crd/bases/postgresql.cnpg.io_clusters.yaml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,8 +1978,9 @@ spec:
19781978
integer)
19791979
type: string
19801980
targetTime:
1981-
description: The target time as a timestamp in the RFC3339
1982-
standard
1981+
description: |-
1982+
The target time as a timestamp in RFC3339 format or PostgreSQL timestamp format.
1983+
Timestamps without an explicit timezone are interpreted as UTC.
19831984
type: string
19841985
targetXID:
19851986
description: The target transaction ID

‎docs/src/cloudnative-pg.v1.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ _Appears in:_
22322232
| `targetXID` _string_ | The target transaction ID | | | |
22332233
| `targetName` _string_ | The target name (to be previously created<br />with `pg_create_restore_point`) | | | |
22342234
| `targetLSN` _string_ | The target LSN (Log Sequence Number) | | | |
2235-
| `targetTime` _string_ | The target time as a timestamp in the RFC3339 standard | | | |
2235+
| `targetTime` _string_ | The target time as a timestamp in RFC3339 format or PostgreSQL timestamp format.<br />Timestamps without an explicit timezone are interpreted as UTC. | | | |
22362236
| `targetImmediate` _boolean_ | End recovery as soon as a consistent state is reached | | | |
22372237
| `exclusive` _boolean_ | Set the target to be exclusive. If omitted, defaults to false, so that<br />in Postgres, `recovery_target_inclusive` will be true | | | |
22382238

‎docs/src/recovery.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ spec:
367367
kind: VolumeSnapshot
368368
apiGroup: snapshot.storage.k8s.io
369369
recoveryTarget:
370-
targetTime: "2023-07-06T08:00:39"
370+
targetTime: "2023-07-06T08:00:39Z"
371371
externalClusters:
372372
- name: origin
373373
plugin:
@@ -405,9 +405,21 @@ Here are the recovery target criteria you can use:
405405

406406
targetTime
407407
: Time stamp up to which recovery proceeds, expressed in
408-
[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format.
408+
[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format, or as a
409+
[timestamp](https://www.postgresql.org/docs/current/runtime-config-wal.html#GUC-RECOVERY-TARGET-TIME).
409410
(The precise stopping point is also influenced by the `exclusive` option.)
410411

412+
:::note
413+
Timestamps without an explicit timezone suffix
414+
(e.g., `2023-07-06 08:00:39`) are interpreted as UTC.
415+
:::
416+
417+
:::warning
418+
Always specify an explicit timezone in your timestamp to avoid ambiguity.
419+
For example, use `2023-07-06T08:00:39Z` or `2023-07-06T08:00:39+02:00`
420+
instead of `2023-07-06 08:00:39`.
421+
:::
422+
411423
:::warning
412424
PostgreSQL recovery will stop when it encounters the first transaction that
413425
occurs after the specified time. If no such transaction exists after the
@@ -623,4 +635,4 @@ data.
623635
cluster. However, this is strongly discouraged unless you are highly
624636
familiar with PostgreSQL's recovery process. Skipping the check incorrectly can
625637
lead to severe data loss. Use with caution and only in expert scenarios.
626-
:::
638+
:::

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/cheynewallace/tabby v1.1.1
1414
github.com/cloudnative-pg/barman-cloud v0.3.3
1515
github.com/cloudnative-pg/cnpg-i v0.3.0
16-
github.com/cloudnative-pg/machinery v0.3.1
16+
github.com/cloudnative-pg/machinery v0.3.3
1717
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
1818
github.com/evanphx/json-patch/v5 v5.9.11
1919
github.com/go-logr/logr v1.4.3

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ github.com/cloudnative-pg/barman-cloud v0.3.3 h1:EEcjeV+IUivDpmyF/H/XGY1pGaKJ5LS
2424
github.com/cloudnative-pg/barman-cloud v0.3.3/go.mod h1:5CM4MncAxAjnqxjDt0I5E/oVd7gsMLL0/o/wQ+vUSgs=
2525
github.com/cloudnative-pg/cnpg-i v0.3.0 h1:5ayNOG5x68lU70IVbHDZQrv5p+bErCJ0mqRmOpW2jjE=
2626
github.com/cloudnative-pg/cnpg-i v0.3.0/go.mod h1:VOIWWXcJ1RyioK+elR2DGOa4cBA6K+6UQgx05aZmH+g=
27-
github.com/cloudnative-pg/machinery v0.3.1 h1:KtPA6EwELTUNisCMLiFYkK83GU9606rkGQhDJGPB8Yw=
28-
github.com/cloudnative-pg/machinery v0.3.1/go.mod h1:jebuqKxZAbrRKDEEpVCIDMKW+FbWtB9Kf/hb2kMUu9o=
27+
github.com/cloudnative-pg/machinery v0.3.3 h1:CaqXqLTJH9RrVv3R/YU0NmFaI/F18HLg2JfH3mQLcDk=
28+
github.com/cloudnative-pg/machinery v0.3.3/go.mod h1:RYAYlVKBF5pH4mg+Q8wHjNDyENV9ajbkG41zOEf8DEs=
2929
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
3030
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
3131
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=

0 commit comments

Comments
 (0)