Software⏱️ 2 min read📅 2026-05-31

How to Fix: psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory

Error resolving PostgreSQL connection.

Quick Answer: Try resetting the PostgreSQL socket directory by running `brew link postgresql --overwrite` and then try connecting again.

To resolve the 'psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory' issue, it's essential to understand that this error typically occurs when your terminal is closed while connected to a PostgreSQL database.

⚠️ Common Causes

  • Exiting the terminal while connected to a PostgreSQL database.

✅ Best Solutions to Fix It

Method 1: Restarting PostgreSQL

  1. Step 1: Open a new terminal and run brew services restart postgresql to restart the PostgreSQL service.

Method 2: Reconnecting to the Database

  1. Step 1: Open a new terminal and run psql -U your_username -d your_database_name to reconnect to your PostgreSQL database.

🎯 Final Words

By following these steps, you should be able to resolve the 'psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory' issue and regain access to your PostgreSQL database.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions