Running Postgres as Launch Daemon I am working on setting up a psql server and would therefore like postgres to run whenever the computer is on, regardless of whether I'm logged it. (The machine is running OS X Yosemite.) I set up a launch daemon to do this, but it doesn't work. syslog gives the following error messages:

Jul 14 17:43:01 user@server sudo[276]:     jaia : TTY=ttys000 ; 
PWD=/Users/jaia ; USER=root ; COMMAND=/usr/bin/nano /Library/LaunchDaemons/homeb
rew.mxcl.postgresql.plist
Jul 14 17:44:35 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): T
his service is defined to be constantly running and is inherently inefficient.
Jul 14 17:44:44 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): S
ervice only ran for 9 seconds. Pushing respawn out by 1 seconds.
Jul 14 17:44:45 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): S
ervice only ran for 0 seconds. Pushing respawn out by 10 seconds.


After that, the last message repeats indefinitely.

Here's my .plist file. The reason for sudo -u _postgres is that postgres can't run as root, which launch daemons do by default.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
  &lt;key&gt;KeepAlive&lt;/key&gt;
  &lt;true/&gt;
  &lt;key&gt;Label&lt;/key&gt;
  &lt;string&gt;homebrew.mxcl.postgresql&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;sudo&lt;/string&gt;
    &lt;string&gt;-u&lt;/string&gt;
    &lt;string&gt;_postgres&lt;/string&gt;
    &lt;string&gt;/usr/local/bin/pg_ctl&lt;/string&gt;
    &lt;string&gt;-D&lt;/string&gt;
    &lt;string&gt;/usr/local/var/postgres&lt;/string&gt;
    &lt;string&gt;start&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;
  &lt;key&gt;UserName&lt;/key&gt;
  &lt;string&gt;_postgres&lt;/string&gt;
  &lt;key&gt;WorkingDirectory&lt;/key&gt;
  &lt;string&gt;/usr/local/var/postgres&lt;/string&gt;
  &lt;key&gt;StandardErrorPath&lt;/key&gt;
  &lt;string&gt;/usr/local/var/postgres/server.log&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


MORE INFORMATION: Loading the job manually via ssh gives the ungrammatical error message "Could not find domain for". Loading it on the machine itself gives "/Library/LaunchDaemons/homebrew.mxcl.postgresql.plist: File exists".

What could be going wrong here?
Leave out the sudo, -u and _postgres in ProgramArguments. launchd takes care of this with the UserName key.