mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Switch The Running Postgres Server Version as a Postgres til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1013 TILs and counting..._
|
||||
_1014 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -568,6 +568,7 @@ _1013 TILs and counting..._
|
||||
- [Storing Emails With citext](postgres/storing-emails-with-citext.md)
|
||||
- [String Contains Another String](postgres/string-contains-another-string.md)
|
||||
- [Switch Non-Castable Column Type With Using Clause](postgres/switch-non-castable-column-type-with-using-clause.md)
|
||||
- [Switch The Running Postgres Server Version](postgres/switch-the-running-postgres-server-version.md)
|
||||
- [Temporarily Disable Triggers](postgres/temporarily-disable-triggers.md)
|
||||
- [Temporary Tables](postgres/temporary-tables.md)
|
||||
- [Terminating A Connection](postgres/terminating-a-connection.md)
|
||||
|
||||
33
postgres/switch-the-running-postgres-server-version.md
Normal file
33
postgres/switch-the-running-postgres-server-version.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Switch The Running Postgres Server Version
|
||||
|
||||
I use [asdf](https://github.com/asdf-vm/asdf) install and manage multiple
|
||||
versions of Postgres on my Mac OSX machine. With `asdf` and project-based
|
||||
`.tools-versions` files, I can control what version of Postgres (`psql`) I use
|
||||
at a project-level.
|
||||
|
||||
The one snag with this workflow is managing the currently running server
|
||||
version. Lets say I need to switch from a project using `12.3` to a project
|
||||
using `13.1`. If the Postgres server running on my machine is using the
|
||||
Postgres server 12.3, then I'll need to manually stop that server and start up
|
||||
the Postgres server 13.1.
|
||||
|
||||
This can be done like so:
|
||||
|
||||
```bash
|
||||
# stop the 12.3 server
|
||||
$ $HOME/.asdf/installs/postgres/12.3/bin/pg_ctl \
|
||||
-D $HOME/.asdf/installs/postgres/12.3/data \
|
||||
stop
|
||||
|
||||
# start the 13.1 server
|
||||
$ $HOME/.asdf/installs/postgres/13.1/bin/pg_ctl \
|
||||
-D $HOME/.asdf/installs/postgres/13.1/data \
|
||||
start
|
||||
```
|
||||
|
||||
This uses the specific asdf-versioned `pg_ctl` command to stop and start the
|
||||
servers.
|
||||
|
||||
I've found it tedious to dig up these commands each time I need to switch, so I
|
||||
added a [`switch_pg` function to my `~/.zshrc`
|
||||
config](https://gist.github.com/jbranchaud/3cda6be6e1dc69c6f55435a387018dac).
|
||||
Reference in New Issue
Block a user