Skip to content

[BUG]: timestamp conversion for recovery target is not valid for UTC times #167

@jsilvela

Description

@jsilvela

In the function ConvertToPostgresFormat in pkg/postgres/time/time.go, which seems to be used specifically for recovery_target_time, the conversion of an RFC3339 or RFC3339Micro input string results in a trailing Z for UTC times.

This is producing an error in recovery clusters. You can see the discussion in cloudnative-pg/cloudnative-pg#8937
and some experiments in cloudnative-pg/cloudnative-pg#8981

Specifically, given an input time in RFC3339 format, in UTC time zone, we get the following:

"msg":"waiting for server to start....2025-10-28 16:40:20.324 UTC [38] 
  LOG:  invalid value for parameter \"recovery_target_time\": \"2025-10-28 16:34:15.000000Z\"",

According to the Postgres documentation on recovery_target_time, the same format used for timestamps is valid, EXCEPT that timezone abbreviations are not allowed, and numeric offsets from UTC are recommended.

The value of this parameter is a time stamp in the same format accepted by the timestamp with time zone data type, except that you cannot use a time zone abbreviation (unless the timezone_abbreviations variable has been set earlier in the configuration file). Preferred style is to use a numeric offset from UTC, or you can write a full time zone name, e.g., Europe/Helsinki not EEST.

https://www.postgresql.org/docs/current/runtime-config-wal.html

If ConvertToPostgresFormat substitutes +00 for Z when formatting UTC times, the recovery time will work fine.

Again, see cloudnative-pg/cloudnative-pg#8981 for the green runs.

In addition, we don't currently have an E2E test that properly exercises the ConvertToPostgresFormat function, as the present implementation uses a Postgres timestamp in the cluster spec, which passes through the Convert function. The E2E will be fixed to use a recovery target timestamp in RFC3339.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions