Re: Error message "psql: could not connect to server: No such file or directory"

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Stefan Schwarzer <stefan(dot)schwarzer(at)unep(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Error message "psql: could not connect to server: No such file or directory"
Date: 2012-06-21 14:07:42
Message-ID: 4FE32AAE.1070300@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 06/20/2012 10:40 PM, Stefan Schwarzer wrote:
>
>>> I need unfortunately to come back to this issue. I (again) re-installed Lion from scratch, and finally got everything working. The Postgres was running, I uploaded a couple of dumped SQL files. And then re-started the machine for another reason. And suddenly it says again the it can't connect to the server.
>>>
>>> I tried
>>> /usr/local/pgsql-9.1/bin/initdb -U postgres -D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US
>>>
>>> and
>>> /usr/local/pgsql-9.1/bin/pg_ctl -D /usr/local/pgsql-9.1/data/ -l logfile start
>>>
>>> and
>>> sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist
>>>
>>> … but nothing happens. I don't have the feeling that it's a problem with the "postgres" and "_postgres" users (as it has worked before already).
>>>
>>> Can anyone give me a hint how I can figure out where the problem lies and what I can do about it? Why did it work before I restarted the computer and why does it not work anymore?
>>>
>>> Thanks a lot for any hints!
>>>
>>
>> When troubleshooting I am firm believer in working from the known to the unknown. In that vein:
>>
>> 1) Is there /usr/local/pgsql-9.1/data/?
>
> Yes:
>
> drwx------ 18 _postgres _postgres 612 Jun 19 09:41 data
>
>
>> a) If so are there subdirectories in it indicating cluster was created? i.e. base/ global/ pg_clog/, etc
>
> Yes:
>
> drwx------ 7 _postgres _postgres 238 Jun 19 08:59 base
> drwx------ 43 _postgres _postgres 1462 Jun 19 09:41 global
> ….
>
>
>> 2) When you say nothing happens does that mean nothing is written to log file and/or terminal? No process shows up in process list?
>
> When I do: sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist
> it says: org.postgresql.postgres: Already loaded
>
> When I do: /usr/local/pgsql-9.1/bin/initdb -U postgres -D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US
> it says: The files belonging to this database system will be owned by user "xxx".
> This user must also own the server process.
> The database cluster will be initialized with locale en_US.
> The default text search configuration will be set to "english".
> initdb: could not access directory "/usr/local/pgsql-9.1/data": Permission denied

So at a guess user 'xxx' is not '_postgres'. You need to be the
_postgres user when doing the initdb.

>
> Same when using "_postgres" instead of "postgres".
>
> When I do: sudo su - _postgres /usr/local/pgsql-9.1/bin/initdb -U postgres -D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US
> it seems to run, but still, same error message "psql: could not connect…."

See, here the initdb worked. Doing the inidtdb is not the same as
starting the database. initdb only creates the initial database cluster.

To start the database you need to do something like(as _postgres):

/usr/local/pgsql-9.1/bin/pg_ctl start -D /usr/local/pgsql-9.1/data

>
> And still nothing in the process list (using "ps auxw | grep post").
>
>
>> 3) If something does happen in, terms of error messages, what are they?
>>
>> 4) Have you looked at system (not Postgres specific) logs to see if this a system issue?
>
> I looked at Apple's Console, where all (?) logs/messages are being assembled, but nothing worrisome there. is there any other specific place where I can look for error messages?
>
>
>> 5) What user are you running the above commands as?
>
> I am user with "Administrator" rights.

The commands need to be run as the _postgres user. Postgres will not run
as root.

>
>
>> a) What user is associated with the Postgres data directory(if it exists)?
>
> See above, "_postgres". There is or could be confusion between Apple's "_postgres" and the normal "postgres" user. But it looks as it isn't in this case..
>
> Thanks for your help!
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc Mamin 2012-06-21 14:17:01 (BUG ?) unprefixed oid -> ERROR: cache lookup failed for function
Previous Message Tom Lane 2012-06-21 14:07:09 Re: Please make it easy to drop a database that is in use