diff --git a/README.md b/README.md index f80a467..0365545 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1369 TILs and counting..._ +_1370 TILs and counting..._ --- @@ -722,6 +722,7 @@ _1369 TILs and counting..._ - [List Database Users](postgres/list-database-users.md) - [List Various Kinds Of Objects](postgres/list-various-kinds-of-objects.md) - [Lower Is Faster Than ilike](postgres/lower-is-faster-than-ilike.md) +- [Manage Major Versions With Brew And Direnv](postgres/manage-major-versions-with-brew-and-direnv.md) - [Max Identifier Length Is 63 Bytes](postgres/max-identifier-length-is-63-bytes.md) - [Open Heroku Database In Postico From Terminal](postgres/open-heroku-database-in-postico-from-terminal.md) - [pg Prefix Is Reserved For System Schemas](postgres/pg-prefix-is-reserved-for-system-schemas.md) diff --git a/postgres/manage-major-versions-with-brew-and-direnv.md b/postgres/manage-major-versions-with-brew-and-direnv.md new file mode 100644 index 0000000..eddb1a3 --- /dev/null +++ b/postgres/manage-major-versions-with-brew-and-direnv.md @@ -0,0 +1,40 @@ +# Manage Major Versions With Brew and Direnv + +I can install multiple major versions of PostgreSQL to my machine with `brew` +with commands like the following: + +```bash +$ brew install postgresql@14 +$ brew install postgresql@16 +$ # ... +``` + +I can then start and stop specific Postgres server versions using the `brew +services start/stop` commands. Let's say 14 is running, but I want to switch to 16. + +```bash +$ brew services stop postgresql@14 +$ brew services start postgresql@16 +``` + +Then I can use [`direnv`](https://direnv.net/) to manage the Postgres client +(bin directory) that gets used for certain projects. This way when I run a +command like `pg_dump` or `psql` it will use the one associated with a specific +major version of Postgres. + +Assuming I already have `direnv` installed, I can add a `.envrc` to my project +with the following line: + +``` +PATH_add /usr/local/opt/postgresql@16/bin +``` + +And then tell my system that the changes to this file are allowed to be sourced +by `direnv`: + +```bash +$ direnv allow . +``` + +That's it. Now I have PostgreSQL 16 (client and server) ready to use for my +current project.