# timestamp vs timestamptz in Postgres: what's actually stored, and how to switch without a rewrite

Neither PostgreSQL timestamp type stores a time zone. Both are 8 bytes, and the difference is how values are converted on the way in and out. Measured on Postgres 17.11: session TimeZone bugs, AT TIME ZONE in both directions, daylight saving time, grouping by day, expression indexes, and how to change a 5-million-row column from timestamp to timestamptz without rewriting the table.

**"Use `timestamptz`" is standard advice about time in PostgreSQL, and a common explanation of it, that `timestamptz` stores a time zone, is wrong. `timestamp with time zone` doesn't store a time zone. Both types are 8 bytes holding the same kind of number; what differs is whether Postgres converts the value using the session's `TimeZone` on the way in and on the way out. This post shows exactly what gets stored, the bugs that come from mixing the two, and how to move an existing `timestamp` column to `timestamptz`: on a 5-million-row table the change took 2 seconds instead of 13 once we ran it in a UTC session without a `USING` clause. Every statement and every output below was run on PostgreSQL 17.11, the major version Relyt One runs.**

## The short answer

- **Storing when something happened** (`created_at`, `paid_at`, log times): use `timestamptz`. It always means one instant, no matter which session wrote it or reads it.
- **Storing a time on someone's wall clock in the future** ("standup at 09:00 Berlin time next April"): store a `timestamp` plus the zone name in a second column, and convert when you need the instant.
- **Already have `timestamp` columns full of UTC values?** Switch them with `SET timezone = 'UTC'` and a plain `ALTER COLUMN ... TYPE timestamptz`. Postgres skips the table rewrite, though it still rebuilds indexes on the column and takes an `ACCESS EXCLUSIVE` lock.
- **Already have `timestamp` columns in some local time?** Convert with an explicit `USING created_at AT TIME ZONE 'Zone/Name'`. That rewrites the table. Rehearse it on a copy first.

## What each type actually stores

Start with one table, one row, two columns, and change the session time zone between writing and reading:

```sql
CREATE TABLE events (
  local_ts timestamp,     -- timestamp without time zone
  utc_ts   timestamptz    -- timestamp with time zone
);

SET timezone = 'America/New_York';
INSERT INTO events VALUES ('2026-12-01 09:00', '2026-12-01 09:00');

SET timezone = 'Asia/Tokyo';
SELECT local_ts, utc_ts FROM events;
--       local_ts       |         utc_ts
-- ---------------------+------------------------
--  2026-12-01 09:00:00 | 2026-12-01 23:00:00+09

SET timezone = 'UTC';
SELECT local_ts, utc_ts FROM events;
--  2026-12-01 09:00:00 | 2026-12-01 14:00:00+00
```

The `timestamptz` value was read as 09:00 New York time, converted to UTC (14:00) and stored. Tokyo and UTC sessions each display that same instant in their own zone. The `timestamp` value was stored as the digits you typed, and every session gets those digits back. Nobody can tell from the row alone that it meant New York.

The [PostgreSQL manual](https://www.postgresql.org/docs/17/datatype-datetime.html) says it directly: a `timestamptz` value "is stored internally as UTC, and the originally stated or assumed time zone is not retained." You can see it in the bytes. Both types are 8 bytes (`pg_column_size` returns 8 for each), and the binary send functions produce the same bytes for the same instant:

```sql
SELECT timestamp_send('2026-12-01 14:00'::timestamp)        AS ts_bytes,
       timestamptz_send('2026-12-01 14:00+00'::timestamptz) AS tstz_bytes;
--       ts_bytes      |     tstz_bytes
-- --------------------+--------------------
--  \x00030491b5fa9800 | \x00030491b5fa9800
```

That's a count of microseconds since 2000-01-01. The types differ only in what the count means: an instant, or a reading on an unspecified clock.

One more difference catches people at input. A `timestamp` silently drops any offset you give it:

```sql
SET timezone = 'UTC';
SELECT '2026-12-01 09:00-05'::timestamp   AS ts,
       '2026-12-01 09:00-05'::timestamptz AS tstz;
--          ts          |          tstz
-- ---------------------+------------------------
--  2026-12-01 09:00:00 | 2026-12-01 14:00:00+00
```

No error and no warning. The manual documents it: for `timestamp`, "PostgreSQL will silently ignore any time zone indication." And because the SQL standard says plain `timestamp` means `timestamp without time zone`, that's the type you get whenever a migration or an ORM writes just `timestamp`.

![Both types store 8 bytes. timestamptz converts with the session TimeZone on input and output; timestamp stores and returns the digits unchanged.](/blog/assets/549af8eeaa8274e2.svg)

## Where `timestamp` goes wrong

None of the following is a Postgres bug. Each one is `timestamp` doing exactly what it is defined to do, in a system where sessions don't all share one time zone.

### Two app servers, one column, eight hours apart

`now()` returns a `timestamptz`. Assigning it to a `timestamp` column converts it to the wall-clock time of the session's `TimeZone`. Here two sessions insert in the same transaction, so `now()` is the same instant for both:

```sql
CREATE TABLE signups (who text, created_at timestamp DEFAULT now());

BEGIN;
SET LOCAL timezone = 'UTC';
INSERT INTO signups (who) VALUES ('server in UTC');
SET LOCAL timezone = 'Asia/Shanghai';
INSERT INTO signups (who) VALUES ('server in Shanghai');
COMMIT;

SELECT who, created_at FROM signups ORDER BY who;
--         who         |         created_at
-- --------------------+----------------------------
--  server in Shanghai | 2026-12-01 21:07:26.359525
--  server in UTC      | 2026-12-01 13:07:26.359525

SELECT max(created_at) - min(created_at) AS apparent_gap FROM signups;
--  08:00:00
```

The same moment is stored eight hours apart. In production this happens when one service sets `TimeZone` in its connection string and another doesn't, or when someone runs a backfill from a laptop. With `timestamptz` both rows would hold the same value.

### Filters that change with the reader

Comparing a `timestamp` with a `timestamptz` is allowed. The manual explains how: the `timestamp` "is assumed to be given in the time zone specified by the TimeZone configuration parameter." So the same query returns different rows for different clients:

```sql
-- the app writes UTC wall-clock times into a timestamp column
CREATE TABLE jobs (id int, finished_at timestamp);
INSERT INTO jobs VALUES (1, timestamp '2026-12-01 13:30');  -- 13:30 UTC

-- "finished in the last hour", asked at 14:00 UTC
SET timezone = 'UTC';
SELECT count(*) FROM jobs
WHERE finished_at > timestamptz '2026-12-01 14:00+00' - interval '1 hour';   -- 1

SET timezone = 'Asia/Shanghai';
SELECT count(*) FROM jobs
WHERE finished_at > timestamptz '2026-12-01 14:00+00' - interval '1 hour';   -- 0
```

In real code the right-hand side is `now() - interval '1 hour'`, and the conversion happens without anyone writing it.

### Durations across a daylight saving change

US clocks went back one hour on 1 November 2026. A `timestamp` doesn't know that:

```sql
SET timezone = 'America/New_York';
SELECT timestamptz '2026-11-01 12:00' - timestamptz '2026-10-31 12:00' AS tstz_elapsed,
       timestamp   '2026-11-01 12:00' - timestamp   '2026-10-31 12:00' AS ts_elapsed;
--   tstz_elapsed  | ts_elapsed
-- ----------------+------------
--  1 day 01:00:00 | 1 day
```

25 hours really passed. If you bill by the hour, or alert when a job runs longer than 24 hours, the `timestamp` answer is wrong twice a year.

`timestamptz` arithmetic also lets you choose between calendar time and elapsed time:

```sql
SELECT timestamptz '2026-10-31 12:00' + interval '1 day'    AS plus_1_day,
       timestamptz '2026-10-31 12:00' + interval '24 hours' AS plus_24_hours;
--        plus_1_day       |     plus_24_hours
-- ------------------------+------------------------
--  2026-11-01 12:00:00-05 | 2026-11-01 11:00:00-05
```

`'1 day'` keeps the wall-clock time ("same time tomorrow"); `'24 hours'` adds exactly 24 hours. Both are correct, for different questions.

Wall-clock input that falls inside a transition is accepted rather than rejected. `'2026-03-08 02:30'` never happened in New York (clocks jumped from 02:00 to 03:00) and becomes `03:30-04`. `'2026-11-01 01:30'` happened twice and becomes `01:30-05`, the second one. The rule is in [Appendix B.2](https://www.postgresql.org/docs/17/datetime-invalid-input.html): a nonexistent time gets the offset from just before the jump, an ambiguous one the offset from just after. If you collect local times from users, validate them in the app.

## `AT TIME ZONE` goes both ways

`AT TIME ZONE` is the tool for moving between the two types, and it does opposite things depending on its input:

- `timestamptz AT TIME ZONE 'America/New_York'` returns a `timestamp`: what a clock in New York showed at that instant.
- `timestamp AT TIME ZONE 'America/New_York'` returns a `timestamptz`: the instant when a clock in New York showed that time.

```sql
SET timezone = 'UTC';
SELECT timestamptz '2026-12-01 14:00+00' AT TIME ZONE 'America/New_York';
--  2026-12-01 09:00:00        (timestamp without time zone)
SELECT timestamp '2026-12-01 09:00' AT TIME ZONE 'America/New_York';
--  2026-12-01 14:00:00+00     (timestamp with time zone)
```

You'll often see `created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/New_York'` copied from an answer online. That idiom is for a `timestamp` column that holds UTC: the first step turns it into an instant, the second into New York wall-clock time. Use it on a `timestamptz` column and you get the wrong hour:

```sql
SELECT timestamptz '2026-12-01 14:00+00' AT TIME ZONE 'UTC' AT TIME ZONE 'America/New_York';
--  2026-12-01 19:00:00+00      -- should be 09:00 in New York
```

For a `timestamptz` column, one `AT TIME ZONE` is all you need.

Use zone names such as `America/New_York`, not offsets written as text. A string like `'UTC-5'` is parsed as a POSIX zone, where [the sign is reversed](https://www.postgresql.org/docs/17/datetime-posix-timezone-specs.html) ("the positive sign is used for zones west of Greenwich"):

```sql
SELECT timestamptz '2026-12-01 14:00+00' AT TIME ZONE 'UTC-5'            AS posix_text,
       timestamptz '2026-12-01 14:00+00' AT TIME ZONE INTERVAL '-05:00'  AS iso_interval;
--      posix_text      |    iso_interval
-- ---------------------+---------------------
--  2026-12-01 19:00:00 | 2026-12-01 09:00:00
```

A fixed offset is also wrong for part of the year anywhere that has daylight saving time. A zone name follows the rules.

## Counting per day

"Orders per day" means per day somewhere. With `timestamptz`, a cast to `date` uses the session's zone, so the same data gives different reports:

```sql
CREATE TABLE orders (id int, created_at timestamptz);
INSERT INTO orders VALUES
  (1, '2026-11-30 23:30+00'), (2, '2026-12-01 01:15+00'),
  (3, '2026-12-01 15:45+00'), (4, '2026-12-01 16:30+00');

SET timezone = 'UTC';
SELECT created_at::date AS day, count(*) FROM orders GROUP BY 1 ORDER BY 1;
--  2026-11-30 | 1
--  2026-12-01 | 3

SET timezone = 'Asia/Shanghai';
SELECT created_at::date AS day, count(*) FROM orders GROUP BY 1 ORDER BY 1;
--  2026-12-01 | 3
--  2026-12-02 | 1
```

Both are right for their zone. A dashboard should name the zone in the query rather than inherit it from whatever connection runs the report:

```sql
SELECT (created_at AT TIME ZONE 'Asia/Shanghai')::date AS day, count(*)
FROM orders GROUP BY 1 ORDER BY 1;

-- or keep a timestamptz for the start of each day
SELECT date_trunc('day', created_at, 'Asia/Shanghai') AS day_start, count(*)
FROM orders GROUP BY 1 ORDER BY 1;
```

The zone matters for indexes too. An index expression must be immutable, and anything that depends on the session `TimeZone` isn't:

```sql
CREATE INDEX ON orders ((created_at::date));
-- ERROR:  functions in index expression must be marked IMMUTABLE

CREATE INDEX orders_day_shanghai
  ON orders (((created_at AT TIME ZONE 'Asia/Shanghai')::date));
-- CREATE INDEX
```

In `pg_proc`, `date(timestamptz)` and the two-argument `date_trunc` are marked stable; `timezone(text, timestamptz)` (the function behind `AT TIME ZONE`) and the three-argument `date_trunc` are immutable. For the index to be used, write the same expression in the query.

## When `timestamp` is the right type

Some times are wall-clock times on purpose. A meeting at 09:00 Berlin time next April should still be at 09:00 Berlin time if daylight saving rules change before then. Converting it to UTC today would freeze today's rules. Store the local time and the zone:

```sql
CREATE TABLE meetings (title text, starts_local timestamp, tz text);
INSERT INTO meetings VALUES ('standup', '2027-04-06 09:00', 'Europe/Berlin');

SET timezone = 'UTC';
SELECT title, starts_local AT TIME ZONE tz AS starts_at FROM meetings;
--   title  |       starts_at
-- ---------+------------------------
--  standup | 2027-04-06 07:00:00+00
```

Opening hours, recurring schedules and birthdays fit the same pattern (a birthday is really a `date`). Everything that records when something happened belongs in `timestamptz`. The PostgreSQL wiki's [Don't Do This](https://wiki.postgresql.org/wiki/Don't_Do_This) page makes the same call: "Don't use the timestamp type to store timestamps, use timestamptz (also known as timestamp with time zone) instead."

## Switching an existing column without a rewrite

`ALTER COLUMN ... TYPE` normally rewrites the whole table and its indexes while holding an `ACCESS EXCLUSIVE` lock. PostgreSQL 12 added an exception for this exact change: when the session time zone is UTC, `timestamp` and `timestamptz` are binary compatible (the [release notes](https://www.postgresql.org/docs/release/12.0/) say so in those words), so there's nothing to rewrite.

We measured it on a table of 5 million rows (925 MB including a primary key and an index on `created_at`), in a Docker container on a laptop. `relfilenode` changes when Postgres writes a new copy of a table or index, so comparing it before and after shows what was rewritten:

```sql
CREATE TABLE events (
  id         bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  created_at timestamp NOT NULL,
  payload    text
);
INSERT INTO events (created_at, payload)
SELECT timestamp '2026-01-01' + g * interval '3 seconds', repeat('x', 100)
FROM generate_series(1, 5000000) g;
CREATE INDEX events_created_at_idx ON events (created_at);
VACUUM ANALYZE events;

CREATE TEMP TABLE before AS
SELECT relname, relfilenode FROM pg_class
WHERE relname IN ('events', 'events_created_at_idx');

SET timezone = 'UTC';
BEGIN;
ALTER TABLE events ALTER COLUMN created_at TYPE timestamptz;
SELECT c.relname, b.relfilenode = c.relfilenode AS same_file
FROM pg_class c JOIN before b USING (relname) ORDER BY 1;
COMMIT;
```

We ran the `ALTER` three ways, rolling back the first two:

| Variant          | Time (s) | Rewritten    |
| ---------------- | -------- | ------------ |
| New York session | 13.4     | table, index |
| UTC + USING      | 10.9     | table, index |
| UTC, no USING    | 2.0      | index only   |

The 2 seconds are the rebuild of `events_created_at_idx`. The manual's [`ALTER TABLE` notes](https://www.postgresql.org/docs/17/sql-altertable.html) explain why it isn't skipped: indexes "must always be rebuilt unless the system can verify that the new index would be logically equivalent to the existing one." On a copy of the table without that index the same `ALTER` took 1.2 ms. Even then it took an `AccessExclusiveLock` (we checked `pg_locks` inside the transaction), so it still has to wait until no other transaction holds a lock on the table, and every query that arrives meanwhile waits behind it.

The fast path only applies when it's also correct, and that's the part to check:

1. **Find out what the values mean.** The shortcut reads every existing value as UTC. If the column has always been written by sessions in UTC, that's right. If it was written in local time, convert with an explicit `USING created_at AT TIME ZONE 'America/New_York'` (or whatever the zone was), which rewrites the table. If different writers used different zones, a single conversion is wrong for some rows: first work out which rows came from which writer (an application column, deploy history, logs), then use a `CASE` in `USING`.
2. **Set the session zone explicitly.** `SET timezone = 'UTC'` in the same session as the `ALTER`. Don't assume your migration tool's connection is already in UTC; check with `SHOW timezone`.
3. **Leave out `USING`.** `USING created_at AT TIME ZONE 'UTC'` produces the same values, but Postgres can't tell, and it forced a full rewrite.
4. **Set a `lock_timeout`** so the `ALTER` gives up instead of queueing every other query behind it, and retry. Our post on [migrations that lock your table](/blog/postgres-migration-locks) shows the lock queue and the retry pattern.
5. **Budget for index rebuilds.** Every index that includes the column is rebuilt under that lock. On a large table that can take minutes.

After the change, the stored bytes are the same and only the meaning is new. A UTC session reads `2026-01-01 00:00:03+00`, the same digits it read before, now as an instant.

## A checklist

- [ ] New columns that record when something happened: `timestamptz`, with `DEFAULT now()` if needed.
- [ ] Future wall-clock times: `timestamp` plus a zone name column.
- [ ] Check your ORM's migrations for a bare `timestamp` type.
- [ ] Reports that group by day name the zone: `AT TIME ZONE 'Zone/Name'` or `date_trunc(..., 'Zone/Name')`.
- [ ] Use zone names, not `'UTC-5'` strings.
- [ ] To convert `timestamp` columns that hold UTC: `SET timezone = 'UTC'`, no `USING`, a `lock_timeout`, and a plan for index rebuilds.

## Try it on a branch first

Everything above is plain PostgreSQL 17. What you can't learn from a blog post is how your own data behaves: which writers used which `TimeZone`, how long your indexes take to rebuild, and whether the `ALTER` is fast or rewrites. On Relyt One, a branch is a good place to find out. It starts from the parent's data with copy-on-write storage and runs on its own compute, so you can run the real `ALTER` on real data, compare `relfilenode`, time the index rebuilds and check your reports, then delete the branch, without touching production.

The manual's [Date/Time Types](https://www.postgresql.org/docs/17/datatype-datetime.html) and [Date/Time Functions](https://www.postgresql.org/docs/17/functions-datetime.html) chapters cover the details used here.

[Start for free](/auth/signin?ref=blog-postgres-timestamp-vs-timestamptz)
