postgresqlhomebrewmacos-sonoma

How to fix service error 256 in homebrew with postgreslq@16?


It's about Arm-based Chip (Apple M1). I installed postgresql@16 using Homebrew and it works very oddly.

Run brew services list and get:

Name          Status     User   File
postgresql@16 error  256 dmitry ~/Library/LaunchAgents/homebrew.mxcl.postgresql@16.plist

If I shut down postgresql@16 via brew and try pg_ctl -D /opt/homebrew/var/postgresql@16 start, I get:

2024-06-21 17:32:26.356 MSK [3252] LOG:  starting PostgreSQL 16.3 (Homebrew) on aarch64-apple-darwin23.4.0, compiled by Apple clang version 15.0.0 (clang-1500.3.9.4), 64-bit
2024-06-21 17:32:26.356 MSK [3252] LOG:  could not bind IPv6 address "::1": Address already in use
2024-06-21 17:32:26.356 MSK [3252] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2024-06-21 17:32:26.356 MSK [3252] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2024-06-21 17:32:26.356 MSK [3252] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2024-06-21 17:32:26.356 MSK [3252] WARNING:  could not create listen socket for "localhost"
2024-06-21 17:32:26.356 MSK [3252] FATAL:  could not create any TCP/IP sockets
2024-06-21 17:32:26.357 MSK [3252] LOG:  database system is shut down

Despite this in Django project the database functions normally, objects are created/received and so on. But through the terminal in Pycharm(psql postgres) nothing can be done, after the request I just have the status postgres-# and nothing happens.

I tried to use this solution, but I don't have a postmaster.pid file in /opt/homebrew/var/postgresql@16. None of the solutions I know help me.


Solution

  • I have a similar scenario to yours. In my case, the root cause was downloading PostgreSQL twice - One from enterprisedb (I believe I downloaded it from https://www.postgresql.org/download/macosx/) and one from homebrew. The reason for the failure of brew services start postgresql is due to the port 5432 is occupied by enterprisedb.

    To resolve or verify this, you can change the port in /opt/homebrew/var/postgresql/postgresql.conf to 5433(or another value) and check if brew services start postgresql works. If so, you can check which app is occupied by port 5432.