↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

57P04 — database_dropped

57P04 is selected when a recovery conflict terminates a session because the connected database must be dropped. The same recovery-conflict primary is used for other conflict reasons, but those branches select 40001; the database-dropped guard is the condition identity that matters here.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Operator Intervention
condition name
database_dropped
lang
en
sqlstate
57P04

Definition PG 18

57P04

At a glance {#at-a-glance}

57P04 is selected when a recovery conflict terminates a session because the connected database must be dropped. The same recovery-conflict primary is used for other conflict reasons, but those branches select 40001; the database-dropped guard is the condition identity that matters here.

Meaning {#meaning}

The fixed call site uses FATAL with primary terminating connection due to conflict with recovery, dynamic recovery-conflict detail, and hint In a moment you should be able to reconnect to the database and repeat your command.. The SQLSTATE expression is explicit: ERRCODE_DATABASE_DROPPED is selected only when reason == PROCSIG_RECOVERY_CONFLICT_DATABASE; other reasons in this terminating branch use ERRCODE_T_R_SERIALIZATION_FAILURE. For the database branch, the detail is User was connected to a database that must be dropped..

Messages {#messages}

  • Primary: terminating connection due to conflict with recovery, FATAL.
  • Database-drop detail: User was connected to a database that must be dropped.
  • Hint: In a moment you should be able to reconnect to the database and repeat your command.
  • Other recovery-conflict reasons can reuse the primary but select 40001 and a different detail; do not label them 57P04 from the primary alone.

Diagnosis {#diagnosis}

Preserve SQLSTATE, primary/detail/hint, database name, backend PID, recovery-conflict reason, and standby/recovery logs. Confirm that the detail identifies the dropped database before treating the condition as 57P04. The FATAL report closes the connection, so there is no session in which to issue ROLLBACK. Check whether the interrupted operation could have committed before disconnection.

Response {#response}

Wait for the recovery conflict/database transition to clear, reconnect to a valid database, and verify durable business state before replaying a non-idempotent operation. If the server reports another recovery-conflict detail with 40001, apply serialization/retry handling instead. Do not repeatedly reconnect while the database is still being dropped or while recovery logs show the conflict is active.

Versions {#versions}

The locked catalogue records this condition from 9.0.4; that boundary does not prove the exact implementation-introduction version. Fixed source coverage is PostgreSQL 18.6.

Related {#related}

57P03, 57P02, 40001

Sources {#sources}

src/backend/tcop/postgres.c#L3233-3248

src/backend/tcop/postgres.c#L2549-2578

The structured evidence record records the SQLSTATE guard, dynamic detail, and source/runtime boundary.

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "57P04 is database_dropped in SQLSTATE Class 57."
}
claims · resolved-paths
{
  "claim_id": "resolved-paths",
  "limits": "Source confirmation is not natural runtime.",
  "method": "Read complete fixed source contexts.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.path.1"
  ],
  "statement": "The cited PostgreSQL 18.6 source paths support the concrete phase, message, and lifecycle boundary described."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 57P04 from 9.0.4; that boundary does not prove exact implementation introduction."
}
claims · database-guard
{
  "claim_id": "database-guard",
  "limits": "",
  "method": "Read the complete guard and errdetail_recovery_conflict helper.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.path.0",
    "src.path.1"
  ],
  "statement": "The terminating recovery-conflict call selects ERRCODE_DATABASE_DROPPED only for PROCSIG_RECOVERY_CONFLICT_DATABASE; other reasons select ERRCODE_T_R_SERIALIZATION_FAILURE and use a different detail."
}
messages · message.0
{
  "limits": "",
  "message_id": "message.0",
  "path": "",
  "position": 0,
  "raw": {
    "detail_template": "User was connected to a database that must be dropped.",
    "hint_template": "In a moment you should be able to reconnect to the database and repeat your command.",
    "id": "message.0",
    "primary_template": "terminating connection due to conflict with recovery",
    "severity_source": "FATAL",
    "sources": [
      "src.path.0",
      "src.path.1"
    ],
    "sqlstate": "57P04"
  },
  "severity": "FATAL",
  "sources": [
    "src.path.0",
    "src.path.1"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "terminating connection due to conflict with recovery",
      "position": 0,
      "role": "",
      "template": "terminating connection due to conflict with recovery"
    },
    {
      "kind": "detail",
      "literal": "User was connected to a database that must be dropped.",
      "position": 1,
      "role": "",
      "template": "User was connected to a database that must be dropped."
    },
    {
      "kind": "hint",
      "literal": "In a moment you should be able to reconnect to the database and repeat your command.",
      "position": 2,
      "role": "",
      "template": "In a moment you should be able to reconnect to the database and repeat your command."
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L438"
}
sources · src.path.0
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/postgres.c",
  "position": 1,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.path.0",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L3241"
}
sources · src.path.1
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/tcop/postgres.c",
  "position": 2,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.path.1",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L2549"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:c60274ce03a97e641e0dde66c8ccba6f99f45be2b281224088beb143c5179fd3

Text language: en · english-manuals:c60274ce03a97e641e0dde66c8ccba6f99f45be2b281224088beb143c5179fd3