Skip to content

Commit 9b89904

Browse files
committed
Add Switch The Running Postgres Server Version as a Postgres til
1 parent 3ce54d4 commit 9b89904

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1013 TILs and counting..._
13+
_1014 TILs and counting..._
1414

1515
---
1616

@@ -568,6 +568,7 @@ _1013 TILs and counting..._
568568
- [Storing Emails With citext](postgres/storing-emails-with-citext.md)
569569
- [String Contains Another String](postgres/string-contains-another-string.md)
570570
- [Switch Non-Castable Column Type With Using Clause](postgres/switch-non-castable-column-type-with-using-clause.md)
571+
- [Switch The Running Postgres Server Version](postgres/switch-the-running-postgres-server-version.md)
571572
- [Temporarily Disable Triggers](postgres/temporarily-disable-triggers.md)
572573
- [Temporary Tables](postgres/temporary-tables.md)
573574
- [Terminating A Connection](postgres/terminating-a-connection.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Switch The Running Postgres Server Version
2+
3+
I use [asdf](https://github.com/asdf-vm/asdf) install and manage multiple
4+
versions of Postgres on my Mac OSX machine. With `asdf` and project-based
5+
`.tools-versions` files, I can control what version of Postgres (`psql`) I use
6+
at a project-level.
7+
8+
The one snag with this workflow is managing the currently running server
9+
version. Lets say I need to switch from a project using `12.3` to a project
10+
using `13.1`. If the Postgres server running on my machine is using the
11+
Postgres server 12.3, then I'll need to manually stop that server and start up
12+
the Postgres server 13.1.
13+
14+
This can be done like so:
15+
16+
```bash
17+
# stop the 12.3 server
18+
$ $HOME/.asdf/installs/postgres/12.3/bin/pg_ctl \
19+
-D $HOME/.asdf/installs/postgres/12.3/data \
20+
stop
21+
22+
# start the 13.1 server
23+
$ $HOME/.asdf/installs/postgres/13.1/bin/pg_ctl \
24+
-D $HOME/.asdf/installs/postgres/13.1/data \
25+
start
26+
```
27+
28+
This uses the specific asdf-versioned `pg_ctl` command to stop and start the
29+
servers.
30+
31+
I've found it tedious to dig up these commands each time I need to switch, so I
32+
added a [`switch_pg` function to my `~/.zshrc`
33+
config](https://gist.github.com/jbranchaud/3cda6be6e1dc69c6f55435a387018dac).

0 commit comments

Comments
 (0)