AskHandle Blog

Resolving PostgreSQL Port 5432 Conflicts on Unix Systems

September 28, 2025Melissa Olson3 min read

Resolving PostgreSQL Port 5432 Conflicts on Unix Systems

When managing PostgreSQL services on Unix systems, conflicts may arise that prevent the service from starting. This guide provides steps to resolve conflicts, particularly those related to port 5432.

Understanding the Error

An example of an error message encountered during PostgreSQL startup is as follows:

text
12024-01-04 10:53:16.557 CST [1366] LOG: starting PostgreSQL 15.5 on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit
22024-01-04 10:53:16.559 CST [1366] LOG: listening on IPv6 address "::1", port 5432
32024-01-04 10:53:16.559 CST [1366] LOG: listening on IPv4 address "127.0.0.1", port 5432
42024-01-04 10:53:16.559 CST [1366] LOG: could not bind Unix address "/tmp/.s.PGSQL.5432": Address already in use
52024-01-04 10:53:16.559 CST [1366] HINT: Is another postmaster already running on port 5432?
62024-01-04 10:53:16.559 CST [1366] WARNING: could not create Unix-domain socket in directory "/tmp"
72024-01-04 10:53:16.559 CST [1366] FATAL: could not create any Unix-domain sockets
82024-01-04 10:53:16.560 CST [1366] LOG: database system is shut down

This message indicates a failure to start due to the Unix domain socket file /tmp/.s.PGSQL.5432 being in use. This often happens when another instance of PostgreSQL is running or did not shut down properly.

Step 1: Identify the Service Using Port 5432

Start by checking what is currently using port 5432. Examine the socket file's details:

bash
1ls -l /tmp/.s.PGSQL.5432

Look for the File:

If the .s.PGSQL.5432 file exists, the output will show its details:

text
1srwxrwxrwx  1 postgres  wheel     0 Jan  4 10:44 .s.PGSQL.5432

Interpreting the Output:

The presence of the file indicates that a PostgreSQL server created it for local connections.

Step 2: Ensure PostgreSQL is Not Running

Before you proceed, check that PostgreSQL or any related service is not running. Use the following commands based on your system:

bash
1sudo service postgresql stop

or

bash
1sudo systemctl stop postgresql

Finding the Process ID (PID):

If the service is not managed, find the PID of the process using the socket with lsof:

bash
1sudo lsof /tmp/.s.PGSQL.5432

This will display details including the PID of the process using the socket.

Stop the process using the kill command:

bash
1sudo kill -9 PID

Replace PID with the actual process ID found earlier.

Step 3: Remove the Socket File

With the service stopped, you can safely remove the socket file:

bash
1sudo rm /tmp/.s.PGSQL.5432

This resolves the immediate conflict.

Step 4: Verify the Removal

Confirm that the file has been deleted:

bash
1ls -la /tmp | grep PGSQL.5432

A successful removal will show no results.

To resolve a port 5432 conflict on Unix systems, follow the steps to identify the service using the port, ensure its inactivity, remove the Unix domain socket file, and verify the removal. These actions help maintain smooth operations and system reliability.