Обсуждение: Connection problems with "psql -h localhost postgres"

Поиск
Список
Период
Сортировка

Connection problems with "psql -h localhost postgres"

От
Wayne Pierce
Дата:
I have PostgreSQL setup and everything is working fine when I use
"psql -d <dbName>" on the command line or when I use mod_python to
connect.  However I when I use "psql -h localhost <dbName> postgres" I
get the following error:

psql: could not connect to server: Connection refused
        Is the server running on host "localhost" and accepting
        TCP/IP connections on port 5432?

I have the following lines in my pg_ident.conf and pg_hba.conf files:

-- pg_ident.conf --
# MAPNAME     IDENT-USERNAME    PG-USERNAME
localhost       all             all
host            all             all

-- pg_hba.conf --
# TYPE  DATABASE    USER        IP-ADDRESS/CIDR    METHOD
# IPv4-style local connections:
host       all       all         0.0.0.0 0.0.0.0         trust
host       all       all         127.0.0.1/32            trust
#host       logs    postgres      127.0.0.1/32       trust
#hostnossl   all      all         10.1.100.143/32    trust

# Using sockets credentials for improved security. Not available everywhere,
# but works on Linux, *BSD (and probably some others)
local      all       all                                 trust

I have tried various combinations, but nothing works.  I have tried
setting tcpip_socket in $PGDATA/postgresql.conf to 'true' and 'false'
with a restart each time.

The reason I need this to work is Ruby on Rails, for some reason rails
connects with the command line option above.  I have no idea why it
will work on way but not another.  I have tried to turn off IDENT
authentication completely (I am the only one with an account on this
system and the only one interacting directly with the database).

Does anyone know how to fix this?  I didn't find too much in the
mailing lists on using the -h option.

Thanks for any suggestions or help,

Wayne

Re: [despammed] Connection problems with "psql -h localhost postgres"

От
Andreas Kretschmer
Дата:
am  02.05.2005, um  9:03:50 -0400 mailte Wayne Pierce folgendes:
> I have PostgreSQL setup and everything is working fine when I use
> "psql -d <dbName>" on the command line or when I use mod_python to
> connect.  However I when I use "psql -h localhost <dbName> postgres" I
> get the following error:
>
> psql: could not connect to server: Connection refused
>         Is the server running on host "localhost" and accepting
>         TCP/IP connections on port 5432?
>
> I have the following lines in my pg_ident.conf and pg_hba.conf files:

PG does not listen on TCP.

Set in /etc/postgresql/postgresql.conf

tcpip_socket = true


Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===

Re: [despammed] Connection problems with "psql -h localhost postgres"

От
Wayne Pierce
Дата:
On 5/2/05, Andreas Kretschmer <akretschmer@despammed.com> wrote:
> am  02.05.2005, um  9:03:50 -0400 mailte Wayne Pierce folgendes:
> > I have PostgreSQL setup and everything is working fine when I use
> > "psql -d <dbName>" on the command line or when I use mod_python to
> > connect.  However I when I use "psql -h localhost <dbName> postgres" I
> > get the following error:
> >
> > psql: could not connect to server: Connection refused
> >         Is the server running on host "localhost" and accepting
> >         TCP/IP connections on port 5432?
> >
> > I have the following lines in my pg_ident.conf and pg_hba.conf files:
>
> PG does not listen on TCP.
>
> Set in /etc/postgresql/postgresql.conf
>
> tcpip_socket = true

I did have that setting.  After restarting the server I typed "ps
-deaf | grep postgres" and the -i option was not showing up for the
postmaster startup command.  I couldn't figure out why so I added '-i'
to the line in /etc/init.d/postgresql and that part now works.

Thank you for the response,

Wayne

Re: Connection problems with "psql -h localhost postgres"

От
Tom Lane
Дата:
Wayne Pierce <shalofin@gmail.com> writes:
> I have PostgreSQL setup and everything is working fine when I use
> "psql -d <dbName>" on the command line or when I use mod_python to
> connect.  However I when I use "psql -h localhost <dbName> postgres" I
> get the following error:

> psql: could not connect to server: Connection refused
>         Is the server running on host "localhost" and accepting
>         TCP/IP connections on port 5432?

This is a kernel-level refusal: your connection request never got to the
postmaster at all, ergo the contents of pg_hba.conf etc are irrelevant.

Assuming you did start the postmaster with tcpip_socket enabled, the
only other possibility I know of is that the kernel is refusing the
connection because of packet filtering rules.  Check your firewall
setup and see what sort of restrictions are imposed on localhost
connections.  You at least want to allow traffic to/from port 5432,
and may want to loosen it up more while you are at it.

            regards, tom lane

Re: Connection problems with "psql -h localhost postgres"

От
Ennio-Sr
Дата:
* Wayne Pierce <shalofin@gmail.com> [020505, 09:03]:
> I have PostgreSQL setup and everything is working fine when I use
> "psql -d <dbName>" on the command line or when I use mod_python to
> connect.  However I when I use "psql -h localhost <dbName> postgres" I
> get the following error:
> [...]

Hi Wayne,
I had a similar problem a few days ago; maybe it's related to the
difference between *unix_socket* and *tcpip_socket*
Try to skip the "-h localhost" from that command: it should work ...
Regards,
    Ennio

--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo.   \\?//
 Fa' qualche cosa di cui non sei capace!"  (diceva Henry Miller) ]    (°|°)
[Why use Win$ozz (I say) if ... "even a fool can do that.              )=(
 Do something you aren't good at!" (as Henry Miller used to say) ]