Skip to content

Conversation

@dverite
Copy link
Collaborator

@dverite dverite commented Jul 1, 2025

The current code has an issue with timestamptz partition keys when the time zone is not UTC.
The first provisioning works as expected, but when reading back the partition definitions,
the expected boundaries differ from what is read from the database.
This is essentially due to rotating locally the values to UTC instead of ignoring the timezone offset.

Additionally add support for the PGTZ env variable (updated driver jackc/pgx) and add a test
with a timestamptz partition key and a non-UTC time zone.

dverite added 4 commits July 1, 2025 15:20
This was added in v5.7.5 (May 10, 2025) and we need it
to easily test different timezones.

Signed-off-by: Daniel Vérité <dverite@gmail.com>
Signed-off-by: Daniel Vérité <dverite@gmail.com>
In order to be timezone-agnostic, we submit partition bounds without
timezone offsets, like:
 VALUES FROM ('YYYY-MM-DD 00:00:00') TO ('YYYY-MM-DD 00:00:00')
The time zone of the session is automatically applied by Postgres.

When reading back these values, we get for instance
 YYYY-MM-DD 00:00:00+02
if the current time zone offset is +02.

If we rotate this timestamp locally to UTC and resubmit it without the
offset, it is now incorrect (unless the server happens to be
configured in UTC).

The fix consists of ignoring the offset when reading the current
bounds, to be consistently timezone-agnostic. The offset always
corresponds implicitly to the time zone of the SQL session, and
must not be forced in the value of the timestamp.

The SQL time zone can be changed dynamically with the PGTZ environment
variable if desired.

Signed-off-by: Daniel Vérité <dverite@gmail.com>
Signed-off-by: Daniel Vérité <dverite@gmail.com>
@dverite
Copy link
Collaborator Author

dverite commented Jul 1, 2025

#storage

@dverite dverite merged commit 2b90a38 into main Jul 1, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants