From 88c9420c63c9cfe8b0006341cb242bf2e37c3a24 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 9 Oct 2020 09:10:41 +0200 Subject: [PATCH 2/3] Make error hint from bind() failure more accurate The hint "Is another postmaster already running ..." should only be printed for errors that are really about something else already using the address. In other cases it is misleading. --- src/backend/libpq/pqcomm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 84568508c5..b8be7de70e 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -530,18 +530,21 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber, err = bind(fd, addr->ai_addr, addr->ai_addrlen); if (err < 0) { + int saved_errno = errno; + ereport(LOG, (errcode_for_socket_access(), /* translator: first %s is IPv4, IPv6, or Unix */ errmsg("could not bind %s address \"%s\": %m", familyDesc, addrDesc), - (IS_AF_UNIX(addr->ai_family)) ? - errhint("Is another postmaster already running on port %d?" - " If not, remove socket file \"%s\" and retry.", - (int) portNumber, service) : - errhint("Is another postmaster already running on port %d?" - " If not, wait a few seconds and retry.", - (int) portNumber))); + saved_errno == EADDRINUSE ? + (IS_AF_UNIX(addr->ai_family) ? + errhint("Is another postmaster already running on port %d?" + " If not, remove socket file \"%s\" and retry.", + (int) portNumber, service) : + errhint("Is another postmaster already running on port %d?" + " If not, wait a few seconds and retry.", + (int) portNumber)) : 0)); closesocket(fd); continue; } -- 2.28.0