Skip to content

fix(db): don't depend on the Postgres session timezone - #1560

Open
Akshats-git wants to merge 1 commit into
flatcar:mainfrom
Akshats-git:fix/postgres-session-timezone
Open

fix(db): don't depend on the Postgres session timezone#1560
Akshats-git wants to merge 1 commit into
flatcar:mainfrom
Akshats-git:fix/postgres-session-timezone

Conversation

@Akshats-git

Copy link
Copy Markdown

Fixes #1541

The instance and update stats queries compared timestamptz columns against now() at time zone 'utc'. That expression returns a plain timestamp with no zone, so Postgres converts it back using the session timezone. Every time window was shifted by the session offset.

If the session runs in UTC nothing is wrong. Anything else and the instance counts on the dashboard are off, and the rollout policy sees granted updates as older or younger than they are. West of UTC they time out early, which disables updates for the whole group under safe mode. East of UTC they stay in progress past the timeout and new instances get held back.

Changes:

  • Replaced now() at time zone 'utc' with plain now() in the five stats queries and in GetGroupUpdatesStats. The timeline queries in the same package already used plain now(), so this also makes them agree.
  • Same fix in sample_data.sql, where the fixture rows were backdated to shifted instants.
  • Connections now pin the session timezone to UTC through the DSN, unless the database URL already sets one. Explicit config still wins.
  • Added tests that run the stats queries under UTC, America/New_York and Asia/Kolkata and expect the same numbers.

Tested against postgres:16.3-alpine started with -c timezone=America/New_York. With the query fix reverted the new tests fail in both directions, so they cover the actual regression. Full backend suite passes against a non-UTC server and a UTC one.

@Akshats-git
Akshats-git requested a review from a team as a code owner August 11, 2026 13:01
Copilot AI lite review requested due to automatic review settings August 11, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…ones in queries and tests

Signed-off-by: Akshat <akshatgupta099@gmail.com>
@Akshats-git
Akshats-git force-pushed the fix/postgres-session-timezone branch from 4d6b184 to 70aa9c8 Compare August 16, 2026 12:51
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.

Instance stats and rollout policy queries break when the Postgres session timezone is not UTC

2 participants