28

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!

Andrea Everett
  • 349
  • 2
  • 4
  • 4
  • 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 ``` – Noortheen Raja May 19 '23 at 16:10

10 Answers10

62

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
Gajen Sunthara
  • 4,470
  • 37
  • 23
  • 3
    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. – Swaathi Kakarla Oct 20 '21 at 06: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 Dec 01 '21 at 21:10
  • 7
    On M1 macs this folder is at `/opt/homebrew/var/postgres` – ook Jan 30 '22 at 11:28
  • On M1 macs, in order to check the logs, they're found in `/opt/homebrew/var/log` – dpd Jun 05 '23 at 09:32
36

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.

Ben Wilson
  • 2,271
  • 3
  • 26
  • 35
7

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.

  • 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 Mar 29 '22 at 02:35
  • in my case it was in: /usr/local/var/postgresql@12/postmaster.pid – nazar kuliyev Jun 09 '22 at 03:47
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

Taimoor Changaiz
  • 10,250
  • 4
  • 49
  • 53
chrisst
  • 1,696
  • 5
  • 19
  • 32
1

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

Undo
  • 25,519
  • 37
  • 106
  • 129
  • 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 Jan 10 '22 at 01:38
1

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
Nagesha S
  • 53
  • 5
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
zs11
  • 159
  • 5
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

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)
yuяi
  • 2,617
  • 1
  • 23
  • 46
-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!

  • 1
    That's just repeats an existing answer. – mustaccio Jun 24 '22 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? – anothernewbiecoder Jun 26 '22 at 03:13