Did you mean to connect to localhost:5432?

Did you mean to connect to: postgresql://localhost:5432?

Port 5432 is for PostgreSQL database connections. Use psql or your database client to connect.

💡 Pro Tip: Port 5432 is PostgreSQL's default port. If you're getting connection errors, check if PostgreSQL service is running and verify your credentials.

Quick Commands for PostgreSQL Port 5432

Check if PostgreSQL is running:
sudo systemctl status postgresql (Linux)
brew services list | grep postgresql (Mac)
pg_ctl status (Windows)
Connect to PostgreSQL:
psql -U postgres
psql -h localhost -p 5432 -U username -d database
Find what's using port 5432:
lsof -i :5432 (Mac/Linux)
netstat -ano | findstr :5432 (Windows)
Start PostgreSQL service:
sudo systemctl start postgresql (Linux)
brew services start postgresql (Mac)
pg_ctl start (Windows)

About Port 5432

Port 5432 is the default port for:

Common PostgreSQL Connection Issues

"psql: could not connect to server: Connection refused"

PostgreSQL server is not running or not accepting connections:

Solutions:

  • Start PostgreSQL: sudo systemctl start postgresql
  • Check if PostgreSQL is installed: psql --version
  • Verify PostgreSQL is listening: sudo netstat -tlnp | grep 5432
  • Check PostgreSQL logs: sudo tail -f /var/log/postgresql/postgresql-*.log

"psql: FATAL: password authentication failed"

Authentication error when connecting to PostgreSQL:

Solutions:

  • Reset PostgreSQL password:
    sudo -u postgres psql
    ALTER USER postgres PASSWORD 'newpassword';
  • Use peer authentication: sudo -u postgres psql
  • Check pg_hba.conf authentication settings
  • Create new user:
    CREATE USER username WITH PASSWORD 'password';
    GRANT ALL PRIVILEGES ON DATABASE dbname TO username;

"psql: FATAL: database does not exist"

Trying to connect to a non-existent database:

Solutions:

  • List available databases: \l in psql
  • Connect to default database: psql -U postgres
  • Create database: CREATE DATABASE dbname;
  • Check database name spelling

"Port 5432 is already in use"

Another process is using PostgreSQL's port:

Solutions:

  • Find the process: lsof -i :5432
  • Stop existing PostgreSQL: sudo systemctl stop postgresql
  • Change PostgreSQL port in postgresql.conf:
    port = 5433
  • Restart PostgreSQL: sudo systemctl restart postgresql

"psql: FATAL: role does not exist"

PostgreSQL user/role doesn't exist:

Solutions:

  • Create role: sudo -u postgres createuser --interactive
  • Or in psql: CREATE ROLE username LOGIN PASSWORD 'password';
  • List existing roles: \du in psql
  • Use existing superuser: psql -U postgres

Useful PostgreSQL Resources