Обсуждение: PGSTAT: bind(2): Can't assign requested address
PRIO: low Hi, in src/backend/postmaster/pgstat.c there is a hard coded bind to 127.0.0.1 that fails if 127.0.0.1 is not configured on loopback interface (e.g. administrator explicitly removed this IP). This should _not_ be the case in normal setups. --- gmake check --- ... ============== creating temporary installation ============== ============== initializing database system ============== ============== starting postmaster ============== pg_regress: postmaster did not start Examine ./log/postmaster.log for the reason. kill: 97857: No such process rm regress.o gmake[2]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test/regress' gmake[1]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test' % cat src/test/regress/log/postmaster.log PGSTAT: bind(2): Can't assign requested address --- snipp --- With postgresql-7.2.1 (and perhaps also earlier versions ?) this prevents postmaster from starting if one does not configure 'stats_start_collector = false'. This works as a workaround. One may also patch the sources and recompile of course. I have seen that there were changes in CVS already but the 127.0.0.1 is still hard coded in there. I discovered that after playing with some routing daemons on my test machine and therefor had removed 127.0.0.1. OS was FreeBSD 4.5-STABLE but that shouldn't matter. -- Greetings Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT 56 69 73 69 74 http://www.zabbadoz.net/
Well, you are the first to report that 127.0.0.1 doesn't work for stats. Unless someone else has a problem, I think we will leave it unchanged. --------------------------------------------------------------------------- Bjoern A. Zeeb wrote: > PRIO: low > > Hi, > > in src/backend/postmaster/pgstat.c there is a hard coded bind to > 127.0.0.1 that fails if 127.0.0.1 is not configured on loopback > interface (e.g. administrator explicitly removed this IP). > This should _not_ be the case in normal setups. > > --- gmake check --- > ... > ============== creating temporary installation ============== > ============== initializing database system ============== > ============== starting postmaster ============== > > pg_regress: postmaster did not start > Examine ./log/postmaster.log for the reason. > > kill: 97857: No such process > rm regress.o > gmake[2]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test/regress' > gmake[1]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test' > % cat src/test/regress/log/postmaster.log > PGSTAT: bind(2): Can't assign requested address > --- snipp --- > > With postgresql-7.2.1 (and perhaps also earlier versions ?) this > prevents postmaster from starting if one does not configure > 'stats_start_collector = false'. > This works as a workaround. > One may also patch the sources and recompile of course. > > I have seen that there were changes in CVS already but the 127.0.0.1 is > still hard coded in there. > > I discovered that after playing with some routing daemons on my test > machine and therefor had removed 127.0.0.1. OS was FreeBSD 4.5-STABLE > but that shouldn't matter. > > -- > Greetings > > Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT > 56 69 73 69 74 http://www.zabbadoz.net/ > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
On Fri, 7 Jun 2002, Bruce Momjian wrote: Hi, it's been some months so I left the fullquote attached. > Well, you are the first to report that 127.0.0.1 doesn't work for stats. > Unless someone else has a problem, I think we will leave it unchanged. The last years this problem was disucced several times (mostly on FreeBSD lists) for the reason of FreeBSD jails. I thought that we had another mail in 2002 about that but couldn't find it anymore. Anyway binding to 127.0.0.1 in a jail binds to the (usually public) IP address of that jail which means the stats socket is basically open to world (from the socket point of view). Another problem (which is not a postgresql problem per se) is that if the system is built without inet6 support or does not support inet6 (as in jails) but there is a ::1 localhost in /etc/hosts the error messages gives a warning like: could not create socket for statistics collector: Protocol not supported which sound annoying in first places until you find out that it worked anyway and remember what cuases the warning. Is there any reason why you explicitly disallow a posix local socket at that point in backend/postmaster/pgstat.c:pgstat_init: ... for (addr = addrs; addr; addr = addr->ai_next) { #ifdef HAVE_UNIX_SOCKETS /* Ignore AF_UNIX sockets, if any are returned. */ if (addr->ai_family == AF_UNIX) continue; #endif ... Couldn't you use/allow (if possible or configured) a posix local socket or even use pipes for that? Greetings Bjoern A. Zeeb > --------------------------------------------------------------------------- > > Bjoern A. Zeeb wrote: >> PRIO: low >> >> Hi, >> >> in src/backend/postmaster/pgstat.c there is a hard coded bind to >> 127.0.0.1 that fails if 127.0.0.1 is not configured on loopback >> interface (e.g. administrator explicitly removed this IP). >> This should _not_ be the case in normal setups. >> >> --- gmake check --- >> ... >> ============== creating temporary installation ============== >> ============== initializing database system ============== >> ============== starting postmaster ============== >> >> pg_regress: postmaster did not start >> Examine ./log/postmaster.log for the reason. >> >> kill: 97857: No such process >> rm regress.o >> gmake[2]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test/regress' >> gmake[1]: Leaving directory `/u1/local/src/postgresql/postgresql-7.2.1/src/test' >> % cat src/test/regress/log/postmaster.log >> PGSTAT: bind(2): Can't assign requested address >> --- snipp --- >> >> With postgresql-7.2.1 (and perhaps also earlier versions ?) this >> prevents postmaster from starting if one does not configure >> 'stats_start_collector = false'. >> This works as a workaround. >> One may also patch the sources and recompile of course. >> >> I have seen that there were changes in CVS already but the 127.0.0.1 is >> still hard coded in there. >> >> I discovered that after playing with some routing daemons on my test >> machine and therefor had removed 127.0.0.1. OS was FreeBSD 4.5-STABLE >> but that shouldn't matter. -- Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT
"Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net> writes: > Is there any reason why you explicitly disallow a posix local socket > at that point in backend/postmaster/pgstat.c:pgstat_init: Because we want UDP, not a Unix socket. regards, tom lane
On Wed, 5 Apr 2006, Tom Lane wrote: Hi, > "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net> writes: >> Is there any reason why you explicitly disallow a posix local socket >> at that point in backend/postmaster/pgstat.c:pgstat_init: > > Because we want UDP, not a Unix socket. what you are giving there as hints is hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; A datagram socket (SOCK_DGRAM) is called "UDP Socket" when it assumes IP (AF_INET) or IPv6 (AF_INET6) as it's underlying protocol. But you can always use SOCK_DGRAM over AF_LOCAL. Stevens gives some good reasons to do so, especially if both peers are on the same host. If there is no need for using the INET(6) protcotol familiy (an I cannot see it as long as we stay on the same host) you may really want to consider using posix local sockets. Greetings Bjoern -- Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT
"Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net> writes: > A datagram socket (SOCK_DGRAM) is called "UDP Socket" when it > assumes IP (AF_INET) or IPv6 (AF_INET6) as it's underlying > protocol. > But you can always use SOCK_DGRAM over AF_LOCAL. I'm unconvinced that that has the same semantics on all platforms. Unix pipes traditionally have different behavior with respect to blocking, partial message send, etc. regards, tom lane
On Wed, 5 Apr 2006, Tom Lane wrote: > "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net> writes: >> A datagram socket (SOCK_DGRAM) is called "UDP Socket" when it >> assumes IP (AF_INET) or IPv6 (AF_INET6) as it's underlying >> protocol. >> But you can always use SOCK_DGRAM over AF_LOCAL. > > I'm unconvinced that that has the same semantics on all platforms. > Unix pipes traditionally have different behavior with respect to > blocking, partial message send, etc. Are you worried about posix local sockets in general? Or are you worried about doing sock_dgram over posix local sockets? just some more thoughts... - libpq uses posix local sockets (even streaming) as default if available and no hostname is given. I'd be more worried about my data... - posix local sockets have been around for ages and I'd rather rely on posix local sockets than any IPv6 protocol implementation. - it's the same API on top of them - it's posix these days - it could be configurable/optional -- Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT
Bjoern A. Zeeb wrote: > On Fri, 7 Jun 2002, Bruce Momjian wrote: > > Hi, > > it's been some months so I left the fullquote attached. > > > Well, you are the first to report that 127.0.0.1 doesn't work for stats. > > Unless someone else has a problem, I think we will leave it unchanged. > > > The last years this problem was disucced several times (mostly on > FreeBSD lists) for the reason of FreeBSD jails. I thought that we > had another mail in 2002 about that but couldn't find it anymore. > > Anyway binding to 127.0.0.1 in a jail binds to the (usually public) IP > address of that jail which means the stats socket is basically open to > world (from the socket point of view). Yes, but we need an interface that will drop packets on heavy load, and a local IP is the only way we know to do that. > Another problem (which is not a postgresql problem per se) is that if > the system is built without inet6 support or does not support inet6 > (as in jails) but there is a ::1 localhost in /etc/hosts the error > messages gives a warning like: > could not create socket for statistics collector: > Protocol not supported > which sound annoying in first places until you find out that it worked > anyway and remember what cuases the warning. Yes, that is confusing. The following patch adds a message after the error: trying another address for the statistics collector which should help reduce confusion. It will appear in 8.2. > Is there any reason why you explicitly disallow a posix local socket > at that point in backend/postmaster/pgstat.c:pgstat_init: > > ... > for (addr = addrs; addr; addr = addr->ai_next) > { > #ifdef HAVE_UNIX_SOCKETS > /* Ignore AF_UNIX sockets, if any are returned. */ > if (addr->ai_family == AF_UNIX) > continue; > #endif > ... > > > Couldn't you use/allow (if possible or configured) a posix local socket > or even use pipes for that? Yes, because it can't drop packets, I think. -- Bruce Momjian http://candle.pha.pa.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.122 diff -c -c -r1.122 pgstat.c *** src/backend/postmaster/pgstat.c 6 Apr 2006 20:38:00 -0000 1.122 --- src/backend/postmaster/pgstat.c 20 Apr 2006 10:43:16 -0000 *************** *** 216,222 **** struct timeval tv; char test_byte; int sel_res; ! #define TESTBYTEVAL ((char) 199) /* --- 216,223 ---- struct timeval tv; char test_byte; int sel_res; ! int tries = 0; ! #define TESTBYTEVAL ((char) 199) /* *************** *** 276,281 **** --- 277,286 ---- continue; #endif + if (++tries > 1) + ereport(LOG, + (errmsg("trying another address for the statistics collector"))); + /* * Create the socket. */