Re: duplicate connection failure messages - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: duplicate connection failure messages
Date
Msg-id 201011120154.oAC1sHa22085@momjian.us
Whole thread Raw
In response to Re: duplicate connection failure messages  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: duplicate connection failure messages
List pgsql-hackers
Peter Eisentraut wrote:
> On tor, 2010-10-14 at 07:30 +0200, Magnus Hagander wrote:
> > And I agree it's not very friendly in this specific case - I
> > wonder if we should log it as "localhost (127.0.0.1) and "localhost
> > (::1)" (and similar for any other case that returns more than one
> > address).
>
> That looks good.

I have developed the attached patch to report whether IPv4 or IPv6 are
being used.  I could not find the numeric value as alwasy populated, and
this seems clearer too:

    $ pql -h localhost test
    psql: could not connect to server: Connection refused
            Is the server running on host "localhost" (IPv4) and accepting
            TCP/IP connections on port 5432?

    $ psql -h 127.0.0.1 test
    psql: could not connect to server: Connection refused
            Is the server running on host "127.0.0.1" (IPv4) and accepting
            TCP/IP connections on port 5432?

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 8f318a1..bf85b49 100644
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
*************** connectFailureMessage(PGconn *conn, int
*** 962,968 ****
      {
          appendPQExpBuffer(&conn->errorMessage,
                            libpq_gettext("could not connect to server: %s\n"
!                      "\tIs the server running on host \"%s\" and accepting\n"
                                          "\tTCP/IP connections on port %s?\n"),
                            SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
                            conn->pghostaddr
--- 962,968 ----
      {
          appendPQExpBuffer(&conn->errorMessage,
                            libpq_gettext("could not connect to server: %s\n"
!                      "\tIs the server running on host \"%s\" (%s) and accepting\n"
                                          "\tTCP/IP connections on port %s?\n"),
                            SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
                            conn->pghostaddr
*************** connectFailureMessage(PGconn *conn, int
*** 970,975 ****
--- 970,980 ----
                            : (conn->pghost
                               ? conn->pghost
                               : "???"),
+                           (conn->addr_cur->ai_family == AF_INET) ? "IPv4" :
+ #ifdef HAVE_IPV6
+                           (conn->addr_cur->ai_family == AF_INET6) ? "IPv6" :
+ #endif
+                           "???",
                            conn->pgport);
      }
  }

pgsql-hackers by date:

Previous
From: Itagaki Takahiro
Date:
Subject: Re: MULTISET and additional functions for ARRAY
Next
From: Bruce Momjian
Date:
Subject: Re: Re: [BUGS] BUG #5650: Postgres service showing as stopped when in fact it is running