I'm trying to pull a production database locally for my rails app. My local postgres version was too low so I needed to update to Postgresql 9.6.5 from 9.4.1.
I installed Postgres 9.6.6 via Homebrew as such:
brew install [email protected]
Then ran:
brew services start [email protected]
However, when I try to do pg_dump I get -bash: pg_dump: command not found.
I also tried updating my path as such:
export PATH="/usr/local/Cellar/postgresql\@9.6/9.6.6/bin:$PATH"
Any idea what I need to do to get pg_dump to work?
5 Answers
Adding this to my ~/.bash_profile did the trick:
export PATH=/usr/local/Cellar/postgresql\@9.6/9.6.6/bin:$PATH
For those who have this issue on Mac even though Postgres path is correctly added on your .bash_profile I found that running pg_dump directly from the Terminal does the job.
Just open your Terminal and type:
pg_dump -U username your_database > db_dump.bak
I tried the ff approach and I got the same error:
sudo su - postgres
pg_dump -U username your_database > db_dump.bak
bash: pg_dump: command not found
If you installed PostgreSQL by pgadmin4 in Mac, you could find the pg tool in
/Library/PostgreSQL/{version}/bin/
Couldn't get path to work in Cygwin but could browse to my pg bin directory (C:\Program Files\PostgreSQL\9.6\bin) and run it directly from there.
For windows what worked for me is to add the Postgres to global vars from env, not ~/.bash_profile,
- Go to Edit the system environment variables
- Then Environement variables
- Then Path then add the location of bin of postgres in my case
C:\Program Files\PostgreSQL\14\bin\ - Click ok on each open window
- Close and reopen your visual code
- Run your command
See Setting Windows PATH for Postgres tools for more details