Software⏱️ 2 min read📅 2026-06-03

How to Fix: Psql could not connect to server: No such file or directory, 5432 error?

PSQL connection error on Vagrant Ubuntu box

Quick Answer: Check if PostgreSQL server is running and configured correctly, ensure the socket file exists in /var/run/postgresql/.s.PGSQL.5432.

The error message 'No such file or directory' indicates that the PostgreSQL server is not running on the specified Unix domain socket. To resolve this issue, follow these steps:

🚀 How to Resolve This Issue

Method 1: Start PostgreSQL Server

  1. Step 1: Run the command sudo service postgresql start to start the PostgreSQL server.

Method 2: Configure PostgreSQL Server to Listen on All Interfaces

  1. Step 1: Edit the /etc/postgresql/common/postgres.conf file and add the following line: `listen_addresses = '*'. This tells PostgreSQL to listen on all available network interfaces.

🎯 Final Words

After implementing these steps, restart the PostgreSQL server by running sudo service postgresql restart and try connecting to it using psql again. If you still encounter issues, ensure that the PostgreSQL server is properly configured and running on your Vagrant machine.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions