Skip to content

Instantly share code, notes, and snippets.

@snaga
Created October 6, 2012 13:31
Show Gist options
  • Save snaga/3844951 to your computer and use it in GitHub Desktop.
Save snaga/3844951 to your computer and use it in GitHub Desktop.
Switch postgresql version for all the commands with using alternatives.
#!/bin/sh
# alternatives-pgsql
#
# Switch postgresql version for all the commands with using alternatives.
#
# Copyright(C) 2012 Uptime Technologies, LLC. All rights reserved.
PATH=/usr/sbin:$PATH
export PATH
NUM=$1
if [ -z $NUM ]; then
echo "id must be specified. abort."
echo "Usage; $0 <num>"
echo "" | alternatives --config pgsql-psql | grep bin/psql
echo
exit;
fi;
find /etc/alternatives/pgsql-* | \
perl -e 's,.*/,,' -p | \
awk '{ print "echo '$NUM' | alternatives --config " $1 }' | \
sh
echo "" | alternatives --config pgsql-psql
@antevens
Copy link

Just adding for anyone else that finds this post, can also use a one-liner in the form of:

find /etc/alternatives/ -name 'pgsql-' -exec basename {} ; | xargs -L 1 alternatives --auto

@shawnweeks
Copy link

shawnweeks commented Mar 13, 2019

In case someone finds this on google again there was a slight typo in the command.
find /etc/alternatives/ -name 'pgsql-*' -exec basename {} \; | xargs -L 1 alternatives --auto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment