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

24

10

I have recently installed Postgres on my Mac via Homebrew. (I may have already had it installed it was not running)

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

Now I am trying to start it with launchctl:

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

...but I am getting an error:

/usr/local/Cellar/postgresql/9.4.0/homebrew.mxcl.postgresql.plist: Operation not permitted

What does this error mean? What am I doing wrong? How can I fix the problem?

Andrew

Posted 2015-02-18T19:54:36.340

Reputation: 11 982

Apparently brew/OSX sometimes requires a restart before everything works. Before we all get into the problem-solving-mode: Did you try turning it off and on again?

– agtoever – 2015-02-27T13:09:34.100

Rebooting doesn't change anything. – Neil – 2015-04-06T19:37:04.103

Agreed, rebooting did not solve the problem. – Andrew – 2015-04-07T19:00:54.153

Answers

84

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

Tmux and Screen a 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.

Neil

Posted 2015-02-18T19:54:36.340

Reputation: 4 761

Thanks! You are right, I was using tmux! However, I seem to be running into a different issue now. Using launchctl outside of tmux, I see "Operation already in progress", yet I cannot connect to Postgres. – Andrew – 2015-04-07T19:03:16.060

I managed to solve my problem through some combination of unloading the launch agent plist, removing the old installation of Postgres, moving the old data directory, and reinstalling the latest version. – Andrew – 2015-04-15T18:10:37.213

Finally i stumbled on this and answered why I have been struggling with for more than a month . Finally i know the reason thanks for this... – kenju254 – 2015-06-17T10:36:49.053

2

A solution for this is to use reattach-to-user-session as mentioned here: http://apple.stackexchange.com/questions/41412/using-tmux-and-pbpaste-pbcopy-and-launchctl in your .tmux.conf

– bibstha – 2015-06-17T12:36:56.410

2

Here are the steps you may need to take:

Remove a previous installation of Postgres:

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 Postgres 9.4+: http://www.postgresql.org/docs/9.4/static/upgrading.html

Seems like you need two installations of Postgres 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 Postgres (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

Andrew

Posted 2015-02-18T19:54:36.340

Reputation: 11 982

0

Does running brew doctor resolve the issue or otherwise turn anything up?

(I can't post comments yet but this may help fix the issue)

Edit - I would run:

brew doctor
brew update
brew doctor
brew cleanup

ckreon

Posted 2015-02-18T19:54:36.340

Reputation: 11

Doesn't help, even after clearing any warnings from brew doctor. – Neil – 2015-04-06T19:37:31.797