Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf9dfa5c

Browse files
committed
Improve postmaster's logging of listen socket creation.
When one of the kernel calls in the socket()/bind()/listen() sequencefails, include the specific address we're trying to bind to in the logmessage. This greatly eases debugging of network misconfigurations.Also, after successfully setting up a listen socket, report its addressin the log, to ease verification that the expected addresses were bound.There was some debate about whether to print this message at LOG level oronly DEBUG1, but the majority of votes were for the former.Discussion:https://postgr.es/m/9564.1489091245@sss.pgh.pa.us
1 parentde75281 commitf9dfa5c

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ su - postgres -c "/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgs
464464

465465
<para>
466466
<screen>
467-
LOG: could not bind IPv4socket: Address already in use
467+
LOG: could not bind IPv4address "127.0.0.1": Address already in use
468468
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
469-
FATAL: could not create TCP/IPlisten socket
469+
FATAL: could not createanyTCP/IPsockets
470470
</screen>
471471
This usually means just what it suggests: you tried to start
472472
another server on the same port where one is already running.
@@ -476,9 +476,9 @@ FATAL: could not create TCP/IP listen socket
476476
on a reserved port number might draw something like:
477477
<screen>
478478
$ <userinput>postgres -p 666</userinput>
479-
LOG: could not bind IPv4socket: Permission denied
479+
LOG: could not bind IPv4address "127.0.0.1": Permission denied
480480
HINT: Is another postmaster already running on port 666? If not, wait a few seconds and retry.
481-
FATAL: could not create TCP/IPlisten socket
481+
FATAL: could not createanyTCP/IPsockets
482482
</screen>
483483
</para>
484484

‎src/backend/libpq/pqcomm.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
319319
charportNumberStr[32];
320320
constchar*familyDesc;
321321
charfamilyDescBuf[64];
322+
constchar*addrDesc;
323+
charaddrBuf[NI_MAXHOST];
322324
char*service;
323325
structaddrinfo*addrs=NULL,
324326
*addr;
@@ -407,7 +409,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
407409
break;
408410
}
409411

410-
/* set up family name forpossible error messages */
412+
/* set upaddressfamily name forlog messages */
411413
switch (addr->ai_family)
412414
{
413415
caseAF_INET:
@@ -431,13 +433,28 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
431433
break;
432434
}
433435

436+
/* set up text form of address for log messages */
437+
#ifdefHAVE_UNIX_SOCKETS
438+
if (addr->ai_family==AF_UNIX)
439+
addrDesc=unixSocketPath;
440+
else
441+
#endif
442+
{
443+
pg_getnameinfo_all((conststructsockaddr_storage*)addr->ai_addr,
444+
addr->ai_addrlen,
445+
addrBuf,sizeof(addrBuf),
446+
NULL,0,
447+
NI_NUMERICHOST);
448+
addrDesc=addrBuf;
449+
}
450+
434451
if ((fd=socket(addr->ai_family,SOCK_STREAM,0))==PGINVALID_SOCKET)
435452
{
436453
ereport(LOG,
437454
(errcode_for_socket_access(),
438-
/* translator: %s is IPv4, IPv6, or Unix */
439-
errmsg("could not create %s socket: %m",
440-
familyDesc)));
455+
/* translator:first%s is IPv4, IPv6, or Unix */
456+
errmsg("could not create %s socket for address \"%s\": %m",
457+
familyDesc,addrDesc)));
441458
continue;
442459
}
443460

@@ -461,7 +478,9 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
461478
{
462479
ereport(LOG,
463480
(errcode_for_socket_access(),
464-
errmsg("setsockopt(SO_REUSEADDR) failed: %m")));
481+
/* translator: first %s is IPv4, IPv6, or Unix */
482+
errmsg("setsockopt(SO_REUSEADDR) failed for %s address \"%s\": %m",
483+
familyDesc,addrDesc)));
465484
closesocket(fd);
466485
continue;
467486
}
@@ -476,7 +495,9 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
476495
{
477496
ereport(LOG,
478497
(errcode_for_socket_access(),
479-
errmsg("setsockopt(IPV6_V6ONLY) failed: %m")));
498+
/* translator: first %s is IPv4, IPv6, or Unix */
499+
errmsg("setsockopt(IPV6_V6ONLY) failed for %s address \"%s\": %m",
500+
familyDesc,addrDesc)));
480501
closesocket(fd);
481502
continue;
482503
}
@@ -494,9 +515,9 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
494515
{
495516
ereport(LOG,
496517
(errcode_for_socket_access(),
497-
/* translator: %s is IPv4, IPv6, or Unix */
498-
errmsg("could not bind %ssocket: %m",
499-
familyDesc),
518+
/* translator:first%s is IPv4, IPv6, or Unix */
519+
errmsg("could not bind %saddress \"%s\": %m",
520+
familyDesc,addrDesc),
500521
(IS_AF_UNIX(addr->ai_family)) ?
501522
errhint("Is another postmaster already running on port %d?"
502523
" If not, remove socket file \"%s\" and retry.",
@@ -533,12 +554,18 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
533554
{
534555
ereport(LOG,
535556
(errcode_for_socket_access(),
536-
/* translator: %s is IPv4, IPv6, or Unix */
537-
errmsg("could not listen on %ssocket: %m",
538-
familyDesc)));
557+
/* translator:first%s is IPv4, IPv6, or Unix */
558+
errmsg("could not listen on %saddress \"%s\": %m",
559+
familyDesc,addrDesc)));
539560
closesocket(fd);
540561
continue;
541562
}
563+
564+
ereport(LOG,
565+
/* translator: first %s is IPv4, IPv6, or Unix */
566+
(errmsg("listening on %s address \"%s\"",
567+
familyDesc,addrDesc)));
568+
542569
ListenSocket[listen_index]=fd;
543570
added++;
544571
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp