psql: could not connect to server: No such file or directory

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
postgresql DBA

psql: could not connect to server: No such file or directory

Error
psql: could not connect to server: No such file or directory

Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Step 1: Check if PostgreSQL is running

sudo systemctl status postgresql-15

If it’s inactive, you need to start it:

sudo systemctl start postgresql

Step 2: Verify Socket Directory

Check if the socket file exists:

ls -l /var/run/postgresql/

If .s.PGSQL.5432 is missing, PostgreSQL didn’t start properly.

Step 3: Connect via TCP (bypass socket)

psql -h 127.0.0.1 -U postgres

If this works, then the issue is only with the socket path.

Step 4: Check Logs

journalctl -u postgresql

Step 5: Remove Stale PID (if needed)

sudo rm -f /var/lib/pgsql/<version>/data/postmaster.pid
sudo systemctl restart postgresql

 

Conclusion

Tuning PostgreSQL for peak performance is a journey, but with a clear understanding of these configuration parameters, you’re well on your way to becoming a pro! At Learnomate Technologies, we’re here to support you every step of the way with top-notch training in PostgreSQL DBA and more.

For more detailed insights and tutorials, do check out our YouTube channelwww.youtube.com/@learnomate, where we regularly share practical tips and deep dives into essential database topics. And if you’re serious about mastering PostgreSQL DBA, head over to our website for our full training program: learnomate.org/training/postgresql-training/.

I’d love to connect with you, so don’t forget to follow my LinkedInhttps://www.linkedin.com/in/ankushthavali/. If you’re eager to read more about various technologies, explore our blog page here: https://learnomate.org/blogs/. Happy learning, and remember—tuning and training go hand-in-hand for database success!