homebrew. Cant start service. get "Bootstrap failed: 5: Input/output error - Postgres - Mac
Solution 1:
The issue is the previous install of postgres was postgres 13, and it created a database under:
/usr/local/var/postgres
which is now incompatible with the version of postgres you're installing, which is version 14.
First question: Do you care about your data?
If not then you can simply delete that folder and attempt to restart the service.
to delete and restart the service do:
rm -rf /usr/local/var/postgres
initdb --locale=C -E UTF8 /usr/local/var/postgres
brew services start postgresql
Otherwise you need to install postgresql@13, and perform a database migration, which can be summed up as follows:
install older postgres, make sure it's stopped
brew install postgresql@13
brew services stop postgresql@13
brew services stop postgres
delete the postgres 13 database created by the installation of postgresql@13
rm -rf /usr/local/var/postgresql@13
move old data to compatible driver folder:
mv /usr/local/var/postgres /usr/local/var/postgresql@13
Now we do the upgrade. First cd to the database folder
cd /usr/local/var
Construct a new blank database, with locale C, encoding of UTF8
initdb --locale=C -E UTF8 -D postgres
Perform the upgrade itself:
pg_upgrade -d postgresql@13 -D postgres -b /usr/local/Cellar/postgresql@13/13.4/bin -B /usr/local/Cellar/postgresql/14.0/bin -v
This should end in success. If it doesn't (e.g. locale/encoding is wrong), then chose the locale and encoding that matches the database.
Finally restart the postgres service:
brew services start postgresql
Solution 2:
The problem is really what @Petesh said. But, the resolution for me was simpler.
When you upgrade your postgresql with brew, it logs a success message. One thing registered will be:
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
So the only thing you need to do is to run the command below:
brew postgresql-upgrade-database
And of course you need to restart the service:
brew services restart postgresql
If you want to make sure it worked, you can run the start command too:
brew services start postgresql