72000
PostgreSQLERRORNotableSnapshotHIGH confidence

Snapshot too old — query snapshot has expired

Production Risk

Medium — query fails but no data corruption; retry in a fresh transaction.

What this means

The query is reading data from a snapshot that has expired because old_snapshot_threshold is set and the snapshot is older than the threshold. PostgreSQL raises this error rather than return results that could be stale beyond the configured tolerance.

Why it happens
  1. 1old_snapshot_threshold is set to a low value (e.g. 1min) in postgresql.conf.
  2. 2A long-running transaction is reading old MVCC data beyond the threshold.
  3. 3Query paused mid-execution (e.g. cursor) past the snapshot threshold.
  4. 4Application holds an idle-in-transaction connection with an open snapshot.
How to reproduce
trigger — this will error
trigger — this will error
SET old_snapshot_threshold = '1min';
-- Wait 1 minute then:
SELECT * FROM large_table;

expected output

ERROR:  snapshot too old

Fix 1

Increase or disable old_snapshot_threshold

Increase or disable old_snapshot_threshold
-- In postgresql.conf:
old_snapshot_threshold = -1  -- disable entirely
-- or increase the window:
old_snapshot_threshold = '60min'

Why this works

Setting to -1 disables the feature entirely; increasing the threshold allows older snapshots to remain valid longer.

Fix 2

Retry the query in a fresh transaction

Retry the query in a fresh transaction
-- Close and reopen the transaction to get a newer snapshot
COMMIT;
BEGIN;
SELECT * FROM large_table;

Why this works

Starting a new transaction acquires a fresh snapshot that is within the threshold.

Fix 3

Break long-running queries into smaller batches

Break long-running queries into smaller batches
-- Use keyset pagination to avoid holding a snapshot for too long
SELECT * FROM large_table WHERE id > :last_id ORDER BY id LIMIT 10000;

Why this works

Smaller batches complete within the snapshot threshold window.

What not to do

Do not set old_snapshot_threshold to very low values (< 1 hour) on OLTP workloads

Legitimate long queries and analytics will start failing with this error unexpectedly

Version notes
9.6

old_snapshot_threshold and error code 72000 introduced in PostgreSQL 9.6

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors