Using multiple postgresql version with appropoiate psql and other pg tools version on mac with postgresapp
First make sure no postgres instance is configured to run on startup. And you get nothing when you run this command: which -a psql
This is to make sure you don't have anything related to postgres in your PATH, which can conflict.
If you do get some hits with above command, you have to manually either remove the installed versions of postgres or just fix PATH and remove ref to that path which has these binaries(psql, pg_dump etc)
For me, i was using brew installed postgres, i had to just comment out a PATH editing line which was inserted by brew in my .bash_profile
Ok, after this we are ready. Now things are simple:
1- Go ahead to https://postgresapp.com/downloads.html and download this release containing multiple versions.
2- Install normally like any other mac app
3- Now, here is some manual work. If you don't care which version of psql, pg_dump etc are used, you can follow official guide here: https://postgresapp.com/documentation/install.html
Which suggests running this command: sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
Infact, for first time installation do run this command anyway.
Now, each time you change postgres version in the postgres app(you can read PostgresApp/PostgresApp#445 (comment) on how to use multiple versions)
You now have to run this command:
echo /Applications/Postgres.app/Contents/Versions/9.6/bin | sudo tee /etc/paths.d/postgresapp
Don't forget to replace 9.6 with the version you are now running in the postgresapp. This will link the correct version tolls(psql/pg_dump etc).
I wrote this gist because it helped me solve some issues i was facing because of wrong version of pg tools. And errors were not helpful to figure the issue is of these versions, so i had to waste lot of hours finding the real issue.
Original idea is from: PostgresApp/PostgresApp#445 (comment)
See https://medium.com/keeping-code/running-multiple-postgresql-versions-simultaneously-on-macos-linux-90b3d7e08ffd
use pg_ctlcluster 12 main start
like commands