After a reboot, postgres on my machine hasn't restarted. What command should I use in Terminal to get it going again?

link|improve this question
feedback

migrated from stackoverflow.com May 5 '10 at 5:45

This question came from our site for professional and enthusiast programmers.

7 Answers

For restarts:

To install postgres using port:

sudo port install postgresql84 postgresql84-server
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'

To launch on startup:

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

To start now:

sudo su postgres -c '/opt/local/lib/postgresql84/bin/postgres -D /opt/local/var/db/postgresql84/defaultdb'

To restart:

sudo su postgres -c 'pg_ctl -D /opt/local/var/db/postgresql84/defaultdb/ restart'

If you installed postgres using fink:

sudo su postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data restart'

Here's more information on Postgres from Apple themselves: http://developer.apple.com/internet/opensource/postgres.html

They show starting it with:

postgres@mail> /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

Obviously they logged in as postgres: sudo su - postgres

link|improve this answer
feedback

In 10.4 days it was...

sudo SystemStarter start PostgreSQL

Might still work.

link|improve this answer
This did the trick. – Jan Jongboom Mar 14 at 10:59
SystemStarter has been deprecated in favor of launchctl in later versions of OSX. – Adam Lassek 2 days ago
feedback

use pg_ctl command to start the postgresql pg_ctl -D start

link|improve this answer
feedback

Mac OS X uses a daemon called launchd that looks at a bunch of .plist configuration files and starts applications as needed (such as on startup, after a program dies, when a network port receives a request, when files are placed into a folder, and so forth.)

Look halfway down this page for details on how to "Create a launchd Launch Agent" to automatically start postgres for you. The instructions look right for Tiger, Leopard, and Snow Leopard. (Beyond that, google for "postgres launchd").

[IIRC, when I found and downloaded postgres for my Mac, the installer created the launchd script for me.]

link|improve this answer
feedback

Thanks @databyte. Just a quick heads-up: your restart command has a trailing oblique apostrophe, which will confuse the CLI if it is cut-and-pasted! Otherwise, thanks for the tip: seems to have worked for me!

(I'd +1 your answer, but I don't have sufficient rep yet.)

link|improve this answer
feedback

If you use macports to install postgresql, by default launching the postgres daemon is disabled and you need to run:

sudo port load postgresql91-server

(or whatever the version it is)...

To find out what the launch scripts are, run:

ls /Library/LaunchDaemons/*postgresql*
link|improve this answer
this was for 10.6 – Reza Toghraee Mar 11 at 2:56
feedback

If you installed postgres using homebrew, you need to use launchctl with the plist file located at ~/Library/LaunchAgents/org.postgresql.postgres.plist

launchctl unload ~/Library/LaunchAgents/org.postgresql.postgres.plist
launchctl load ~/Library/LaunchAgents/org.postgresql.postgres.plist
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.