Snapshot too old — query snapshot has expired
Production Risk
Medium — query fails but no data corruption; retry in a fresh transaction.
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.
- 1old_snapshot_threshold is set to a low value (e.g. 1min) in postgresql.conf.
- 2A long-running transaction is reading old MVCC data beyond the threshold.
- 3Query paused mid-execution (e.g. cursor) past the snapshot threshold.
- 4Application holds an idle-in-transaction connection with an open snapshot.
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
-- 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
-- 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
-- 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.
✕ 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
old_snapshot_threshold and error code 72000 introduced in PostgreSQL 9.6
PostgreSQL 17 — 72000 snapshot_too_old
https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-OLD-SNAPSHOT-THRESHOLD ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev