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:

export PG_DUMP
export PATH

On looking at echo $PATH, I get:


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':


Error message on running cap 'deploy:migrate':

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

output of 'pg_dump --version':

pg_dump (PostgreSQL) 8.4.11

  • What is the output of "ls /usr/pgsql-9.1/bin"? And "which pg_dump"?
    – user130370
    Sep 11, 2012 at 20:16
  • Hi Eric, I have added the outputs above.
    – A4J
    Sep 11, 2012 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?
    – user130370
    Sep 11, 2012 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, 2012 at 20:52
  • Short answer : Yes. But there might exist some cleaner solutions.
    – user130370
    Sep 11, 2012 at 20:57

2 Answers 2


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

export PG_DUMP
export PATH
  • 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, 2012 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, 2012 at 22:38

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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