1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Manage Major Versions With Brew And Direnv as a Postgres TIL

This commit is contained in:
jbranchaud
2024-02-18 13:06:55 -06:00
parent 4e4b9b3d25
commit e86c36eff4
2 changed files with 42 additions and 1 deletions

View File

@@ -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). 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 Database Users](postgres/list-database-users.md)
- [List Various Kinds Of Objects](postgres/list-various-kinds-of-objects.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) - [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) - [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) - [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) - [pg Prefix Is Reserved For System Schemas](postgres/pg-prefix-is-reserved-for-system-schemas.md)

View File

@@ -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.