Back to lessons

Hosting Operations

Check Whether PostgreSQL Is Accepting Connections

An app cannot reach PostgreSQL and you need a quick first-response check before digging into logs or credentials.

Command

pg_isready -h 127.0.0.1 -p 5432

What changed

Nothing changes. pg_isready reports whether the server accepts connections.

Danger

safe

When to use it

Use during deploys, incident triage, service restarts, and health checks.

When not to use it

Do not treat readiness as proof that a specific user, database, or query works.

Undo or recovery

No undo needed because this command is read-only.

Expected output

A line showing host, port, and whether PostgreSQL is accepting connections.

demo script

Disposable terminal steps

  1. pg_isready -h 127.0.0.1 -p 5432
  2. pg_isready -h 127.0.0.1 -p 15432 || true
  3. ss -ltnp | grep ':5432'

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ pg_isready -h 127.0.0.1 -p 5432
127.0.0.1:5432 - accepting connections
::exit-code::0
$ pg_isready -h 127.0.0.1 -p 15432 || true
127.0.0.1:15432 - no response
::exit-code::0
$ ss -ltnp | grep ':5432'
LISTEN 0      128    127.0.0.1:5432      0.0.0.0:* users:(("postgres",pid=421,fd=5))
::exit-code::0

YouTube Short

Check Postgres readiness first.

Before changing configs, ask PostgreSQL whether it is accepting connections on the expected host and port.

LinkedIn hook

The database was running, but it was not ready.

Question: When an app cannot reach Postgres, do you check readiness before logs?

experiments

A/B tests to run

Metric: short_save_rate

A: The database was running, but it was not ready.

B: Check Postgres readiness before changing config.