48

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!

1
  • 1
    In my case, I have started the service as root when it first failed. Re-installing didn't fix in that case. I had to stop it as root before starting as a normal user sudo brew services stop postgresql@14 brew services start postgresql@14 Commented May 19, 2023 at 16:10

12 Answers 12

84

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
4
  • 4
    Thank you! This was very helpful. I got a different error looking into the log, it was this: ``` 2021-10-20 12:06:41.065 IST [50107] FATAL: database files are incompatible with server 2021-10-20 12:06:41.065 IST [50107] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0. "root" execution of the PostgreSQL server is not permitted. ``` So I had to ensure I was installing the right version of Postgres. Commented Oct 20, 2021 at 6:41
  • I have the same error, but my error log says: "root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server. Not sure why as it isn't being launched as root.
    – Marty
    Commented Dec 1, 2021 at 21:10
  • 11
    On M1 macs this folder is at /opt/homebrew/var/postgres
    – ook
    Commented Jan 30, 2022 at 11:28
  • 3
    On M1 macs, in order to check the logs, they're found in /opt/homebrew/var/log
    – dpd
    Commented Jun 5, 2023 at 9:32
50

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.

2
  • 3
    Did the trick for me. Thanks! Commented Jan 19, 2022 at 14:20
  • It all makes sense now. Commented Jan 12, 2023 at 16:53
11

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.

3
  • 1
    Other macs may have it at: /usr/local/var/postgres/postmaster.pid OR /Users/[name]/Library/'Application Support'/Postgres/var/postmaster.pid I added a bash script: rm /opt/homebrew/var/postgresql@10/postmaster.pid && brew services restart postgresql@10 you may have to slightly tweak this
    – svey
    Commented Mar 29, 2022 at 2:35
  • 1
    in my case it was in: /usr/local/var/postgresql@12/postmaster.pid Commented Jun 9, 2022 at 3:47
  • Since the name updates with each version look in /usr/local/var/{your_version}/postmaster.id to find the file to remove
    – Matt
    Commented Aug 24 at 4:02
4

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

brew 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 :)

1
  • 2
    brew services upgrade postgresql gave me an error but brew upgrade postgresql let me installed a newer version of postgres. Just thought I'd mention it. :)
    – charint
    Commented Jan 10, 2022 at 1:38
3

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 install postgresql
  >  brew services run postgresql

2

For me it is working after doing this, I use mac intel chip. I have installed potgres using brew

$rm /usr/local/var/postgresql@14/postmaster.pid
$brew services restart postgresql
1

Restart instead of start, and specify version:

brew services restart postgresql@12
Stopping `postgresql@12`... (might take a while)
==> Successfully stopped `postgresql@12` (label: homebrew.mxcl.postgresql@12)
==> Successfully started `postgresql@12` (label: homebrew.mxcl.postgresql@12)
1

If you have the same error for mysql, and you ran a brew upgrade recently, keep in mind the following caveats :

Upgrading from MySQL <8.4 to MySQL >9.0 requires running MySQL 8.4 first:

If you run all of these commands, mysql should start fine.

1
  • it works, thank you
    – lidashuang
    Commented Sep 11 at 8:21
0

I got the same error:

% brew services start yabai
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/503 /Users/myuser/Library/LaunchAgents/
homebrew.mxcl.yabai.plist` exited with 5.

I have an extra user who manages brew called brew. After trying to run a brew service with sudo, this was a solution (on Apple silicon):

% sudo brew services stop yabai
% sudo chmod -R g+w /opt/homebrew 
% sudo chown -R brew /opt/homebrew 
% brew services start yabai
0

I have similar case with mysql, when I run:

brew services start mysql

It show : Failture while executing; /bin/launchctl bootstrap gui/1952607496 /Users/root/Library/LaunchAgents/homebrew.mxcl.mysql.plist exited with 5

All I have to do is run following line and start server again

rm /Users/root/Library/LaunchAgents/homebrew.mxcl.my
sql.plist
0

please remove

rm /opt/homebrew/var/postgresql@16/postmaster.pid 

After postgresql@16 will restart automatically.

-2

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!

2
  • 1
    That's just repeats an existing answer.
    – mustaccio
    Commented Jun 24, 2022 at 20:12
  • 1
    Okay? So does that mean I can’t phrase it in a way that I think is more helpful? Or in a way I think people will understand more? I’m trying to understand what the intention of your comment was? There’s multiple people repeating things in different ways in this thread? Why am I the only one you’re saying this to? Commented Jun 26, 2022 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.