I am using brew postgresql-upgrade-database to upgrade postgresql from 11.8 to 12 and migrate the data. The process failed with the following output
Upgrading postgresql data from 11 to 12...
Stopping postgresql#11... (might take a while)
==> Successfully stopped postgresql#11 (label: homebrew.mxcl.postgresql#11)
waiting for server to shut down.... done
server stopped
==> Moving postgresql data from /usr/local/var/postgres to /usr/local/var/postgres.old...
==> Creating database...
Error: Upgrading postgresql data from 11 to 12 failed!
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
Error: Failure while executing; /usr/local/Cellar/postgresql/12.4/bin/initdb --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --lc-messages=en_US.UTF-8 --lc-monetary=en_US.UTF-8 --lc-numeric=en_US.UTF-8 --lc-time=en_US.UTF-8 -E\ UTF8 /usr/local/var/postgres exited with 1.
How do I fix this?
There is an [issue][1] using brew postgresql-upgrade-database. I will update this answer when the issue is resolved.
As at July 21, 2021 this issue is still open. My workaround is below:
WARNING this will wipe out your databases so they have to be reloaded or re-initialized.
brew uninstall --force postgresql
brew install postgresql#12
cd /usr/local/var/
rm -rf postgres
initdb /usr/local/var/postgres
When doing the brew install read the post install message and make sure that you have the correct paths etc in your .zshrc (or equivalent file e.g. .bashrc). If you do not have this set your path correctly, the initdb command may work.
[1]: http://github.com/Homebrew/homebrew-core/issues/60686
Related
When trying to start postgresql
➜ ~ 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/josh/Library/LaunchAgents/homebrew.mxcl.postgresql#14.plist` exited with 5.
Getting "error" as status when running brew services list
➜ ~ brew services list
Name Status User File
postgresql#14 error 256 root ~/Library/LaunchAgents/homebrew.mxcl.postgresql#14.plist
PSQL was working perfectly fine, shut down my laptop (did not update) and when I turned it on the next day psql was not working. I am on OSX Version 12.6 (Monteray).
Had the same error today 🤓 on my Mac Ventura 13.0. Did these steps and it helped.
Run rm /usr/local/var/postgresql#{YOUR_VERSION}/postmaster.pid to remove postmaster.pid file. this is usually caused by an error in the postmaster.pid file.
Run brew services stop postgresql to stop the current postgresql service.
Then finally run brew services start postgresql, a new postmaster.pid file will be generated.
If this doesn't work you can run brew doctor and see if it will return Your system is ready to brew. If there are warnings 🥶, you can share them here with the community for more details.?
I had the same issue on 13.0 on M1 pro, all is did was brew services restart postgresql#14, it shut down, restarted and ran fine, issue gone.
Had the same issue, but couldn't get Postgres 14 working, and ended up just upgrading to Postgres 15, which I did get to work.
The steps looked like this (version numbers might vary)
brew services stop postgresql#14
brew install postgresql#15
# This command will copy data over to the new database
brew /opt/homebrew/Cellar/postgresql#15/15.1/bin/pg_upgrade -b /opt/homebrew/Cellar/postgresql#14/14.6/bin/ -d /opt/homebrew/var/postgres/ -D /opt/homebrew/var/postgresql#15/
brew services start postgresql#15
In my case, I had postgresql#13 and postgresql#14 install with brew on Ventura 13.1
I first removed postgresql#13 and all data within :
brew remove postgresql#13 and rm -rf /usr/local/var/postgresql#13
This assure me that the previous folder is fully remove, however, I did not care about my local data ... you may want to take care of it before doing this
After that, I reinstall postgresql#14 within the following commands :
# Remove postgresql 14 with brew
brew remove postgresql#14
# Reinstall postgresql 14 with brew
brew install postgresql#14
# Remove all the files in the db folder
rf -rf /usr/local/var/postgresql#14/*
# Kill all process that run any db of the postgresql 14 folder
pkill -f /usr/local/var/postgresql#14
# Initialize the db folder for postgresql 14
initdb --locale=C -E UTF-8 /usr/local/var/postgresql#14
# Restart postgresql with brew (should say that it's already running)
brew services start postgresql#14
I am trying to prevent my current version of posgtgresql being upgraded. Accordingly I did brew pin postgresql#12. However I am finding that if I do
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
I get the following error message
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
Looking at the log output, the last lines are
2022-05-01 17:31:00.816 AEST [18650] FATAL: database files are incompatible with server
2022-05-01 17:31:00.816 AEST [18650] DETAIL: The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 14.2.
so postgresql has been updated to version 14.2.
If I do brew list --pinned it shows
postgresql#10
postgresql#11
postgresql#12
so I am still have postgresql#12 pinned. So why has the pinning not worked, and how do I restore posgresql to version 12?
I notice that if I do brew services list I see
postgresql none
postgresql#10 none
postgresql#11 none
postgresql#12 error 6 Chris ~/Library/LaunchAgents/homebrew.mxcl.postgresql#12.plist
i.e. postgresql#14 is not listed, so perhaps postgresql was upgraded in some other manner than using brew? However, I certainly did not do explicit upgrade, so do not see how this could have happened.
In lieu of an answer to this question, the way I recover from this situation is explained in this SO answer.
In brief (warning this destroys the databases)
brew uninstall --force postgresql
brew install postgresql#12
cd /usr/local/var/
rm -rf postgres
initdb /usr/local/var/postgres
Trying to look on the bright side, it is an opportunity to upgrade your databases by either a minor or major version.
I just got a new Macbook Pro M1 and have been trying to install Postgres with homebrew. After trying a bunch of different approaches from installing different versions of Postgres to trying rm /usr/local/var/postgres/postmaster.pid I've had no luck. I am at the point now where I can't even successfully install Postgres without an error message. When I uninstall and then reinstall use brew install postgres I get:
➜ ~ brew install postgres
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/manifests/14.1_1
Already downloaded: /Users/landonlapensee/Library/Caches/Homebrew/downloads/34e850b9c47867f84334b48fe844f7a171369d777b5c118a4119297f7c215147--postgresql-14.1_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/blobs/sha256:027c8b48406c3d732241426e0f5d2caf9f48cb4d2d38610b8f5d46f0adf7a89f
Already downloaded: /Users/landonlapensee/Library/Caches/Homebrew/downloads/b74d7a88df70e29d3cd5714896c2dd5b16a1e8c01188164026a4b5762f18234b--postgresql--14.1_1.monterey.bottle.tar.gz
==> Pouring postgresql--14.1_1.monterey.bottle.tar.gz
==> /usr/local/Cellar/postgresql/14.1_1/bin/initdb --locale=C -E UTF-8 /usr/local/var/postgres
Last 15 lines from /Users/landonlapensee/Library/Logs/Homebrew/postgresql/post_install.01.initdb:
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting default time zone ... America/Vancouver
creating configuration files ... ok
running bootstrap script ... 2021-12-07 10:07:39.032 PST [52558] FATAL: could not create shared memory segment: Cannot allocate memory
2021-12-07 10:07:39.032 PST [52558] DETAIL: Failed system call was shmget(key=1895806, size=56, 03600).
2021-12-07 10:07:39.032 PST [52558] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMALL parameter. You might need to reconfigure the kernel with larger SHMALL.
The PostgreSQL documentation contains more information about shared memory configuration.
child process exited with exit code 1
initdb: removing contents of data directory "/usr/local/var/postgres"
Warning: The post-install step did not complete successfully
You can try again using:
brew postinstall postgresql
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
https://www.postgresql.org/docs/14/app-initdb.html
To restart postgresql after an upgrade:
brew services restart postgresql
Or, if you don't want/need a background service you can just run:
/usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
==> Summary
🍺 /usr/local/Cellar/postgresql/14.1_1: 3,304 files, 43.9MB
==> Running `brew cleanup postgresql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Then if I run brew services start postgres I get:
➜ ~ brew services start postgres
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/landonlapensee/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5
If I run psql I get:
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/landonlapensee/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5.
➜ ~ psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
And if I run ➜ ~ rm /usr/local/var/postgres/postmaster.pid I get:
rm: /usr/local/var/postgres/postmaster.pid: No such file or directory
I am so lost on this issue. I am trying to set this up to use for a ruby on rails environment. Does anybody know what could be causing this issue? (I tried so many different threads/commands that I think I have created root files that are causing conflicts)
Or does anybody of any suggestions of any paid services that could walk me through fixing this?
BIG THANKS!
I had the same problem. Apparently it did not start the server after reinstalling because there was another server, postgresql#13 (the previous version before updating) still running. I killed the process and then it started the updated server.
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:
I have changed the method column to trust in my hba_pg files.
I have tried the command ALTER in the terminal to change the password.
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.
The command chpass to change my user's password.
Help would be much appreciated. Thank you!
This is what I did to resolve on my Mac.
Looked at the postgres.log cat /usr/local/var/log/postgres.log | tail -100
Found the following error on my logs FATAL: lock file "postmaster.pid" already exists
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.
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
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 :)
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
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.
Try stoping it with brew services stop postgresql
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!
running brew services start mongodb-community which yields:
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/<myUserName>/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.
when I run launchctl load -w /Users/<myUserName>/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
yields
Load failed: 5: Input/output error
I recently upgraded macOs to BigSur 11.5.2.
Ive uninstall and reinstalled homebrew and xcode.
try this
brew services restart <mongodb-community#4.4>
I am able to run mongodb through homebrew. I believe this solved my issue:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
followed by
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
I saw this issue with MySQL and the solution was my current profile was not the owner of my homebrew folder.
I had to change it because I have a second profile set up for another work space, but they share the same homebrew path.
I would suggest anyone who sees this error try running
sudo chown -R $(whoami) $(brew --prefix)/*
And then seeing if that will resolve it. Again I didn't have this issue with MongoDB, but I saw this exact error with MySQL when my profile didn't own the brew folder.
Try this if you tried to restart your service, but it still doesn't work
stop your service
brew services stop mongodb-community
restart your macOS
start your service again
brew services start mongodb-community
To see the real errors, you need to run the service without brew
I had a similar problem, but instead of mongodb, I could not start apache(httpd).
$ brew services start httpd
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/john/Library/LaunchAgents/homebrew.mxcl.httpd.plist` exited with
5.
FAIL: 1
Unfortunately brew doesn't show the user what causes this error. At first I tried to use the tips from the answers in this thread, but neither reinstalling apache nor unload -w/load -w helped.
I also found nothing in the brew logs. I decided to investigate apache itself. To do this I ran apache without brew:
$ /opt/homebrew/Cellar/httpd/2.4.51/bin/apachectl start
httpd: Syntax error on line 66 of /opt/homebrew/etc/httpd/httpd.conf: Cannot load /opt/homebrew/Cellar/php#5.6/5.6.40_3/lib/httpd/modules/libphp5.so into server: dlopen(/opt/homebrew/Cellar/php#5.6/5.6.40_3/lib/httpd/modules/libphp5.so, 0x000A): tried: '/opt/homebrew/Cellar/php#5.6/5.6.40_3/lib/httpd/modules/libphp5.so' (no such file), '/usr/local/lib/libphp5.so' (no such file), '/usr/lib/libphp5.so' (no such file)
FAIL: 1
Then it was finally clear what was the reason why httpd service was not starting. It turned out that after the php upgrade, the php version had changed and I forgot to write the new php version in the apache configuration file.
I quickly fixed this and apache started up.
It seems that the mongodb-community is already started. So do restart it instead of starting, by the following command:
brew services restart mongodb-community
I faced a similar problem with postgresql 11 and restarting the service did not help. The issue arose when my MacBook restarted abruptly.
After checking the ports and trying out all the possible solutions, I decided to look into the logs.
tail -n 100 /usr/local/var/log/postgresql#11.log
This gave me the last 100 lines of the log where I found this:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 479) running in data directory "/usr/local/var/postgresql#11"?
Clearly, the issue was with postmaster.pid so I deleted it:
rm /usr/local/var/postgresql#11/postmaster.pid
Started the postgres service again:
brew services start postgresql#11
and voila! It worked.
I had similar error in regard to postgres.
$ brew services start postgresql
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/yrk/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5.
I've tried restart and it looked promising:
$ brew services restart postgres
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
But there still was a problem when trying to connect:
$ psql -d postgres -U apiuser
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Checking postgres log as mentioned by #mansoor.khan helped, in my case it was:
tail /usr/local/var/log/postgres.log.
And the issue was clear:
$ tail /usr/local/var/log/postgres.log
2022-05-19 14:18:46.029 CEST [32374] FATAL: database files are incompatible with server
2022-05-19 14:18:46.029 CEST [32374] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:18:56.071 CEST [32676] FATAL: database files are incompatible with server
2022-05-19 14:18:56.071 CEST [32676] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:06.111 CEST [32885] FATAL: database files are incompatible with server
2022-05-19 14:19:06.111 CEST [32885] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:16.128 CEST [33102] FATAL: database files are incompatible with server
2022-05-19 14:19:16.128 CEST [33102] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:26.166 CEST [33434] FATAL: database files are incompatible with server
2022-05-19 14:19:26.166 CEST [33434] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
Now the problem is: how to revert to previous version or upgrade old data to new version of postgres DB, but this is for another topic.
run something like launchctl remove homebrew.mxcl.mongodb-community before the load command solved my problem
I had this when upgrading from 4.4 to 5.0 and I suspect it’s similar for you. Lets assume you were upgrading 5.x to 6.x then the resolution would be ...
check your mongo log, e.g.
vi /usr/local/var/log/mongodb/mongo.log
Look for any errors relating to file/directory permissions and fix those, e.g. though I’m not quite sure whether ‘wheel’ or ‘admin’ is right.
sudo chown yourloginname:wheel thedirectory/*
Roll back to your previous working version of mongo (e.g. 5.x)
Start Mongo 5
Start a Mongo Shell and type
db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
Check the logs to verify the database has detected 5.0
Uninstall 5.x
Re-install 6.x
Restart / start 6.x
It should now work?
In my case, another httpd process was running on the Mac. Killed with monitor tool allowed me to start httpd.
I had a similar problem on mysql.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/gerd/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
In my case the mysqld miss the osx network connection permission. After restart OSX it appear the network permissions dialog. I granted the permission to msqld and the problem was fixed!
Happened with redis. Realized there was a bind setting in the config, binding the server to an incorrect ip address.
I faced the same problem. This commands helped me
brew uninstall rabbitmq
brew uninstall erlang
brew install rabbitmq
brew services restart rabbitmq
You may run into this if the service is already running, but as another user.
For example, you may have run sudo brew services start example and are now running brew services info example. It tells you it's not running and you think "hm, it should be running" and enter brew services start example.
Potentially example is already bound to, say, port 7777 and now you ask for another program to be bound to the same port, leading to a failing service start.
In short: If you are binding to a port, check if the same service is already running as another user and bound to the same port.