The History Book Hiding Inside Postgres

https://unsplash.com/de/fotos/ein-paar-uhren-die-an-einer-wand-stehen-KCkL6fFjgdA

TL;DR: The advice for timestamp with time zone always sounds the same: use it, always feed it a real IANA zone name — not a bare UTC offset — and Postgres will convert it correctly no matter how old the date is. That’s true. What’s less obvious is how much history Postgres has to replay to make it true — and that history is sitting right there in your database, no library card required. I went looking, and Vienna’s clock alone has been reset for reasons ranging from an 1893 standardization to two world wars.

Behind the Rule

This is the advice you’ll find everywhere — the official docs, wikis, every “how to handle dates in Postgres” post out there: use timestamp with time zone, and always give it a real zone name like Europe/Vienna, never a fixed offset like +01:00. Follow that, and Postgres converts your input to UTC using whatever rule was actually in force at that exact moment in that zone, then converts it back to any zone you ask for later — correctly, no matter how old the date is. Give it a bare offset instead, and there’s nothing to look up: Postgres just adds or subtracts hours, and none of what follows in this article applies to you.

But zone rules aren’t physics. They’re decisions someone made — a standardization committee, a wartime energy policy, a religious calendar — and then just left sitting in a rule file. So I decided to trip over some on purpose.

The Experiment

Nothing fancy — a recursive CTE walking Europe/Vienna from 1890 to 2030 in 6-month steps, comparing a naive timestamp against its UTC equivalent:

WITH RECURSIVE years AS (
SELECT '1890-01-01 12:00:00'::timestamp AS test_date
UNION ALL
SELECT test_date + INTERVAL '6 months'
FROM years
WHERE test_date < '2030-01-01'::timestamp
)
SELECT
test_date,
test_date AT TIME ZONE 'Europe/Vienna' AS utc_equivalent,
EXTRACT(EPOCH FROM (test_date - (test_date AT TIME ZONE 'Europe/Vienna' AT TIME ZONE 'UTC'))) / 3600 AS offset_hours
FROM years;

test_date AT TIME ZONE ‘Europe/Vienna’ takes the naive timestamp, treats it as if it were local Vienna time, and gives you the UTC instant. The last column just turns that into a plain offset in hours, so the pattern jumps out instead of hiding in timestamp arithmetic.

The output for 1890–2030 was mostly the boring +1/+2 alternation you’d expect from CET/CEST. Except it wasn’t, in three places.

Exhibit 1 — before time zones existed

1.089 hours isn’t a rounding artifact — it’s 1h 5m 21s, which is almost exactly how far Vienna sits east of Greenwich. Before 1893, “Vienna time” was the sun over Vienna. There was no CET, no committee, just Local Mean Time (LMT), city by city.

Zooming into daily granularity around the switch:

WITH RECURSIVE d AS (
SELECT '1893-01-01'::timestamp AS test_date
UNION ALL
SELECT test_date + INTERVAL '1 day' FROM d WHERE test_date < '1894-01-01'::timestamp
),
offsets AS (
SELECT
test_date,
EXTRACT(EPOCH FROM (test_date - (test_date AT TIME ZONE 'Europe/Vienna' AT TIME ZONE 'UTC'))) / 3600 AS offset_hours,
LAG(EXTRACT(EPOCH FROM (test_date - (test_date AT TIME ZONE 'Europe/Vienna' AT TIME ZONE 'UTC'))) / 3600)
OVER (ORDER BY test_date) AS prev_offset
FROM d
)
SELECT test_date, offset_hours
FROM offsets
WHERE offset_hours IS DISTINCT FROM prev_offset;

April 1, 1893 — the exact day Vienna’s local mean time was replaced by a flat, telegraph-and-railway-friendly UTC+1. That’s a specific calendar date, sitting in a tzdata rule file, that nobody notices until a query goes back far enough.

Exhibit 2 — Europe’s first DST experiment

The 1890–2030 run showed something odd around 1916–1918: a +2 reading that shouldn’t have been there. Zooming into monthly granularity confirmed it:

Central Europe’s first daylight saving experiment, introduced in 1916 as a wartime energy-saving measure, shows up as a clean three-summer pattern. It disappears again in 1919, around the same time the Austro-Hungarian Empire did.

Exhibit 3 — an extended summer, then a year without one

The 1938–1946 window is the most irregular stretch in the whole 1890–2030 run:

That 32-month stretch pinned at +2 was Nazi Germany’s wartime policy of permanent summer time, applied to Austria after its 1938 annexation. 1945 — the year the war in Europe ended and Vienna was divided among the occupying powers — shows no DST at all; by 1946 the seasonal rhythm had resumed. It’s not a glitch — the clocks really did run that way.

Exhibit 4 — a lunar calendar, not a solar one

Not every irregularity comes from a war or a 19th-century standardization effort. Morocco (Africa/Casablanca) has run permanent DST (UTC+1) since 2012 — with one exception: clocks revert to standard time (UTC+0) for the entire month of Ramadan, then switch back afterward. Because Ramadan follows the Islamic lunar calendar, that reversion window isn’t tied to a season — it drifts roughly 11 days earlier every year.

Same recursive-CTE pattern, weekly granularity, run for two different years:

WITH RECURSIVE w AS (
SELECT '2023-01-01'::timestamp AS test_date
UNION ALL
SELECT test_date + INTERVAL '1 week' FROM w WHERE test_date < '2024-01-01'::timestamp
)
SELECT
test_date,
test_date AT TIME ZONE 'Africa/Casablanca' AS utc_equivalent,
EXTRACT(EPOCH FROM (test_date - (test_date AT TIME ZONE 'Africa/Casablanca' AT TIME ZONE 'UTC'))) / 3600 AS offset_hours
FROM w;

Run the same query for 2019 and 2023 side by side and the dip visibly lands about six weeks earlier in the calendar in 2023 than in 2019 — almost exactly what four years of an 11-day-per-year lunar drift would predict. It’s not a war or a committee this time — just a different calendar, sitting in the same tzdata format as everything else.

Exhibit 5 — a day that never happened

The most literal discontinuity of all: on December 30, 2011, Samoa skipped an entire calendar day to jump to the other side of the International Date Line, aligning its trading week with Australia and New Zealand instead of the US. Running the same recursive-CTE pattern for Pacific/Apia with daily granularity around the switch shows the leap:

WITH RECURSIVE d AS (
SELECT '2011-12-25'::timestamp AS test_date
UNION ALL
SELECT test_date + INTERVAL '1 day' FROM d WHERE test_date < '2012-01-05'::timestamp
)
SELECT
test_date,
test_date AT TIME ZONE 'Pacific/Apia' AS utc_equivalent,
EXTRACT(EPOCH FROM (test_date - (test_date AT TIME ZONE 'Pacific/Apia' AT TIME ZONE 'UTC'))) / 3600 AS offset_hours
FROM d;

The offset jumps straight from -10 to +14 with no gradual transition — a 24-hour leap, not the usual 1-hour DST step. Listing which local calendar dates Samoa actually had that week makes it unambiguous:

SELECT DISTINCT date_trunc('day', test_date AT TIME ZONE 'Pacific/Apia')::date AS local_date
FROM generate_series('2011-12-25'::timestamp, '2012-01-05'::timestamp, '1 day') AS test_date
ORDER BY local_date;
2011-12-25
2011-12-26
2011-12-27
2011-12-28
2011-12-29
-------------- nothing here-----------
2011-12-31
2012-01-01
2012-01-02
2012-01-03
2012-01-04
2012-01-05

December 30, 2011 simply isn’t there. Samoa’s calendar just skips from the 29th to the 31st.

How this actually works: IANA, zic, and updates

Here’s how it actually works, per the PostgreSQL docs: PostgreSQL documentation

  • The IANA time zone database (what everyone calls tzdata, formerly the “Olson database”) is a public set of plaintext rule files, maintained by volunteers, that record every time zone change a region has ever had — DST introduced, DST abolished, offset changed, zone renamed — each one stamped with the exact date it took effect. It’s the same database your phone, browser, and Linux box all rely on.
  • zic — the “zone information compiler” — takes those plaintext rule files and compiles them into the binary TZif format that programs actually read at runtime.
  • Where Postgres gets its copy: by default, Postgres builds and ships its own compiled copy of the IANA database, so it doesn’t depend on whatever happens to be installed on the host OS. There’s a build option, –with-system-tzdata=DIRECTORY, that points Postgres at the operating system’s copy instead (typically /usr/share/zoneinfo) — mainly used by Linux distribution packagers who’d rather have one shared copy on the system than have Postgres carry a redundant one.
  • How updates ship: tzdata changes several times a year — some country somewhere is always adjusting a DST law — and Postgres just bundles a refreshed copy into its regular minor releases. No separate migration step, no special action from you beyond the usual minor-version update. It shows up as an ordinary changelog line. PostgreSQL 17.5’s release notes, for example, say:

“Update time zone data files to tzdata release 2025b for DST law changes in Chile, plus historical corrections for Iran.”

Apply that minor version bump, and the next time any country touches its clock law, your queries already know about it. No code change required.

You can peek at the current rule for a given zone or abbreviation directly, though these catalogs only show what’s in effect right now, not the history:

SELECT * FROM pg_timezone_names WHERE name IN ('Europe/Vienna', 'Africa/Casablanca');
SELECT * FROM pg_timezone_abbrevs WHERE abbrev IN ('CET','CEST','MET','MEST');

For anything historical, there’s no shortcut — you walk the calendar and let AT TIME ZONE replay the compiled rule set for you, one timestamp at a time, exactly like the exhibits above.

So, Is timestamptz “Just Handled”?

Yes — genuinely, it is. You never have to write the 1916 DST rule, the 1945 no-DST rule, Morocco’s Ramadan exception, or Samoa’s missing day yourself; someone already encoded all of it in tzdata, Postgres ships it, and AT TIME ZONE replays it correctly for any date you throw at it, 1890 included. It’s just worth knowing that “handled” means your database is quietly carrying a small, well-maintained history archive around, and every so often a query into the past hands you a fact you didn’t expect to learn from a timestamp column.

None of the results above came from some special dataset. Every one of them is what a completely fresh, default install of Postgres gives you the moment you run these queries — the tzdata rules ship with the software itself, no setup required. You don’t need a library card or an archive to read any of this history; it’s compiled straight into the database sitting on your laptop, right now.

One practical takeaway: this only works if you actually apply minor version updates. Skip them for a few years and your queries are running on stale tzdata.

A Few More Things I Found While Poking Around

After Vienna, I got curious what else changed in the last century, so I ran the same kind of check across a big chunk of the time zones Postgres knows, just looking for years where the offset jumped by a lot or didn’t match a normal DST switch. A few that stood out:

  • Liberia used UTC-0:44:30 until 1972. It was one of the last countries in the world with a non-round time offset.
  • Kwajalein Atoll switched sides of the International Date Line twice: once in 1969 and again in 1993.
  • In 1995, Kiribati moved several of its islands across the date line at the same time, so that the whole country was finally on the same calendar day.
  • Tokelau made the same jump as Samoa, on the same date, at the end of 2011.
  • Danmarkshavn, a weather station in Greenland, stopped changing its clock altogether in 1996 and remained on UTC.
  • Davis Station in Antarctica was closed for a few years in the 1960s, and you can see that gap directly in the data.
  • Casey Station in Antarctica still switches between UTC+8 and UTC+11 depending on which coast of Australia its supply flights use that year.

None of this changes the point of the article. It was just interesting to see how much of this is already sitting in a database that most of us only ever use to store rows.


The History Book Hiding Inside Postgres was originally published in willhaben Tech Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.