Skip to content
Commitpedia
Log in Join & edit

Fix: psql connection to server on socket /var/run/postgresql/.s.PGSQL.5432 failed

psql tried the local Unix socket and found nothing there. The server is not running, listens on another port, or uses a different socket directory than your client expects.

Not checked by a trusted editor yet Last edited Outdated?

Edit history of Fix: psql connection to server on socket /var/run/postgresql/.s.PGSQL.5432 failed: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
2 min

On Debian, Ubuntu and similar systems the full error reads:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
	Is the server running locally and accepting connections on that socket?

When you run psql without -h, it connects through a Unix-domain socket, a special file whose name ends in the port number (.s.PGSQL.5432). “No such file or directory” means that file does not exist where psql looked, so no server is listening there. The server has not rejected you; psql never reached one.

Causes, most likely first

  1. The server is not running: it was never started, failed to start, or stopped after a reboot.
  2. It runs on a different port, for example 5433 because a second cluster or version was installed. The socket name then ends in .5433.
  3. Client and server disagree on the socket directory. The upstream default is /tmp, while Debian/Ubuntu packages use /var/run/postgresql. Mixing a psql or libpq from one source with a server from another (for example a source build, Homebrew or a different repository) causes exactly this message.
  4. The server runs in a container or on another machine, so there is no local socket at all.

Fix it step by step

  1. Check whether a server is running and on which port.
  2. If it is down, start it and read the log if it fails to start.
  3. If it runs on another port, connect with -p.
  4. If the socket is in another directory, point -h at that directory.
  5. If the server is elsewhere, connect over TCP with -h hostname.

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
pg_lsclusters
sudo systemctl status postgresql
ls -l /var/run/postgresql/ /tmp/.s.PGSQL.* 2>/dev/null
ss -ltnp | grep -i postgres

pg_lsclusters (Debian/Ubuntu) lists every cluster with its version, port, status and log file. If the status is down, start it and check why it stopped:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo pg_ctlcluster 18 main start
sudo systemctl start postgresql
sudo tail -n 30 /var/log/postgresql/postgresql-18-main.log

Common reasons for a failed start are a full disk, a typo in postgresql.conf, or another process already using the port; the log names the problem.

If the server runs but elsewhere, tell psql where:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo -u postgres psql -p 5433
sudo -u postgres psql -h /tmp
psql -h localhost -U appuser -d appdb

-h with a value that starts with / is treated as a socket directory; anything else is a host name for a TCP connection. The server’s own setting is unix_socket_directories (restart required), which you can check with SHOW unix_socket_directories; once you are connected.

Prevent it

  • Enable the service so it starts at boot: sudo systemctl enable postgresql (the unit is named postgresql-<version> for PGDG packages on RHEL-family systems).
  • Install the client and the server from the same source, and avoid several PostgreSQL installations on one machine unless you need them.
  • Use pg_isready in scripts to wait until the server accepts connections.

Official documentation

See also

  • 0198 Install PostgreSQL and connect with psql on Debian, Ubuntu and RHEL Install the PostgreSQL server from your distribution or the official PGDG repositories, start it, and open your first psql session as the… Beginner · How-to · Linux Article Install & connect 15 Oct 2026
  • 0199 psql meta-commands cheat sheet The backslash commands you use every day in psql: connecting, listing databases, tables and roles, describing objects, timing queries, expanded output and… Beginner · Reference · Any system Article Install & connect · Roles & administration 15 Oct 2026
  • 0201 pg_hba.conf and PostgreSQL authentication methods pg_hba.conf decides who may connect from where and how they must prove who they are. Rules are checked top to bottom and… Intermediate · Concept · Linux Article Install & connect · Security & access 15 Oct 2026
  • 0210 Fix: FATAL: no pg_hba.conf entry for host The server received the connection but no pg_hba.conf rule matches this client address, user, database and SSL mode. Add or correct a… Intermediate · Fix · Linux Article Install & connect · Security & access 15 Oct 2026
  • 0257 Run PostgreSQL properly on a Linux server: install, lock down, back up, monitor and patch Set up PostgreSQL 18 from the official repository for one application: a dedicated role and database, SCRAM logins from one app server… Intermediate · Tutorial · Linux Article Backup & restore · Install & connect · Roles & administration 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Commitpedia +3,067 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?