Error while trying to start PostgreSQL installed via Homebrew: "Operation not permitted"

It could be that you're using launchctl inside of Tmux or Screen.

Tmux and Screen are terminal multiplexers that spawn multiple "screens" that you can easily switch between in a single terminal.

For some reason unknown to me, running launchctl inside of Tmux never works, and emits the error Operation not permitted. Run it inside of a normal shell and it will probably work just fine.


Here are the steps you may need to take:

Remove a previous installation of PostgreSQL:

brew remove postgres
rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Install the new version:

brew install postgres
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

The data from your previous installation will need to be upgraded to be compatible with PostgreSQL 9.4+: http://www.postgresql.org/docs/9.4/static/upgrading.html

It seems like you need two installations of PostgreSQL in order to upgrade your database, and I didn't care to bother with that, so I just recreated the database with the new version:

mv /usr/local/var/postgres /usr/local/var/old-postgres
initdb -D /usr/local/var/postgres

Now launch PostgreSQL (outside of tmux if you are using that):

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Check the logs for any issues:

tail /usr/local/var/postgres/server.log