Skip to content

sql: stop relying on time.LoadLocation for time zone data #36864

@knz

Description

@knz

Summary of the problem

CockroachDB uses the Go language's idea of where time zones are defined, and this is non-standard. This breaks time zone support in some environments, most notably Windows.

Workarounds

  • run on an OS platform where Go has proper timezone support (e.g. Linux)
  • get a copy of zoneinfo.zip from the Go sources and set the env var ZONEINFO to point to it
  • install the Go sources and set GOROOT to point to them

Note: since 20.1 a node will refuse to start up (#45680) if the tzdata is not available. It is possible to forcefully start a node (and cause inconsistent time results in SQL) via the env var COCKROACH_INCONSISTENT_TIME_ZONES.

Description of the problem

CockroachDB currently uses Go's standard time.LoadLocation to load time zone data.

However Go's standard time package is very simple/dumb. It takes the time zone name given as a file name, tries to open that in the system-wide tzdata directory, and satisfies itself with what it finds there. If the file does not exist (as would happen if the given string is mis-cased), tough luck.

There are multiple problems with this design:

Solution

CockroachDB should:

  • embed its own copy of a time zone database (like postgres does? I'm not sure)
  • it should only accept time zone names that are known to be valid/exist when cockroachdb was built (to avoid trying to open a file with a special name)
  • it should provide its own custom time zone loader, which knows how to find time zone names case-insensitively.

Another approach would be to scan the system-wide timezone database upon process start-up and then normalize the name cases in an in-RAM cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-pgcompatSemantic compatibility with PostgreSQLB-os-windowsIssues specific to the Windows OS.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions