You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Port in use' check not working in older versions of macOS #789
In macOS 10.15, the check for the 'port in use' error before being able to press the 'Initialise' or 'Start' buttons seem not to work. Instead the operation is initiated and an "pg_ctl: could not start server" error is presented. This however does not seem to be a regressions of the latest refactoring regarding PID file deletion as I can reproduce the problem even with 2.7.2. The issue does not affect macOS 12. I have not tried to reproduce this on other older versions of macOS.
I've tried to reproduce this bug with Postgres.app 2.7.10 on macOS 10.15.7. It works fine for me.
Could it be something related to your VM? Maybe there is a weird network configuration that makes it break.
The check in Postgres.app is hard coded to try opening a port on "127.0.0.1". It seems that this check in the GUI succeeds, but then PostgreSQL fails to open a port. Maybe it has something to do with listen_address? Did you change the default config?
I've spent some more investigation on this. Thank you for the hint on listen_address! I can now reproduce the behaviour even on modern versions of macOS:
create a server on a specific port, like 3322
initialize and start the server
netstat -anvp tcp | grep 3322 should now show a process in state LISTEN on 127.0.0.1.3322 for tcp4
connect psql to the server and execute ALTER SYSTEM SET listen_addresses TO '*';
restart the server
netstat -anvp tcp | grep 3322 should now show a process in state LISTEN on *.3322 for tcp4
change another (inzialized) server to run on that port
note that Postgres.App shows "Not running" as server state, not "Port in use"
try to start the server and get a error message "Port 3322 is already in use"
this is not perfect, but does no harm.
If you alternatively
create a new server on that port
note that Postgres.App shows "Empty data directory" as server state
attempt to initialize the server, get a error message "Could not start PostgreSQL server."
we are in an error state that is not resolvable without manual intervention: The init_db has been run but the server could not be started and the process aborts before the usual role and database could be created. This is an error condition we have seen in many issues but I never understood how this can happen.
Obviously, * (or 0.0.0.0) does include 127.0.0.1 but our portInUse test seems not to be able to detect that. A nc -b lo0 -l 3322 fails with Address already in use. But Postgres itself seem to be happy binding on 127.0.0.1 again, it only chokes on the lockfile when attempting to bind to the unix domain socket (but it doesn't change if I set unix_socket_directories to ''):
LOG: listening on IPv6 address "::1", port 3322
LOG: listening on IPv4 address "127.0.0.1", port 3322
FATAL: lock file "/tmp/.s.PGSQL.3322.lock" already exists
HINT: Is another postmaster (PID 18227) using socket file "/tmp/.s.PGSQL.3322"?
Activity
jakob commentedon Nov 22, 2024
I've tried to reproduce this bug with Postgres.app 2.7.10 on macOS 10.15.7. It works fine for me.
Could it be something related to your VM? Maybe there is a weird network configuration that makes it break.
The check in Postgres.app is hard coded to try opening a port on "127.0.0.1". It seems that this check in the GUI succeeds, but then PostgreSQL fails to open a port. Maybe it has something to do with listen_address? Did you change the default config?
tbussmann commentedon Jan 14, 2025
I've spent some more investigation on this. Thank you for the hint on
listen_address! I can now reproduce the behaviour even on modern versions of macOS:3322netstat -anvp tcp | grep 3322should now show a process in stateLISTENon127.0.0.1.3322fortcp4psqlto the server and executeALTER SYSTEM SET listen_addresses TO '*';netstat -anvp tcp | grep 3322should now show a process in stateLISTENon*.3322fortcp4this is not perfect, but does no harm.
If you alternatively
we are in an error state that is not resolvable without manual intervention: The
init_dbhas been run but the server could not be started and the process aborts before the usual role and database could be created. This is an error condition we have seen in many issues but I never understood how this can happen.Obviously,
*(or0.0.0.0) does include127.0.0.1but our portInUse test seems not to be able to detect that. Anc -b lo0 -l 3322fails withAddress already in use. But Postgres itself seem to be happy binding on127.0.0.1again, it only chokes on the lockfile when attempting to bind to the unix domain socket (but it doesn't change if I setunix_socket_directoriesto''):This my be the same root problem as in #798