SQLSTATE 25000Severity lowLab verified

Incident brief

COPY FREEZE with prior transaction activity

COPY ... WITH (FREEZE) was attempted while a cursor was still open in the same transaction. PostgreSQL refused because it can no longer guarantee no one else can see the pre-freeze rows.

What lands in your log

ERROR: cannot perform COPY FREEZE because of prior transaction activity

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Start a transaction, create a new table, and open a cursor (DECLARE ... CURSOR) that is still open.
Fix
Run COPY ... FREEZE before opening any cursor, the table just needs to have been created or truncated in the current transaction, with no cursors or older snapshots yet.
Proof
Reproduced on PostgreSQL 16.14 → COPY ... WITH (FREEZE) was rejected with SQLSTATE 25000 while a cursor was still open in the same transaction. The identical COPY FREEZE succeeded once it ran before the cursor was opened.

Fix

What to do right now

Application-level steps for this error.

  • Run COPY ... FREEZE before opening any cursor, the table just needs to have been created or truncated in the current transaction, with no cursors or older snapshots yet.
  • Or move the cursor-based work into a separate transaction that runs after the COPY commits.
Fix SQL
DROP TABLE IF EXISTS batch8_freeze_demo;
BEGIN;
CREATE TABLE batch8_freeze_demo (id int);
COPY batch8_freeze_demo FROM STDIN WITH (FREEZE);
1
2
.
COMMIT;
SELECT * FROM batch8_freeze_demo ORDER BY id;

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops