Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

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

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

7 Answers 7

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

share|improve this answer

On OSX 10.7.5 (Lion) using the default install of PostgreSQL 9.2.3

sudo su postgres -c "/Library/PostgreSQL/9.2/bin/pg_ctl -m fast -D /Library/PostgreSQL/9.2/data restart"

-m fast will kill the active connections

Use to start or stop in lieu of restartfor the corresponding actions

share|improve this answer

In 10.4 days it was...

sudo SystemStarter start PostgreSQL

Might still work.

share|improve this answer
    
This did the trick. –  Jan Jongboom Mar 14 '12 at 10:59
1  
SystemStarter has been deprecated in favor of launchctl in later versions of OSX. –  Adam Lassek May 23 '12 at 21:01

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
share|improve this answer
    
Possibly things ahve evolved on the homebrew side, but now, hombrew creates by default ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist –  Jerome Oct 1 at 15:15

use pg_ctl command to start the postgresql pg_ctl -D start

share|improve this answer

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

share|improve this answer

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

sudo port load postgresql92-server

(or whatever the version it is)...

But if it is working and you want to stop (or restart) it, just run:

sudo port unload postgresql92-server

To find out what the launch scripts are, run:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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