Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to set the $PATH to pick up the latest version of pg_dump as I'm currently getting a mismatch error while doing a migrate in my Rails app (I recently changed the schema type to SQL).

I have added a new file in /etc/profile.d called pg_dump.sh, and inside that put:

PG_DUMP=/usr/pgsql-9.1
export PG_DUMP
PATH=$PATH:$PG_DUMP/bin
export PATH

On looking at echo $PATH, I get:

/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/pgsql-9.1/bin:/root/bin

And I still get the error.

Do I need to change the order? If so any ideas how?


Output of 'ls /usr/pgsql-9.1/bin':

clusterdb droplang pg_archivecleanup pg_ctl pg_standby psql createdb dropuser pg_basebackup pg_dump pg_test_fsync reindexdb createlang ecpg pgbench pg_dumpall pg_upgrade vacuumdb createuser initdb pg_config pg_resetxlog postgres vacuumlo dropdb oid2name pg_controldata pg_restore postmaster

And output of 'which pg_dump':

/usr/bin/pg_dump


Error message on running cap 'deploy:migrate':

 ** [out :: 46.4.9.199] pg_dump: server version: 9.1.4; pg_dump version: 8.4.11
 ** [out :: 46.4.9.199] pg_dump: aborting because of server version mismatch
 ** [out :: 46.4.9.199] rake aborted!
 ** [out :: 46.4.9.199] Error dumping database

output of 'pg_dump --version':

pg_dump (PostgreSQL) 8.4.11

share|improve this question
    
What is the output of "ls /usr/pgsql-9.1/bin"? And "which pg_dump"? –  Eric DANNIELOU Sep 11 '12 at 20:16
    
Hi Eric, I have added the outputs above. –  A4J Sep 11 '12 at 20:28
    
Thanks does it work better if in your script you replace PATH=$PATH:$PG_DUMP/bin by PATH=$PG_DUMP/bin:$PATH? By the way what is the error message and the expected result? –  Eric DANNIELOU Sep 11 '12 at 20:41
    
Hi again Eric, I have updated the post above with the error message. I am using Capistrano, and running cap deploy:migrate on my local machine which runs rake db:migrate on the production server. I'm not sure I can change the script to use a different path (?) Btw, when I try $pg_dump --version, I get: pg_dump (PostgreSQL) 8.4.11 - which makes me think I just need to get the new path before the old one in $PATH? –  A4J Sep 11 '12 at 20:52
    
Short answer : Yes. But there might exist some cleaner solutions. –  Eric DANNIELOU Sep 11 '12 at 20:57
show 2 more comments

2 Answers

up vote 1 down vote accepted

A quick and dirty solution would be to edit /etc/profile.d/pg_dump.sh :

PG_DUMP=/usr/pgsql-9.1
export PG_DUMP
PATH=$PG_DUMP/bin:$PATH
export PATH
share|improve this answer
    
You should also consider figuring out (a) WHY you have multiple Postgres versions (or at least clients) installed, and (b) if you need them (If you don't need them, get rid of the older ones -- 9.x clients should be fine talking to 8.x databases, though obviously you should test this in your environment before making any irreversible changes) –  voretaq7 Sep 11 '12 at 21:27
    
That's a good point - Though I think from memory, I had to keep the original postgres as webmin needs it. –  A4J Sep 11 '12 at 22:38
add comment

I prefer this answer that explains how to symlink the new version. (reprinting below for convenience):

your new version of pg_dump is not in your PATH, all you need to do is to remove the old version, and symlink the new one to any directory in your PATH, for example, /usr/bin.

Like follows:

sudo ln -s /actual/new/pg_dump /usr/bin/pg_dump

To find the new pg_dump, you need to know the location of the postgresql install. If you used homebrew, it's /usr/local/Cellar/postgresql/9.2.2/bin (or whatever your version is)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.