Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 May 5 '10 at 5:45

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

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:

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
I don't have a user postgres, the default install does not create this. – IanVaughan Jul 9 '15 at 7:19

On OS X 10.7.5 (Lion), with 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 start or stop in lieu of restart for the corresponding actions.

share|improve this answer
Added a \ to the end of the first line so that bash wouldn't try interpreting /Library/PosgreSQL/9.2/data as an executable, but as an argument to pg_ctl. – ArtOfWarfare Oct 21 '15 at 22:36

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 '14 at 15:15

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
SystemStarter has been deprecated in favor of launchctl in later versions of OSX. – Adam Lassek May 23 '12 at 21:01

After wrestling with this for a long time, I added a simple function to my .bash_profile to make this easier:

pgctl_func() {

    if [ -z $1 ]; then
       echo "usage: pgctl start|stop|restart"
       return 0

    pgctl_cmd=$(mktemp -t "$0")
    echo 'source $HOME/; ' > pgctl_cmd
    echo "pg_ctl -m fast $1" >> pgctl_cmd

    sudo su -l postgres < pgctl_cmd
alias pgctl='pgctl_func'
share|improve this answer

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


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.