Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Postgres.app on macOS will not start a server on port 5432

ErrorPort 5432 is already in use

Short answer

Postgres.app fails to start when something else already holds port 5432, when another server uses the same data directory, or when a crash left a stale postmaster.pid. Find what listens on the port, stop it or give the new server a different port, and read postgres-server.log in the data directory.

  • Applies to Postgres.app, macOS
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find which process is listening on port 5432.

    lsof -nP -iTCP:5432 -sTCP:LISTEN
  2. 2Match what you see, then jump to its fix

    1. 1lsof lists a postgres process that is not the one Postgres.app is starting, for example from another Postgres.app server or a second PostgreSQL install.Another PostgreSQL server already uses the portFix
    2. 2lsof shows a postgres process owned by a different Mac user account.Another macOS user is running Postgres.appFix
    3. 3Postgres.app reports Could not delete stale postmaster.pid file after a crash or forced shutdown.A stale postmaster.pid is left in the data directoryFix
    4. 4The app only shows that the server did not start.The cause is not clear from the app windowFix

What does the error look like?

  • Port 5432 is already in use
  • Could not delete stale postmaster.pid file

Cause 1 of 4

Another PostgreSQL server already uses the port

1Check

Postgres.app says this error usually means a PostgreSQL server is already running on your Mac. It can be a different server inside Postgres.app, or a separate installation.

lsof -nP -iTCP:5432 -sTCP:LISTEN

2Fix

Stop that server, or change the port of the new one in the Database Settings of Postgres.app. Only one server can use each port.

# In Postgres.app: select the server, open Database Settings, set Port to 5433, then Start.

3Verify

The server shows as running, and psql connects on the chosen port.

psql -p 5433 -c 'select 1'

Confirmed by postgresapp.com

Did this fix it?

Cause 2 of 4

Another macOS user is running Postgres.app

1Check

The documentation notes that another user on the same Mac may already be running Postgres.app, and each port can be used once.

lsof -nP -iTCP:5432 -sTCP:LISTEN

2Fix

Ask that user to stop their server, or give each user's server its own port.

# Postgres.app, Database Settings > Port: use a different port for each user.

3Verify

Both servers start.

lsof -nP -iTCP -sTCP:LISTEN | grep postgres

Confirmed by postgresapp.com

Did this fix it?

Cause 3 of 4

A stale postmaster.pid is left in the data directory

1Check

If PostgreSQL crashes, the file can hold an old pid that prevents starting. Postgres.app normally removes it itself and reports the error when it cannot.

ls "DATA DIRECTORY/postmaster.pid"

2Fix

Make sure no postgres process uses that data directory, then delete postmaster.pid from the data directory and start again. The data directory path is shown in the server settings of the app.

rm "DATA DIRECTORY/postmaster.pid"

3Verify

Start the server from the app.

psql -c 'select version()'

Confirmed by postgresapp.com

Did this fix it?

Cause 4 of 4

The cause is not clear from the app window

1Check

Quit Postgres.app, start the server by hand with the same data directory and port to see the full error, and read postgres-server.log in the data directory.

/Applications/Postgres.app/Contents/Versions/latest/bin/postgres -D "DATA DIRECTORY" -p 5432
tail -n 50 "DATA DIRECTORY/postgres-server.log"

2Fix

Fix what the printed message names, then start from the app again.

# replace DATA DIRECTORY with the path shown in Database Settings

3Verify

The manual start no longer prints an error.

psql -c 'select 1'

Confirmed by postgresapp.com

Did this fix it?

How do I stop it coming back?

  • Run one PostgreSQL install per port on a Mac; pick distinct ports when you keep several.
  • Quit servers from Postgres.app before shutting the Mac down or removing the app.
  • Add the Postgres.app bin folder to your PATH so psql talks to the server you expect.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.