Re: Please Help me with connecting my PostgreSQL

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org, Lasntonpeng <lanstonpeng(at)gmail(dot)com>, psycopg-owner(at)postgresql(dot)org
Subject: Re: Please Help me with connecting my PostgreSQL
Date: 2011-03-31 13:42:35
Message-ID: AANLkTik20Fgimxh0TJFABHfGcyGQ0G+xYABh=pX2VW28@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Thu, Mar 31, 2011 at 2:33 PM, Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> wrote:
> On Thursday, March 31, 2011 5:54:34 am Lasntonpeng wrote:

>> It's the first time that I can't find the answer about some tech problems
>>
>> Here's my problems:
>> >>conn=psycopg2.connect(database="mydb", user="postgres",
>>
>> password="123",port=5433)
>>
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> psycopg2.OperationalError: could not connect to server: No such file or
>> directory
>>  Is the server running locally and accepting
>> connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
>
> Two problems. The first is the one Karsten already mentioned about the difference
> on ports. Second you have not specified a host so Psycopg is trying the local
> socket. If you are trying to connect from a machine other than the other one
> with the Postgres server it is not going to find the socket. Also the socket
> connection may have a  restriction in pg_hba.conf that would prevent a
> connection.

To connect to a database on the local machine, the quick answer is:
add host=127.0.0.1 to the connection string, which makes it connect to
the network socket instead of the unix socket. And I mean "127.0.0.1",
not "localhost".

All the gory details are in the pg_hba.conf documentation.

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2011-03-31 14:07:57 Re: Please Help me with connecting my PostgreSQL
Previous Message Adrian Klaver 2011-03-31 13:33:40 Re: Please Help me with connecting my PostgreSQL