select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 55 · OBJECT NOT IN PREREQUISITE STATE

object_not_in_prerequisite_state

SQLSTATE
55000
Condition name
object_not_in_prerequisite_state
Class
Object Not In Prerequisite State
Source macro
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
Evidence
Observed at runtime in the source evidence
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>55000 — Object not in prerequisite state</h1>

At a glance

55000 means the requested operation lacks a required object or server state. This page selects the session-local sequence prerequisite behind currval; preload, recovery, and invalid-index paths are separate mechanisms.

Meaning

currval is defined per backend session. Creating a sequence, or calling nextval in another session, does not initialize the current session. The fixed sequence template is currval of sequence "%s" is not yet defined in this session with ERROR severity.

Other fixed 55000 paths have different prerequisites. pg_stat_statements reports pg_stat_statements must be loaded via "shared_preload_libraries"; add the extension to that startup setting and restart the server through the normal configuration procedure. pg_surgery reports recovery is in progress with detail Heap surgery functions cannot be executed during recovery.; wait for recovery to finish or run the operation on the appropriate writable primary. pgstattuple reports index "%s" is not valid; inspect the index and rebuild it with the appropriate REINDEX or migration procedure before using that function. These are object or server-state checks, not permission failures and not interchangeable with the session-local sequence case.

Diagnosis

Check the exact object state and the backend session that owns it. For this path, identify the sequence and verify whether this backend has called nextval; a pooled connection that ran nextval is a different prerequisite state. In an explicit transaction, a failed currval aborts the transaction, so issue ROLLBACK or ROLLBACK TO SAVEPOINT before repairing it. For other 55000 paths inspect recovery, preload settings, index validity, or object-specific prerequisites.

Response

Call nextval in the same backend before currval, or pass an explicitly known value when that is the intended contract. In autocommit, reconnecting or issuing the next statement is possible because the failed statement's transaction has ended; inside an explicit transaction, recover with a rollback or savepoint before calling nextval. Do not treat this as a privilege failure or assume a successful call from a pool’s different connection initializes the current one.

Observed diagnostics

The selected source group is ERROR with the dynamic sequence-name template above. Runtime diagnostics named currval_sequence; after the failure the autocommit session stayed IDLE, and the same session then returned 10 from nextval and currval.

Representative case

The selected registry creates the sequence and then, on one autocommit backend, calls currval before any nextval, initializes the sequence with nextval (returning 10), and reads currval again (returning 10). The failing call, repair, and verification are therefore one session-scoped state transition; this case does not test a connection-pool handoff.

CREATE SEQUENCE sequence_identifier START WITH 10;
SELECT currval('sequence_regclass');
SELECT nextval('sequence_regclass');
SELECT currval('sequence_regclass')

The selected PostgreSQL 18.6 and 10.21 runs passed SQLSTATE, severity, state or disconnect recovery, repair, cleanup, and isolated-target stop assertions. See case JSON and authored evidence.

Versions

The locked catalogue records 55000 from 7.4 through the listed snapshots. The sequence-session case passed on 18.6 and 10.21; these observations do not cover the other 55000 branches or infer every intermediate implementation.

Sources

  • src.errcodes.18.6src/backend/utils/errcodes.txt at 724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba (source).
  • src.currval.18.6src/backend/commands/sequence.c at 724edf9bde9d356724ad384a2e196edc3c9f80f7; blob SHA-256 3e5afe17d5a84862fae502a5481211220368f1d639e9d07ba6f96ee8be92a8d8 (source).
  • src.currval.10.23src/backend/commands/sequence.c at 02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; blob SHA-256 5510e1266e8d8c548a4318d753392e92e689d348f3353a2aa53d8dea871c44ab (source).
  • src.path.0contrib/pg_stat_statements/pg_stat_statements.c at 724edf9bde9d356724ad384a2e196edc3c9f80f7, the shared_preload_libraries guard (source).
  • src.path.1contrib/pg_surgery/heap_surgery.c at 724edf9bde9d356724ad384a2e196edc3c9f80f7, the recovery guard and detail (source).
  • src.path.2contrib/pgstattuple/pgstatindex.c at 724edf9bde9d356724ad384a2e196edc3c9f80f7, the invalid-index guard (source).
  • src.calls.REL_18_6 / src.calls.REL_10_23 — fixed call scans, SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf / 00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.
  • manifest.55000 / snippet-registry.55000 — hashes are recorded in evidence/55000.json and each selected runtime record.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

55000 is object_not_in_prerequisite_state in SQLSTATE Class 55.

Method: Read fixed definition.

src.errcodes.18.6

The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described.

Method: Read complete fixed source contexts.

Limits: Source confirmation is not natural runtime.

src.path.0 src.path.1 src.path.2

The locked catalogue records 55000 from 7.4; that boundary does not prove exact implementation introduction.

Method: Use catalogue boundary.

src.errcodes.18.6

The sequence currval path requires a prior nextval call in the same backend session and reports 55000 before that prerequisite exists; creating the sequence does not initialize the session-local last-value state.

Method: Read fixed sequence.c source-call records and compare same-session registry assertions.

Limits: Other 55000 paths represent different object or server states.

src.currval.18.6 src.currval.10.23

The currval_before_nextval case passed on isolated PostgreSQL 18.6 and 10.21 targets; nextval initialized currval on the same session and returned 10.

Method: Execute the shared registry and inspect SQLSTATE, severity, session state, repair, cleanup, and target stop.

Limits: Scope is limited to sequence session state and does not cover recovery, preload, or invalid-index branches.

manifest.55000 snippet-registry.55000

Message templates

ERROR · message.0

Primary

pg_stat_statements must be loaded via "shared_preload_libraries"
ERROR · message.1

Primary

recovery is in progress

Detail

Heap surgery functions cannot be executed during recovery.
ERROR · message.2

Primary

index "%s" is not valid
ERROR · message.currval.18.6

Primary

currval of sequence "%s" is not yet defined in this session
ERROR · message.currval.10.23

Primary

currval of sequence "%s" is not yet defined in this session

Reproduction & repair cases

currval_before_nextval · PG 10, 18

Preconditions

  • A runner-owned sequence exists.
  • The trigger and repair use one backend session.

Trigger: Call currval for a sequence before this backend has called nextval, then initialize and read it.

Expected assertions

  • SQLSTATE is 55000 with ERROR severity
  • The diagnostic says currval is not yet defined in this session
  • The failed autocommit session remains IDLE
  • nextval initializes currval on the same backend and both values are 10

Repair: Use nextval in the same session before currval, or pass an explicitly known value; creating the sequence in another session does not initialize this session’s currval state.

Cleanup: Close all runner connections and drop the case schema with an owner connection.

Recorded runtime evidence

18.6 (Homebrew) · passed

Run: ops-55000-latest-1

{
  "nextval": 10,
  "sequence": "\"c55000_currval_before_nextval\".\"currval_sequence\"",
  "diagnostic": {
    "text": "currval of sequence \"currval_sequence\" is not yet defined in this session",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "55000",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "sequence.c",
    "source_line": "887",
    "message_hint": null,
    "datatype_name": null,
    "exception_type": "ObjectNotInPrerequisiteState",
    "internal_query": null,
    "message_detail": null,
    "constraint_name": null,
    "message_primary": "currval of sequence \"currval_sequence\" is not yet defined in this session",
    "source_function": "currval_oid",
    "internal_position": null,
    "statement_position": null,
    "severity_nonlocalized": "ERROR"
  },
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "session_scope": "CREATE SEQUENCE, the failing currval, nextval, and repaired currval all ran on one autocommit backend session.",
  "connection_autocommit": true,
  "currval_after_nextval": 10
}
10.21 (Debian 10.21-1.pgdg90+1) · passed

Run: ops-55000-pg10-1

{
  "nextval": 10,
  "sequence": "\"c55000_currval_before_nextval\".\"currval_sequence\"",
  "diagnostic": {
    "text": "currval of sequence \"currval_sequence\" is not yet defined in this session",
    "context": null,
    "severity": "ERROR",
    "sqlstate": "55000",
    "table_name": null,
    "column_name": null,
    "schema_name": null,
    "source_file": "sequence.c",
    "source_line": "840",
    "message_hint": null,
    "datatype_name": null,
    "exception_type": "ObjectNotInPrerequisiteState",
    "internal_query": null,
    "message_detail": null,
    "constraint_name": null,
    "message_primary": "currval of sequence \"currval_sequence\" is not yet defined in this session",
    "source_function": "currval_oid",
    "internal_position": null,
    "statement_position": null,
    "severity_nonlocalized": "ERROR"
  },
  "failed_status": "IDLE",
  "repair_status": "IDLE",
  "session_scope": "CREATE SEQUENCE, the failing currval, nextval, and repaired currval all ran on one autocommit backend session.",
  "connection_autocommit": true,
  "currval_after_nextval": 10
}

Definition snapshot: english-manuals:130167bdf421a1e0f7412cebfb8… · English manual source