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

Creating a db on my newly installed postresql on OS X

From
Søren Krogh Neigaard
Date:
Hi

Im totally new to postgresql. I installed 8.4.3 via MacPorts, and it told me to run this command to have postgresql
startat boot: 

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

I can see with a ps command that there are something runing. So what next? I can read that I must use initdb to create
adatabase, and give it a path to a file/directory where the data will be stored, but will the running postgresql server
thenknow where this database/data is? 

What are the next steps to get me up and running?

Med venlig hilsen/Best regards
Søren Neigaard <soeren@neigaard.com>

If I'd known computer science was going to be like this, I'd never have given up being a rock 'n' roll star.


Attachment

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

From
Tom Lane
Date:
=?iso-8859-1?Q?S=F8ren_Krogh_Neigaard?= <soeren@neigaard.com> writes:
> Im totally new to postgresql. I installed 8.4.3 via MacPorts, and it told me to run this command to have postgresql
startat boot: 

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

> I can see with a ps command that there are something runing. So what next? I can read that I must use initdb to
createa database, and give it a path to a file/directory where the data will be stored, but will the running postgresql
serverthen know where this database/data is? 

If the server is running, there must already be a valid data directory
for it to work in.  I'm not familiar with the MacPorts package but it
seems likely that that daemon script ran initdb for you --- you could
look into the script to check.

> What are the next steps to get me up and running?

Try "psql postgres" and see what happens.

            regards, tom lane

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

From
Søren Krogh Neigaard
Date:
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"?

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#

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?Or is it something else that is my problem? 

Med venlig hilsen/Best regards
Søren Neigaard <soeren@neigaard.com>

If I'd known computer science was going to be like this, I'd never have given up being a rock 'n' roll star.

On 16/04/2010, at 19.01, Tom Lane wrote:

> =?iso-8859-1?Q?S=F8ren_Krogh_Neigaard?= <soeren@neigaard.com> writes:
>> Im totally new to postgresql. I installed 8.4.3 via MacPorts, and it told me to run this command to have postgresql
startat boot: 
>
>> sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql84-server.plist
>
>> I can see with a ps command that there are something runing. So what next? I can read that I must use initdb to
createa database, and give it a path to a file/directory where the data will be stored, but will the running postgresql
serverthen know where this database/data is? 
>
> If the server is running, there must already be a valid data directory
> for it to work in.  I'm not familiar with the MacPorts package but it
> seems likely that that daemon script ran initdb for you --- you could
> look into the script to check.
>
>> What are the next steps to get me up and running?
>
> Try "psql postgres" and see what happens.
>
>             regards, tom lane


Attachment

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

From
Tom Lane
Date:
=?iso-8859-1?Q?S=F8ren_Krogh_Neigaard?= <soeren@neigaard.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?

> 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.

> 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
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.

            regards, tom lane

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

From
Michael Wood
Date:
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@sss.pgh.pa.us> wrote:
> =?iso-8859-1?Q?S=F8ren_Krogh_Neigaard?= <soeren@neigaard.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@gmail.com>