Thread: could not bind IPv4 socket

could not bind IPv4 socket

From
Grzegorz Buś
Date:

Hi,

 

I'm using Centos 4.7 and after upgrading PostgreSQL to version 8.3.7 (from ver. 7.4)  via yum I cannot connect to my postgres server from remote hosts.

 

I know that for PostgreSQL servers starting with version 8.0 remote connections can only be set in postgresql.conf allowing them in “listen_addresses” parameter. My settings are following:

 

listen_addresses = 'localhost,XXX.XXX.XXX.XXX'

 

where XXX.XXX.XXX.XXX is IP address of remote client that I want to be able to use PostgreSQL server. Port is default.

 

When I start server (service postgresql start) I receive status [OK], but in pgstartup.log there is information about some errors (or rather warnings – but that’s why remote connections don’t work):

 

WARNING:  could not create listen socket for "XXX.XXX.XXX.XXX"

LOG:  could not bind IPv4 socket: Cannot assign requested address

HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.

 

Of course – there is no other instance of PostgreSQL serve nor any other application is using this TCP port. This commands returns empty string:

 

netstat -plunt | grep 5432

pg -A | grep postmaster

 

I must add that everything works fine for my local apps – they can easily connect to the server. I also tried few other non-default ports from range 60000+ with same result. Additionally, previous version (7.4) had no problems for accepting remote connections.

 

Thanks,

Grzegorz Bus

Re: could not bind IPv4 socket

From
Greg Smith
Date:
On Thu, 30 Apr 2009, Grzegorz Bu? wrote:

> listen_addresses = 'localhost,XXX.XXX.XXX.XXX'
> where XXX.XXX.XXX.XXX is IP address of remote client that I want to be able to use PostgreSQL server. Port is
default.

listen_addresses gets set to the IP address of the server itself, the IP
address it is "listening" for input on.  Since you're giving it a remote
address, that's why it can't create a socket to listen there.

There is a second file here, pg_hba.conf, that filters down who can
connect to the database.  Normal practice here is to set:

listen_address='*'

So that the server is remotely accessible from all of its interfaces, and
then you can do all filtering of who can connect just via pg_hba.conf
instead.  See
http://www.postgresql.org/docs/8.3/static/auth-pg-hba-conf.html for more
information.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

Re: could not bind IPv4 socket

From
Craig Ringer
Date:
Greg Smith wrote:

> Normal practice here is to set:
>
> listen_address='*'
>
> So that the server is remotely accessible from all of its interfaces,
> and then you can do all filtering of who can connect just via
> pg_hba.conf instead.

Just to expand on that:

listen_addresses is usually used if you want to do things like:

- Have the database running on a gateway host that's directly connected
to the Internet, but only permit connections to the database on the LAN
side, so even pre-auth exploits can't attack the database server from
the Internet side;

- Lock a cluster down to only be accessible from the local host, so
remote hosts can't even see it's running and can't attempt to talk to it; or

- Run multiple clusters on one host, each one bound to a different IP
address on the usual PostgreSQL port, so the machine hosting the
clusters looks like it's really multiple separate machines to outside users.

--
Craig Ringer

Re: could not bind IPv4 socket

From
Grzegorz Buś
Date:
> listen_addresses gets set to the IP address of the server itself, the
> IP address it is "listening" for input on.  Since you're giving it a
> remote address, that's why it can't create a socket to listen there.

> There is a second file here, pg_hba.conf, that filters down who can
> connect to the database.  Normal practice here is to set:

> listen_address='*'

OK. My settings now are following:

# cat postgresql.conf | grep listen
listen_addresses = 'localhost,*'        # what IP address(es) to listen on;

I did restart postgresql service, but problem still persists:

# rm /var/lib/pgsql/data/pgstartup.log
rm: remove regular file `/var/lib/pgsql/data/pgstartup.log'? y # service
postgresql restart
Stopping postgresql service:                               [  OK  ]
Starting postgresql service:                               [  OK  ]
# cat /var/lib/pgsql/data/pgstartup.log
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a
few seconds and retry.

Local apps can still connect to the postgresql server - but remote can't.

> So that the server is remotely accessible from all of its interfaces,
> and then you can do all filtering of who can connect just via pg_hba.conf
instead.
> See http://www.postgresql.org/docs/8.3/static/auth-pg-hba-conf.html for
more information.

I know - after upgrading PostgreSQL from version 7.4 (which allowed remote
connections) to 8.3 I copied settings from old pg_hba.conf.

--
Kind Regards,
Grzegorz Bus


Re: could not bind IPv4 socket

From
Adrian Klaver
Date:
On Sunday 03 May 2009 12:01:24 pm Grzegorz Buś wrote:
> > listen_addresses gets set to the IP address of the server itself, the
> > IP address it is "listening" for input on.  Since you're giving it a
> > remote address, that's why it can't create a socket to listen there.
> >
> > There is a second file here, pg_hba.conf, that filters down who can
> > connect to the database.  Normal practice here is to set:
> >
> > listen_address='*'
>
> OK. My settings now are following:
>
> # cat postgresql.conf | grep listen
> listen_addresses = 'localhost,*'        # what IP address(es) to listen on;
>
> I did restart postgresql service, but problem still persists:
>
> # rm /var/lib/pgsql/data/pgstartup.log
> rm: remove regular file `/var/lib/pgsql/data/pgstartup.log'? y # service
> postgresql restart
> Stopping postgresql service:                               [  OK  ]
> Starting postgresql service:                               [  OK  ]
> # cat /var/lib/pgsql/data/pgstartup.log
> LOG:  could not bind IPv4 socket: Address already in use
> HINT:  Is another postmaster already running on port 5432? If not, wait a
> few seconds and retry.

Did you heed the HINT and see if there is another instance of Postgres running?

>
> Local apps can still connect to the postgresql server - but remote can't.

If it cannot bind to IP socket then no remote connections will not succeed.
Local connections will occur over local Unix socket.

>
> > So that the server is remotely accessible from all of its interfaces,
> > and then you can do all filtering of who can connect just via pg_hba.conf
>
> instead.
>
> > See http://www.postgresql.org/docs/8.3/static/auth-pg-hba-conf.html for
>
> more information.
>
> I know - after upgrading PostgreSQL from version 7.4 (which allowed remote
> connections) to 8.3 I copied settings from old pg_hba.conf.
>
> --
> Kind Regards,
> Grzegorz Bus



--
Adrian Klaver
aklaver@comcast.net

Re: could not bind IPv4 socket

From
"Vladimir N. Indik"
Date:
Try this command separately.
# service postgresql stop
and then
# service postgresql start

On Воскресенье 03 мая 2009 23:01:24 Grzegorz Buś wrote:
> postgresql restart
> Stopping postgresql service:                               [  OK  ]
> Starting postgresql service:                               [  OK  ]

--
Vladimir N. Indik

Re: could not bind IPv4 socket

From
Grzegorz Buś
Date:
> > # cat /var/lib/pgsql/data/pgstartup.log
> > LOG:  could not bind IPv4 socket: Address already in use
> > HINT:  Is another postmaster already running on port 5432? If not,
> wait a
> > few seconds and retry.
>
> Did you heed the HINT and see if there is another instance of Postgres
> running?
>

As I wrote in my first message - for sure there is no other PostgreSQL
server instance nor any other application is using this TCP port. (I checked
with commands `ps -A | grep postmaster` and `netstat -plunt | grep 5432`):

# service postgresql stop
Stopping postgresql service:                               [  OK  ]
# netstat -plunt | grep 5432
# ps -A | grep postmaster
# rm /var/lib/pgsql/pgstartup.log
rm: remove regular file `/var/lib/pgsql/pgstartup.log'? y
# service postgresql start
Starting postgresql service:                               [  OK  ]
# cat /var/lib/pgsql/pgstartup.log
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a
few seconds and retry.


Any other hints?

--
Kind Regards
Grzegorz Bus


Re: could not bind IPv4 socket

From
Grzegorz Buś
Date:
When I run separately start/stop commands I still get "could not bind socket" message:

# service postgresql stop
Stopping postgresql service:                               [  OK  ]
# netstat -plunt | grep 5432
# ps -A | grep postmaster
# rm /var/lib/pgsql/pgstartup.log
rm: remove regular file `/var/lib/pgsql/pgstartup.log'? y
# service postgresql start
Starting postgresql service:                               [  OK  ]
# cat /var/lib/pgsql/pgstartup.log
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.

--
Kind Regards,
Grzegorz Bus

-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Vladimir N. Indik
Sent: Monday, May 04, 2009 10:15 AM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] could not bind IPv4 socket

Try this command separately.
# service postgresql stop
and then
# service postgresql start

On Воскресенье 03 мая 2009 23:01:24 Grzegorz Buś wrote:
> postgresql restart
> Stopping postgresql service:                               [  OK  ]
> Starting postgresql service:                               [  OK  ]

--
Vladimir N. Indik

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: could not bind IPv4 socket

From
Adrian Klaver
Date:
On Monday 04 May 2009 4:29:27 am Grzegorz Buś wrote:
> When I run separately start/stop commands I still get "could not bind
> socket" message:
>
> # service postgresql stop
> Stopping postgresql service:                               [  OK  ]
> # netstat -plunt | grep 5432
> # ps -A | grep postmaster
> # rm /var/lib/pgsql/pgstartup.log
> rm: remove regular file `/var/lib/pgsql/pgstartup.log'? y
> # service postgresql start
> Starting postgresql service:                               [  OK  ]
> # cat /var/lib/pgsql/pgstartup.log
> LOG:  could not bind IPv4 socket: Address already in use
> HINT:  Is another postmaster already running on port 5432? If not, wait a
> few seconds and retry.
>
> --
> Kind Regards,
> Grzegorz Bus
>
> -----Original Message-----
>

In my /tmp directory I have the following when the server is running. These
files are removed on shutdown. When you do your shutdown, check and see if they
are still there and what there timestamp is. Could be there are left over files
from your previous version.

/tmp$
srwxrwxrwx  1 postgres postgres    0 2009-05-04 05:51 .s.PGSQL.5432
-rw-------  1 postgres postgres   27 2009-05-04 05:51 .s.PGSQL.5432.lock

--
Adrian Klaver
aklaver@comcast.net

Re: could not bind IPv4 socket

From
Grzegorz Buś
Date:
Ok., that's it. After deleting this files everything works fine. Thanks ;)

--
Kind Regards,
Grzegorz Bus

-----Original Message-----
From: Adrian Klaver [mailto:aklaver@comcast.net]
Sent: Monday, May 04, 2009 3:19 PM
To: pgsql-general@postgresql.org
Cc: Grzegorz Buś
Subject: Re: [GENERAL] could not bind IPv4 socket
Importance: High

On Monday 04 May 2009 4:29:27 am Grzegorz Buś wrote:
> When I run separately start/stop commands I still get "could not bind
> socket" message:
>
> # service postgresql stop
> Stopping postgresql service:                               [  OK  ]
> # netstat -plunt | grep 5432
> # ps -A | grep postmaster
> # rm /var/lib/pgsql/pgstartup.log
> rm: remove regular file `/var/lib/pgsql/pgstartup.log'? y
> # service postgresql start
> Starting postgresql service:                               [  OK  ]
> # cat /var/lib/pgsql/pgstartup.log
> LOG:  could not bind IPv4 socket: Address already in use
> HINT:  Is another postmaster already running on port 5432? If not, wait a
> few seconds and retry.
>
> --
> Kind Regards,
> Grzegorz Bus
>
> -----Original Message-----
>

In my /tmp directory I have the following when the server is running. These
files are removed on shutdown. When you do your shutdown, check and see if they
are still there and what there timestamp is. Could be there are left over files
from your previous version.

/tmp$
srwxrwxrwx  1 postgres postgres    0 2009-05-04 05:51 .s.PGSQL.5432
-rw-------  1 postgres postgres   27 2009-05-04 05:51 .s.PGSQL.5432.lock

--
Adrian Klaver
aklaver@comcast.net