Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cm4ep-00037n-8s for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Mar 2017 20:27:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cm4eo-00021j-MS for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Mar 2017 20:27:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cm4em-0001xE-Q7 for pgsql-hackers@postgreSQL.org; Thu, 09 Mar 2017 20:27:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cm4ek-0001dS-He for pgsql-hackers@postgreSQL.org; Thu, 09 Mar 2017 20:27:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v29KRPhN009565 for ; Thu, 9 Mar 2017 15:27:25 -0500 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Upgrading postmaster's log messages about bind/listen errors MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <9558.1489091229.0@sss.pgh.pa.us> Date: Thu, 09 Mar 2017 15:27:25 -0500 Message-ID: <9564.1489091245@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9558.1489091229.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Over in https://www.postgresql.org/message-id/flat/201703072317.01345.john.iliffe%4= 0iliffe.ca we spent quite a lot of effort to diagnose what turned out to be a simple networking misconfiguration. It would probably have taken a lot less effort if the postmaster were more forthcoming about exactly what address it's trying to bind to. I seem to recall having wanted to include that info in the messages many years ago, but at the time we lacked any reasonably-portable way to decode a struct addrinfo. Now we have pg_getnameinfo_all(), so PFA a patch to include the specific address in any complaint about failures in the socket/bind/listen sequence. For good measure I also added a DEBUG1 log message reporting successful binding to a port. I'm not sure if there's an argument for putting this out at LOG level (i.e. by default) --- any thoughts about that? There are probably a couple of example messages in the SGML docs that would need to be updated, but I've not trawled for them yet. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="add-address-to-bind-failure-msgs.patch"; charset="us-ascii" Content-ID: <9558.1489091229.2@sss.pgh.pa.us> Content-Description: add-address-to-bind-failure-msgs.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 7939b1f..3f3b2f2 100644 *** a/src/backend/libpq/pqcomm.c --- b/src/backend/libpq/pqcomm.c *************** StreamServerPort(int family, char *hostN *** 319,324 **** --- 319,326 ---- char portNumberStr[32]; const char *familyDesc; char familyDescBuf[64]; + const char *addrDesc; + char addrBuf[NI_MAXHOST]; char *service; struct addrinfo *addrs =3D NULL, *addr; *************** StreamServerPort(int family, char *hostN *** 407,413 **** break; } =20=20 ! /* set up family name for possible error messages */ switch (addr->ai_family) { case AF_INET: --- 409,415 ---- break; } =20=20 ! /* set up address family name for log messages */ switch (addr->ai_family) { case AF_INET: *************** StreamServerPort(int family, char *hostN *** 431,443 **** break; } =20=20 if ((fd =3D socket(addr->ai_family, SOCK_STREAM, 0)) =3D=3D PGINVALID_S= OCKET) { ereport(LOG, (errcode_for_socket_access(), ! /* translator: %s is IPv4, IPv6, or Unix */ ! errmsg("could not create %s socket: %m", ! familyDesc))); continue; } =20=20 --- 433,460 ---- break; } =20=20 + /* set up text form of address for log messages */ + #ifdef HAVE_UNIX_SOCKETS + if (addr->ai_family =3D=3D AF_UNIX) + addrDesc =3D unixSocketPath; + else + #endif + { + pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr, + addr->ai_addrlen, + addrBuf, sizeof(addrBuf), + NULL, 0, + NI_NUMERICHOST); + addrDesc =3D addrBuf; + } +=20 if ((fd =3D socket(addr->ai_family, SOCK_STREAM, 0)) =3D=3D PGINVALID_S= OCKET) { ereport(LOG, (errcode_for_socket_access(), ! /* translator: first %s is IPv4, IPv6, or Unix */ ! errmsg("could not create %s socket for address \"%s\": %m", ! familyDesc, addrDesc))); continue; } =20=20 *************** StreamServerPort(int family, char *hostN *** 461,467 **** { ereport(LOG, (errcode_for_socket_access(), ! errmsg("setsockopt(SO_REUSEADDR) failed: %m"))); closesocket(fd); continue; } --- 478,486 ---- { ereport(LOG, (errcode_for_socket_access(), ! /* translator: first %s is IPv4, IPv6, or Unix */ ! errmsg("setsockopt(SO_REUSEADDR) failed for %s address \"%s\": %m", ! familyDesc, addrDesc))); closesocket(fd); continue; } *************** StreamServerPort(int family, char *hostN *** 476,482 **** { ereport(LOG, (errcode_for_socket_access(), ! errmsg("setsockopt(IPV6_V6ONLY) failed: %m"))); closesocket(fd); continue; } --- 495,503 ---- { ereport(LOG, (errcode_for_socket_access(), ! /* translator: first %s is IPv4, IPv6, or Unix */ ! errmsg("setsockopt(IPV6_V6ONLY) failed for %s address \"%s\": %m", ! familyDesc, addrDesc))); closesocket(fd); continue; } *************** StreamServerPort(int family, char *hostN *** 494,502 **** { ereport(LOG, (errcode_for_socket_access(), ! /* translator: %s is IPv4, IPv6, or Unix */ ! errmsg("could not bind %s socket: %m", ! familyDesc), (IS_AF_UNIX(addr->ai_family)) ? errhint("Is another postmaster already running on port %d?" " If not, remove socket file \"%s\" and retry.", --- 515,523 ---- { 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.", *************** StreamServerPort(int family, char *hostN *** 533,544 **** { ereport(LOG, (errcode_for_socket_access(), ! /* translator: %s is IPv4, IPv6, or Unix */ ! errmsg("could not listen on %s socket: %m", ! familyDesc))); closesocket(fd); continue; } ListenSocket[listen_index] =3D fd; added++; } --- 554,571 ---- { ereport(LOG, (errcode_for_socket_access(), ! /* translator: first %s is IPv4, IPv6, or Unix */ ! errmsg("could not listen on %s address \"%s\": %m", ! familyDesc, addrDesc))); closesocket(fd); continue; } +=20 + ereport(DEBUG1, + /* translator: first %s is IPv4, IPv6, or Unix */ + (errmsg("listening on %s address \"%s\"", + familyDesc, addrDesc))); +=20 ListenSocket[listen_index] =3D fd; added++; } ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--