Last active
June 8, 2022 18:29
-
-
Save andrewmcodes/960709c1e2daa24210db1e28233601f9 to your computer and use it in GitHub Desktop.
Start Redis and Postgres with asdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# PG | |
# Start with `switch_pg 13.6` for example | |
function pg_switch { | |
local version_to_run=$1 | |
local currently_running_version=$(psql --no-psqlrc -t -c 'show server_version;' postgres | xargs) | |
# check if you're erroneously switching to the same version | |
if [ "$version_to_run" = "$currently_running_version" ]; then | |
echo "Postgres $version_to_run is already running." | |
return 1 | |
fi | |
echo Switching from $currently_running_version to $version_to_run | |
# stop the currently running postgres server | |
$HOME/.asdf/installs/postgres/$currently_running_version/bin/pg_ctl \ | |
-D $HOME/.asdf/installs/postgres/$currently_running_version/data \ | |
stop | |
# start the server to be started | |
$HOME/.asdf/installs/postgres/$version_to_run/bin/pg_ctl \ | |
-D $HOME/.asdf/installs/postgres/$version_to_run/data \ | |
start | |
# switch the global asdf version, this ensures that `psql` is shimmed to the right version-directory | |
asdf global postgres $version_to_run | |
} | |
# Redis | |
# Start with `redis_start` | |
alias redis_start='redis-server --daemonize yes' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment