homebrew-postgresql
homebrew-postgresql copied to clipboard
Include LaunchAgent plist
Official postgresql formula includes a LaunchAgent plist, any reason for not including it?
+1
Looking briefly through the code there are two ways to generate automatically LaunchAgent .plist:
- by patching pg_createcluster, if one is to manage different versions with postgresql-common. Caveat: pg_createcluster is written in Perl. Even worse: it's targeted at managing Debian Linux which uses init scripts like other UNIXes and unlike OS X.
- in the formula, like other postgresql formulas. But then if postgresql-common is used, pg_createcluster won't know anything about the generated LaunchAgent file. The user will have to manually copy and edit the .plist to make it work with the generated clusters.
There is a plist here: http://sorescode.com/2013/05/17/installing-postgresql-93-beta-using-homebrew.html
Here is a thread that discusses why most of the proposed launchd.plist solutions are faulty: http://www.postgresql.org/message-id/[email protected]
@petere So what is recommended option for now? I just want some default cluster to start on boot, now I'm doing by hand this command on system start:
$ pg_ctlcluster 9.4 main start
@petere any ideas? What do you use?
+1
+1
What did everyone here do? I'm stuck just using pg_ctlcluster for now but would like an option to do on startup
Sorry to bother everyone on an old thread, but this is still a super useful tool and I'm trying to get my clusters to automatically start on boot.
This sorescode.com blog is offline now, but I found a cached version: http://web.archive.org/web/20200219121857/http://sorescode.com/2013/05/17/installing-postgresql-93-beta-using-homebrew.html
I read some of the replies on the postgres thread about launchd not being a good solution, and I believe the main concern was about launchd not waiting for the network to come up. Please correct me if I'm wrong, but I think that would only be relevant for daemons (in /System/Library/LaunchDaemons/
, etc.), and wouldn't apply for agents (in ~/Library/LaunchAgents
), since these are only run once the user logs in. (Presumably the OS would be ready to start the postgres cluster at that point.)
I have a Postgres 11 cluster named main
, and here is how I set it up to start on boot:
I created a launchd plist file at /usr/local/opt/postgresql@11/homebrew.postgresql-common.11-main.start.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.postgresql-common.11-main</string>
<key>LimitLoadToSessionType</key>
<array>
<string>Aqua</string>
<string>Background</string>
<string>LoginWindow</string>
<string>StandardIO</string>
<string>System</string>
</array>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/pg_ctlcluster</string>
<string>11</string>
<string>main</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/postgresql-common.11-main.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/postgresql-common.11-main.log</string>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>
(This just runs pg_ctlcluster 11 main start
.)
Symlinked it into ~/Library/LaunchAgents
:
ln -sfv /usr/local/opt/postgresql@11/homebrew.postgresql-common.11-main.start.plist ~/Library/LaunchAgents
And ran it to check that it works:
launchctl load ~/Library/LaunchAgents/homebrew.postgresql-common.11-main.start.plist
Then you can create more plists for any other clusters that you want to start. (P.S. Maybe a pg_ctlcluster start
or pg_ctlcluster all start
command would be helpful, to start all the clusters at once.)