DEV Community

Cover image for Postgresql not working on Mac M1 ARM: quick fix
Mattia Orfano
Mattia Orfano

Posted on

Postgresql not working on Mac M1 ARM: quick fix

Sometimes, shit happens.

Especially after a long work-day, when you have no energy left and decide to upgrade system libraries without understanding a dime... and boom! Everything breaks and stop working.

This is exactly what happened to me few weeks ago.

I launched a simple brew upgrade to have all formulae updated and after that my postgresql stopped working. From brew services list I saw:

postgresql@14   error 256 mattia ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
Enter fullscreen mode Exit fullscreen mode

mhh... wtf!??

So I thought, "maybe I have to start the service again..."

➜ ~ brew services start postgresql

Warning: Use postgresql@14 instead of deprecated postgresql
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/mattiaorfano/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.
Enter fullscreen mode Exit fullscreen mode

It seems they changed path to stable postgresql version and there is some wrong configuration in my system. What do I do?

"I'm tired as shit and don't want to fix this at 8PM"

"Tomorrow I can't work"

"Worse... I can't read all the databases"

"I'm fucked!"

I looked around and found few suggestions that involved reinstalling the entire postgresql instance.

"Absolutely not! I don't want to uninstall it and lose the data. There must be another solution..."

I took a long breath, stretched my arms, and created another #10stips that you're about to read (what's 10stips? the column where you learn how to solve issues within 10 seconds, because I already tested it for you).

Fix Postgresql installation on MAC M1 ARM

Instead of deleting and reinstalling the entire postgresql installation (you might lose your data!) I just did this:

brew services stop postgresql

using Activity monitor check if there are active postgres processes and kill them

reboot the system

rm -rf /opt/homebrew/var/postgres/postmaster.pid

brew services start postgresql@14
Enter fullscreen mode Exit fullscreen mode

Now, you might encounter another issue:

Library not loaded: '/opt/homebrew/opt/postgresql/lib/libpq.5.dylib' (LoadError)
  Referenced from: '/Users/mattiaorfano/.rbenv/versions/2.4.10/lib/ruby/gems/2.4.0/gems/pg-0.20.0/lib/pg_ext.bundle'
  Reason: tried: '/opt/homebrew/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file), '/opt/homebrew/Cellar/postgresql@14/14.5_1/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file) - /Users/mattiaorfano/.rbenv/versions/2.4.10/lib/ruby/gems/2.4.0/gems/pg-0.20.0/lib/pg_ext.bundle
Enter fullscreen mode Exit fullscreen mode

There is an incorrect library pathing for postgresql@14, and all you have to do is:

sudo ln -s /opt/homebrew/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Enter fullscreen mode Exit fullscreen mode

Launch the service again with brew services start postgresql@14 and now you can turn off the computer and go to sleep.

You're welcome ;-)

Top comments (4)

Collapse
 
matssigge profile image
Mats Sigge

I ran into the same thing. This seems to be related to this issue github.com/Homebrew/homebrew-core/.... Regarding the broken pg gem, the suggested solution (in this comment) to run bundle pristine pg worked for me. It forces a rebuild of the native extensions of the gem, which binds the gem to the updated lib folder, and you don't have to create the manual symlink in your last step.

Collapse
 
mattiaorfano profile image
Mattia Orfano

thanks for sharing

Collapse
 
matssigge profile image
Mats Sigge

And I forgot to say thanks for writing this up in the first place. 😊👍

Collapse
 
robin_heller_baa8a10fe931 profile image
Robin Heller

Geez! Thx, you saved my day!