SQLSTATE 34000Severity lowLab verified

Incident brief

Cursor does not exist

A CLOSE (or FETCH/MOVE) named a cursor that was never declared, or was already closed. PostgreSQL has no OPEN statement, a cursor exists only once you DECLARE it.

What lands in your log

ERROR: cursor "order_cursor" does not exist

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

In 10 seconds

What triggers it
Begin a transaction.
Fix
DECLARE the cursor before you FETCH, MOVE, or CLOSE it, there is no implicit OPEN.
Proof
Reproduced on PostgreSQL 16.14 → CLOSE of an undeclared cursor was rejected with SQLSTATE 34000, aborting the transaction. Declaring the cursor first let FETCH and CLOSE succeed.

Fix

What to do right now

Application-level steps for this error.

  • DECLARE the cursor before you FETCH, MOVE, or CLOSE it, there is no implicit OPEN.
  • Remember non-holdable cursors are implicitly closed at COMMIT/ROLLBACK; don't reuse the name across transactions.
  • Query pg_cursors to see which cursors are actually open in the current session.
Fix SQL
-- declare the cursor before you FETCH or CLOSE it
BEGIN;
DECLARE order_cursor CURSOR FOR SELECT g FROM generate_series(1, 3) AS g;
FETCH ALL FROM order_cursor;
CLOSE order_cursor;
COMMIT;

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-19 (isolated 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