Skip site navigation (1) Skip section navigation (2)

Re: Creating a db on my newly installed postresql on OS X

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Søren Krogh Neigaard <soeren(at)neigaard(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Creating a db on my newly installed postresql on OS X
Date: 2010-04-17 19:39:42
Message-ID: m2r5a8aa6681004171239h37fae9d9q59915d7f24ff4f8c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi

I have some experience with OS X and launchd so maybe I could shed a
little light on this.

On 16 April 2010 22:08, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> =?iso-8859-1?Q?S=F8ren_Krogh_Neigaard?= <soeren(at)neigaard(dot)com> writes:
>> When I issue the command "psql postgres", I get this message:
>> psql: could not connect to server: No such file or directory
>>       Is the server running locally and accepting
>>       connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
>
> Oh, well in that case you seem to not have a server running ... what was
> it you saw in ps exactly?

Also "sudo launchctl list" should show something like this:

53	-	org.macports.postgresql84-server

where "53" is the process ID of the PostgreSQL postmaster (I suppose)
and org.macports.postgresql84-server corresponds to an identifier in
the launchd plist file.

If there's no number in the first column, it means that launchd was
probably not able to start it and is probably trying to.  I suspect
that the launchd plist file tells launchd to restart it if it exits.

>> I found a tutorial that told me to do the following:
>
>> sudo mkdir -p /opt/local/var/db/postgresql84/defaultdb
>> sudo chown postgres:postgres /opt/local/var/db/postgresql84/defaultdb
>> sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb -D /opt/local/var/db/postgresql84/defaultdb'
>> sudo su postgres
>> /opt/local/lib/postgresql84/bin/createuser -s -P -l #MYUSER#
>
> That seems to be missing the step of starting the postmaster.

Yes, I believe the "sudo launchctl ..." command should be in there somewhere.

>> But still I get the same error when ever I try and run psql. But how
>> does postgresql know where to find my database files?
>
> The postmaster should be started by a step along the lines of
>
>        sudo su postgres -c '.../postmaster -D /opt/.../defaultdb &'
>
> However, if you're going to use the Macports startup script, it very

I haven't used Macports and don't know what their startup script for
PostgreSQL looks like, but they are apparently using launcd to run
PostgreSQL.

Søren said in the initial e-mail that he had run the following command:

sudo launchctl load -w
/Library/LaunchDaemons/org.macports.postgresql84-server.plist

The plist file mentioned in that command is an XML file which tells
launchd how to start something.  In that file it will mention the
actual startup script.

launchd is basically a combined init, atd, crond, inetd, rc.d/init.d
and can also run a program when a file is created in a directory.
Here's we're dealing with the rc.d/init.d or init part of it.  As
mentioned above, the plist file probably tells launchd to restart
PostgreSQL if it exits and to keep trying to start it.  This is like
running /sbin/getty from your /etc/inittab file on other systems.  If
launchd can't start it, it will try a few more times.  If it still
can't start it, launchd will wait for a few minutes before trying
another few times.  (This is exactly the sort of thing you'd get from
init on other systems.  i.e. "XXX spawning too fast.  Disabled for y
minutes.")

> probably has got a database location hard-wired into it --- you need to
> look at that script and see what it's using, rather than assuming that
> that tutorial matches the script.  Also, look to see where the script
> is sending the postmaster's stderr, and have a look into that logfile
> to see if the postmaster is reporting any useful error messages.

Launchd sends all stdout and stderr of processes it starts to the
system logs.  /var/log/system.log, if I remember correctly.  There's
an app called Console.app for looking at the logs if you're not
comfortable with the command line and tools like less, grep, etc.  In
Console.app you can look at just one of the logs (e.g. system.log) or
you can see all message.  I am not in front of a Mac at the moment, so
I can't remember the exact details.

By the way, this might be relevant:

http://svn.macports.org/repository/macports/trunk/dports/databases/postgresql84-server/Portfile

It implies that you have to initdb yourself.

I suspect looking at the logs in Console.app will be helpful.  If not
then looking at the startup script should at least tell us where it's
looking for the database.

-- 
Michael Wood <esiotrot(at)gmail(dot)com>

In response to

pgsql-novice by date

Next:From: machielrDate: 2010-04-19 09:55:34
Subject: Re: Calculating database sizes using a script
Previous:From: Bob McConnellDate: 2010-04-17 19:21:54
Subject: Re: Converting a table from SQL Server

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group