How should Postgres be installed to run as a daemon under user name _postgres on Mac OSX?

451 views Asked by At

I followed directions for installing Postgres on Mac OS X using Brew. All worked well. I placed a .plist in my Library/LaunchAgents and had Postgres running when I logged in. However, when I logged out postgres shuts down (which is correct behavior for processes started by launchd which are in a user's Library/LaunchAgents directory).

I wanted to have the database running all the time for all users so I tried to move my file homebrew.mxcl.postgresql.plist into the directory /Library/LaunchDaemons. I set the owner:group to root:wheel and set permissions as well. This didn't work as Postgres said it wouldn't run as root (reported in the log file in /usr/local/var/log). So I added a UserName and GroupName to be _postgres for each. It wouldn't run, and I believe there were permission issues, which I gather is that postgres running as postgres running as user:group of _postgres:_postgres cannot read files in /usr/local/var/postgres or /usr/local/var/log which are all sholland:admin for user:group (brew installed files under my userid holland and group admin). I changed the UserName to sholland and GroupName to admin in /Library/LaunchDaemons/homebrew.mxcl.postgresql.plist, and now postgres is running happily each restart as user sholland group admin.

This is all fine, but I would like to run Postgres under user _postgres instead. I imagine I could use sudo chown _postgre:_postgres * in /usr/local/var/log and /usr/local/var/postgres, but I don't know if there are other issues if I go that route. It seems that it would all be cleaner if brew did the install with user:group _postgres:_postgres instead of under my username and group admin.

The motivation to be able to set user:group in homebrew.mxcl.postgresql.plist to _postgres:_postgres is that I will be migrating the project to a linux system on a server at my hospital where I will use Django to run a report generator and patient tracking system for my GI group. I will need to run postgres under it's own user:group to keep permissions other than my personal userid in that environment.

So, how does one get brew to install postgres under user _postgres under Mac OS X?

0

There are 0 answers