I was using Postgres universal (postgresql package managed by brew) and I had installed postgresql@14 managed version by brew at the same time. This instruction covers what to do if you use postgresql@14 managed by brew or the universal version.
This instruction is inspired by the issue.
You can change the version to the one that you want to upgrade to. It's recommended to upgrade one version at a time.
brew install postgresql@15
brew services stop postgresql@14
Stop Postgres universal that is managed outside of brew. Do it only if brew services stop postgresql@14
does not stop the Postgres because you use the universal version:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Migrate local DBs from 14 to 15. Use this command only if you use Postgres universal. See the path is different for the -d
option.
/opt/homebrew/opt/postgresql@15/bin/pg_upgrade -b /opt/homebrew/opt/postgresql@14/bin -d /opt/homebrew/var/postgres -D /opt/homebrew/var/postgresql@15
Otherwise, if you use postgresql@14 managed by brew use the following directory path for the -d
option:
/opt/homebrew/opt/postgresql@15/bin/pg_upgrade -b /opt/homebrew/opt/postgresql@14/bin -d /opt/homebrew/var/postgresql@14 -D /opt/homebrew/var/postgresql@15
Unlink old Postgres to ensure the psql command version 14 is no longer used:
brew unlink postgresql@14
Link the new one:
brew link postgresql@15 --force
Start Postgres 15.
brew services start postgresql@15
Type psql
in the terminal, you should use the client version 15.
Type:
select version();
You should see the Postgres 15 version.
All should be fine now.
Run a Rails app you have locally. It should work, but it still uses old Postgres 14 client provided by brew.
Remove Postgres 14 only if you are sure everything works with your project DB locally after the DB migration done via pg_upgrade
.
brew uninstall postgresql@14
After you uninstalled it. You may need to remove the pg
gem to unlink it from the old version of Postgres 14.
Run in the Rails app folder:
gem uninstall pg
(select all)
Now reinstall the pg
gem.
bundle install
The Rails app should work now and use a new Postgres 15 local client:
bin/rails server
If you find this helpful, check the Knapsack Pro for parallel testing in your Rails app