I found this great article that got me started https://ivdl.co.za/2023/08/16/upgrading-from-postgresql-14-to-15-installed-with-homebrew-on-an-apple-silicon-mac/ only problem was that I was getting an error when referencing the postgresql@15 part so had to change that.

Upgrading from Postgres 14 to 15

Following the article we first have to install postgresql@15 with brew install postgresql@15.

Then made sure that neither 14 or 15 were running brew services stop postgresql@14 & brew services stop postgresql@15

The next part is where I have problems with the command shown in the article.

/opt/homebrew/Cellar/postgresql@15/15.4/bin/pg_upgrade -b /opt/homebrew/Cellar/postgresql@14/14.9/bin -d postgresql@14 -B /opt/homebrew/Cellar/postgresql@15/15.4/bin -D postgresql@15

I got a permission error to do with postgresql@15 🤷‍♂️

Running brew info postgresql@15 I found a path for postgresql@15

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@15

I replaced postgresql@15 with /opt/homebrew/var/postgresql@15 and did the same with postgresql@14 to come up with the following command

/opt/homebrew/Cellar/postgresql@15/15.4/bin/pg_upgrade -b /opt/homebrew/Cellar/postgresql@14/14.9/bin -d  /opt/homebrew/var/postgresql@14 -B /opt/homebrew/Cellar/postgresql@15/15.4/bin -D  /opt/homebrew/var/postgresql@15

This worked perfectly. I think we could use the bew info to build this command on any machine (I think Apple Intel installs will be different)

After this, we run brew services start postgresql@15 and check that our databases are available 👌

Upgrading from Postgres 15 to 16

We follow the same process as above. Install postgresql@16, brew install postgresql@16.

Stop 15 and 16, brew services stop postgresql@15 & brew services stop postgresql@16

Then upgrade,

/opt/homebrew/Cellar/postgresql@16/16.0/bin/pg_upgrade -b /opt/homebrew/Cellar/postgresql@15/15.4/bin -d  /opt/homebrew/var/postgresql@15 -B /opt/homebrew/Cellar/postgresql@16/16.0/bin -D  /opt/homebrew/var/postgresql@16

Start postgresql@16, brew services start postgresql@16 and check our databases 🚀

Other bits

pg gem

gem uninstall pg and then bundle install from a Rails project or gem install pg - you want to see it building with native extensions 👌

pg_dump and pg_config

brew link --force libpq