On Sat, 26 Jul 2008, Steve Atkins wrote:

The obvious thing to do is write a wrapper that will transparently run the right version of psql for the database it's connecting to. Has anyone already done that?

Several times, and I never seem to have the previous rev around when writing a new one (writing useful error checks is the time consuming part). The archives to my rescue: the attached is something I just whipped together which hopefully will be the last time I do this from scratch again 'cause I can just find this post instead. This presumes you've installed all the versions into a directory tree at /opt/pgsql/<version>, and you have to tweak the end of the script to make it run that command instead of just printing the output.

Sample session using the script:

$ cat systems
aaa     hosta   5432    8.2
bbb     hostb   5432    8.3
$ ./runpsql aaa
/opt/pgsql/8.2/bin/psql -h hosta -p 5432
$ ./runpsql bbb
/opt/pgsql/8.3/bin/psql -h hostb -p 5432
$ ./runpsql ccc
system "ccc" not found in systems listing file at: systems

It appends the stuff after the system name to the psql command, but you do have to worry about shell escaping with this simple implementation; example:

$ ./runpsql bbb -Atc \"select 1\"
/opt/pgsql/8.3/bin/psql -h hostb -p 5432 -Atc "select 1"

--
* Greg Smith [EMAIL PROTECTED] http://www.gregsmith.com Baltimore, MD
#!/bin/bash 
SYSTEM=$1
SYSLIST='systems'

shift
PARAM="$*"

if [ -z "$SYSTEM" ]; then
  echo Usage:  $0 systemname
  echo Uses the system listing in the file:  $SYSLIST
  exit 1
fi

if [ ! -f "$SYSLIST" ]; then
  echo Missing systems list file $SYSLIST
  exit 2
fi

LINE=`grep ^$SYSTEM $SYSLIST`
if [ $? -ne 0 ] || [ -z "$LINE" ]; then
  echo system \"$SYSTEM\" not found in systems listing file at:  $SYSLIST
  exit 3
fi

CMD=`echo $LINE | awk '{print "/opt/pgsql/" $4 "/bin/psql -h " $2 " -p " $3}'`
CMD="$CMD $PARAM"
echo $CMD
#$CMD
-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to