5: Input/output error Error: Failure while executing; `/bin/launchctl bootstrap gui/502 and FATAL: password authentication failed for user

Viewed 27996

The error 5: Input/output Error: Failure while executing; /bin/launchctl bootstrap gui/502 /Users/Andrea/Library/LaunchAgents/homebrew.mxcl.postgresql.plist exited with 5 is occurring when typing in the command "brew services start postgresql".

I am trying to create a database using homebrew and postgresql. If I type the command "brew services stop postgresql" and then start it back up the error does not occur. But will reoccur on the initial start of postgresql.

After, I stop postgresql and restart it using homebrew I type in "createdb 'test'. This error appears:

"error: could not connect to database template1: FATAL: password authentication failed for user "Andrea". Initially I tried to primarily work on the password authentication with no luck.

Here are the steps I have taken:

  1. I have changed the method column to trust in my hba_pg files.
  2. I have tried the command ALTER in the terminal to change the password.
  3. I created a root login on my computer, where I tried to access the file and use the root's password to create the database.
  4. The command chpass to change my user's password.

Help would be much appreciated. Thank you!

6 Answers

This is what I did to resolve on my Mac.

  1. Looked at the postgres.log cat /usr/local/var/log/postgres.log | tail -100
  2. Found the following error on my logs FATAL: lock file "postmaster.pid" already exists
  3. Fix above PID issue and restart the server.
rm /usr/local/var/postgres/postmaster.pid 
brew services restart postgresql

Sometimes this can be solved by simply running

brew services restart postgresql

instead of

brew services start postgresql

It happens when a previous postgres process doesn't terminate properly (maybe because you killed a psql process in activity monitor or otherwise). Restarting appears to properly unlock/delete the postmaster.pid file where "start" doesn't.

On the m1 mac I had the same issue and had to remove the postmaster.pid file as well. For m1 macs, the file is at /opt/homebrew/var/postgres/postmaster.pid, so I ran

/opt/homebrew/var/postgres/postmaster.pid

and I could brew services start postgresql successfully.

To build on what @gajen-sunthara said, I made sure to upgrade my postgresql installation:

brew services upgrade postgresql

Then removed the postmaster.pid:

rm /usr/local/var/postgres/postmaster.pid 

And restarted postgresql:

brew services restart postgresql

And that should get it going again :)

The other answers didn't apply because I didn't have the pid file (or many other files in those directories). The same error was caused by a bad install, most likely because I had previously installed libpq to get the psql CLI in isolation previously as per: Correct way to install psql without full Postgres on macOS?.

Solution, clean install:

brew uninstall postgresql
brew uninstall libpq

brew uninstall postgresql
brew services run postgresql

I know this has already been answered, but for anyone seeing this in the future, here is some help.

This often happens because it wasn't properly stopped when it was used at a different time, and the version you are using now has a conflict with what you were running previously. There are a few ways to fix it.

  1. Try stoping it with brew services stop postgresql
  2. Start it with brew services start postgresql

You can also just do brew services restart postgresql and not do step 1 and 2. Hope this helps someone!

Related