Independent technical referenceOfficial site
  • Software and digital services
  • Databases

08004

PostgreSQL 08004 database error: server rejected new connection

Verified with sources3 sourcesReviewed Oct 19, 2026
Technician coming? See the 2 steps they must show you
Trace

Risk level

Medium

Proceed carefully and stop if the check is unclear.

Urgency

Medium

Quick answer

SQLSTATE 08004 (sqlserver_rejected_establishment_of_sqlconnection) means the client reached PostgreSQL, but the server actively refused to open the session. Check pg_isready and read the exact server error message before retrying.

Safety first

Stop and check this first

  • Never use SIGKILL (kill -9) to stop a PostgreSQL server that is disallowing connections during shutdown or recovery; SIGKILL prevents releasing shared memory and semaphores and leaves subprocesses running.
  • Never grant superuser or pg_use_reserved_connections to normal application accounts to bypass 08004 capacity rejections; doing so consumes the emergency administrative reserve.

Safe checks you can perform

  • Check server readiness state with pg_isready
  • Read the primary Message (M) and Detail (D) fields in ErrorResponse
  • Inspect max_connections, reserved slots, and pg_hba_file_rules

Leave these tasks to a qualified professional

  • Do not attempt this professional task: Update pg_hba.conf rules and reload configuration safely
  • Do not attempt this professional task: Right-size connection pooling or reserved connection parameters

What a technician must be able to justify

Technician visit

These are the steps they must carry out and show you. Tick them as they work: if steps are skipped, do not accept a part swap.

These are not instructions for opening or handling the equipment yourself. They are the checks that should support a technical conclusion.

  1. Update pg_hba.conf rules and reload configuration safely

    What they doHave the DBA add or reorder the specific host or hostssl record in pg_hba.conf with scram-sha-256 authentication, verify CONNECT privilege on the target database, call pg_reload_conf() or pg_ctl reload, and confirm clean loading in pg_hba_file_rules.

    They must show youthe pg_hba_file_rules query result showing the matched rule with a null error column after reload.

    In writingthe added pg_hba.conf record (type, database, user, CIDR address, auth-method) and the GRANT CONNECT statement if applied.

  2. Right-size connection pooling or reserved connection parameters

    What they doHave the DBA and application team cap total pool connections below max_connections minus superuser_reserved_connections and reserved_connections, or adjust max_connections at a planned server restart if kernel and shared memory resources allow.

    They must show youthe current connection count per application and the SHOW outputs for max_connections, reserved_connections, and superuser_reserved_connections.

    In writingthe per-instance pool size calculation and the configured server connection limits.

Before accepting a part or repair

Nothing has been shown yet. Do not accept a part swap based on the code alone.

Follow these steps

Note: Follow the documented order. An error code identifies the affected system, but it does not prove by itself which part has failed.

  1. Check server readiness state with pg_isready

    Tools required

    Who:
    Your developer or platform operator runs pg_isready against the target PostgreSQL host and port.
    How:
    Run pg_isready -h <hostname> -p <port> and inspect both the printed status line and the shell exit status.
    Result that matters:
    Exit status 1 (rejecting connections) corresponds to PQPING_REJECT, meaning the server process is running but in startup, shutdown, or crash recovery.
    If pg_isready returns 1 with rejecting connections, that confirms the cluster is in a lifecycle transition (startup, shutdown, or recovery) and rules out client network routing.
    If pg_isready returns 0 with accepting connections while the application still gets 08004, that points to connection slot exhaustion, pg_hba.conf rules, or role privileges.
    Evidence to keep:
    Record the exact pg_isready message, exit code, and timestamp.

    Do not attempt to force-restart a PostgreSQL cluster that is rejecting connections during WAL crash recovery.

    Evidence: PostgreSQL database connection control functions · PostgreSQL 18 pg_isready

  2. Read the primary Message (M) and Detail (D) fields in ErrorResponse

    No special tools

    Who:
    Your developer or DBA reviews the client exception and the PostgreSQL server log for the rejected attempt.
    How:
    Capture the unlocalized SQLSTATE (field C), primary Message (field M), and Detail (field D) from the failed login and match the timestamp in the server log.
    Result that matters:
    During the startup phase, the server sends ErrorResponse and immediately closes the connection, logging more detail in the server log than it sends to the client.
    If the message states that remaining connection slots are reserved or too many clients are already connected, that confirms max_connections saturation.
    If the message states no pg_hba.conf entry for host, user, and database, that isolates the rejection to host-based authentication rules or SSL/GSS encryption requirements.
    Evidence to keep:
    Keep the exact server log line with client IP, user, database name, and message text, redacting any secret values.

    Evidence: PostgreSQL error and notice fields · PostgreSQL 18 protocol message flow · PostgreSQL 18 authentication problems

  3. Inspect max_connections, reserved slots, and pg_hba_file_rules

    Tools required

    Who:
    Your DBA runs read-only catalog queries using an administrative session.
    How:
    Check SHOW max_connections, SHOW superuser_reserved_connections, and SHOW reserved_connections, and query pg_hba_file_rules to inspect active authentication records and any non-null error fields.
    Result that matters:
    By default, max_connections is typically 100 and superuser_reserved_connections is 3, and pg_hba_file_rules reveals rule order and syntax errors without editing files.
    If active connections equal or exceed max_connections minus the reserved connection settings, that confirms non-privileged logins are blocked by capacity limits.
    If connection slots are free but pg_hba_file_rules shows a matching reject rule, a hostssl mismatch, or no matching row for the client CIDR, that confirms an HBA policy rejection.
    Evidence to keep:
    Save the output of the SHOW commands and the relevant rows from pg_hba_file_rules.

    Never set auth-method to trust in pg_hba.conf or grant superuser to application roles to bypass reserved connection limits.

    Evidence: PostgreSQL connection settings · PostgreSQL 18 the pg_hba.conf file

Still not solved

If the error persists, stop here. See what the technician must do and show you.

Virtual technician

Does 08004 still appear after these checks?

This guided flow uses the exact code and your answers to choose a test, an expected result and the next branch.

Where this code applies

A code is meaningful only inside the right product and version context.

Primary scope

System
Software and digital services
Brand
PostgreSQL
Product type
Databases

Known code variants

  • PostgreSQL 08004
  • sqlserver_rejected_establishment_of_sqlconnection
  • SQLSTATE 08004

What it means

PostgreSQL Appendix A assigns 08004 to sqlserver_rejected_establishment_of_sqlconnection in Class 08 Connection Exception. Unlike an unreachable host or dead network link, 08004 means the server received the startup request and sent back an ErrorResponse before immediately closing the connection. Official causes include server startup, smart or fast shutdown, crash recovery (reported as PQPING_REJECT), exhausted max_connections slots where remaining slots belong to superuser_reserved_connections or reserved_connections, or host and privilege policy checks. Code 08004 alone does not prove which server gate refused the login.

Warnings and stop conditions

  • Highsource verified

    Never use SIGKILL (kill -9) to stop a PostgreSQL server that is disallowing connections during shutdown or recovery; SIGKILL prevents releasing shared memory and semaphores and leaves subprocesses running.

    Evidence: PostgreSQL server shutdown

  • Mediumsource verified

    Never grant superuser or pg_use_reserved_connections to normal application accounts to bypass 08004 capacity rejections; doing so consumes the emergency administrative reserve.

    Evidence: PostgreSQL connection settings

Symptoms and causes

Probable causes · in order

  • Server in startup, smart or fast shutdown, or crash recovery stateCommon

    When PostgreSQL is starting up, recovering by replaying WAL, or executing a SIGTERM smart shutdown or SIGINT fast shutdown, it is running but disallows new connections and returns PQPING_REJECT.

    Evidence: PostgreSQL database connection control functions · PostgreSQL server shutdown · PostgreSQL 18 pg_isready

  • Active sessions reached max_connections minus reserved slotsCommon

    Once concurrent sessions reach max_connections minus superuser_reserved_connections (default three) and reserved_connections, PostgreSQL rejects new connections from regular application roles.

    Evidence: PostgreSQL connection settings

  • Host-based authentication rule in pg_hba.conf refused the clientPossible

    PostgreSQL evaluates pg_hba.conf sequentially on each startup packet; if no record matches the connection type, client IP address, database, and user, or if a reject record matches first, access is denied.

    Evidence: PostgreSQL 18 authentication problems · PostgreSQL 18 the pg_hba.conf file

  • Missing CONNECT privilege or unsupported major protocol versionLess common

    Even after passing pg_hba.conf, a user without the CONNECT privilege on the target database or a client requesting an unsupported protocol version receives an ErrorResponse during startup.

    Evidence: PostgreSQL 18 frontend/backend protocol overview · PostgreSQL 18 protocol message flow · PostgreSQL 18 the pg_hba.conf file

Sources and technical references

  1. 1

    PostgreSQL 18 Appendix A: Error Codes

    PostgreSQL Global Development Group · 2026 · official_doc

  2. 2

    PostgreSQL error and notice fields

    PostgreSQL Global Development Group · 2026 · official_doc

  3. 3

    PostgreSQL database connection control functions

    PostgreSQL Global Development Group · 2026 · official_doc

Sources: PostgreSQL 18 Appendix A: Error Codes · PostgreSQL error and notice fields · PostgreSQL database connection control functionsreviewed 2026-10-19 · verified

Was this entry useful?