pg_dump server version mismatch [duplicate] - ruby-on-rails

This question already has answers here:
How to fix pg_dump version mismatch errors?
(6 answers)
Closed 8 years ago.
I'm getting the following error whenever I run rake tasks on my Rails app's database.
pg_dump: server version: 9.2.4; pg_dump version: 9.1.5
pg_dump: aborting because of server version mismatch
I've Googled around, and found some suggestions about updating the postgres brew package, but this did not work.
Why is the incorrect pg_dump version being used, and how can I fix this? Or what search terms should I be looking for to find a solution?
EDIT
Info on my pg_dump configuration:
$ pg_dump --version
> pg_dump (PostgreSQL) 9.1.5
$ which pg_dump
> /usr/bin/pg_dump
$ echo $PATH
> /Users/andrewharvey/.rvm/gems/ruby-1.9.3-p392#mantawatch/bin:/Users/andrewharvey/.rvm/gems/ruby-1.9.3-p392#global/bin:/Users/andrewharvey/.rvm/rubies/ruby-1.9.3-p392/bin:/Users/andrewharvey/.rvm/bin:/usr/local/heroku/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/andrewharvey/.rvm/bin
I'm using oh_my_zsh, and path is defined in my .zshrc file. This may be the cause of my problem (and I'm sure this can be cleaned up), unfortunately I don't know enough what I'm doing to debug and edit this. Grateful for pointers (I'm using RVM and postgres installed via Homebrew).
source $ZSH/oh-my-zsh.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
alias pg='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log'
export
PATH=$PATH:/usr/local/bin:/Users/andrewharvey/.rvm/gems/ruby-2.0.0-p0/bin:/Users/andrewharvey/.rvm/gems/ruby-2.0.0-p0#global/bin:/Users/andrewharvey/.rvm/rubies/ruby-2.0.0-p0/bin:/Users/andrewharvey/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

For mac users
put to the top of .profile file.
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
then run
. ~/.profile

What does the output of the following show? It looks like the pg_dump version you are trying to use is a 9.1 version, whereas the cluster you are connecting to is 9.2. If that's the case, then you'll need to determine the correct path of the 9.2 pg_dump.
pg_dump --version
which pg_dump
echo $PATH
[edited after OP provided more details]
According to this page: https://wiki.postgresql.org/wiki/Installers/Mac_OS_X, homebrew probably installed the tools at /usr/local/bin. However, your current $PATH has /usr/local/bin located after several other paths.
I've tidied up your $PATH setting. so try saving the changes below to your .zshrc file and source'ing it to pick up the changes (source ~/.zshrc).
export PATH=/usr/local/bin:/Users/andrewharvey/.rvm/gems/ruby-2.0.0-p0/bin:/Users/andrewharvey/.rvm/gems/ruby-2.0.0-p0#global/bin:/Users/andrewharvey/.rvm/rubies/ruby-2.0.0-p0/bin:/Users/andrewharvey/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH
export PATH="/usr/local/heroku/bin:$PATH"

Related

Cant perform query in rails : may have been in progress in another thread when fork() was called

I am running under macOS Catalina version 10.15.1
When I run my rails console on my project and try to perform a query like User.first I get :
objc[57093]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[57093]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
I followed this answer and added OBJC_DISABLE_INITIALIZE_FORK_SAFETY to my .zshrcfile which looks like that :
ZSH=$HOME/.oh-my-zsh
# You can change the theme with another one:
# https://github.com/robbyrussell/oh-my-zsh/wiki/themes
ZSH_THEME="robbyrussell"
# Useful oh-my-zsh plugins for Le Wagon bootcamps
plugins=(git gitfast zsh-autosuggestions last-working-dir zsh-syntax-highlighting common-aliases history-substring-search)
# Prevent Homebrew from reporting - https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
export HOMEBREW_NO_ANALYTICS=1
# Actually load Oh-My-Zsh
source "${ZSH}/oh-my-zsh.sh"
unalias rm # No interactive rm by default (brought by plugins/common-aliases)
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
# Load rbenv if installed (To manage your Ruby versions)
export PATH="${HOME}/.rbenv/bin:${PATH}"
type -a rbenv > /dev/null && eval "$(rbenv init -)"
# Load nvm if installed (To manage your Node versions)
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"
# Anaconda binaries (python, pip, conda, jupyter, pytest, pylint etc.)
export PATH="/anaconda3/bin:${HOME}/anaconda3/bin:${PATH}"
# Rails and Ruby uses the local `bin` folder to store binstubs.
# So instead of running `bin/rails` like the doc says, just run `rails`
# Same for `./node_modules/.bin` and nodejs
export PATH="./bin:./node_modules/.bin:${PATH}:/usr/local/sbin"
# Store your own aliases in the ~/.aliases file and load the here.
[[ -f "$HOME/.aliases" ]] && source "$HOME/.aliases"
# Encoding stuff for the terminal
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export EDITOR=atom
When I run in my terminal echo $OBJC_DISABLE_INITIALIZE_FORK_SAFETY I get YES, so I think the environment variable is correcly set... but that doesnt fix the issue.
How can I fix this problem ?
What worked for me, was disbaling Spring: export DISABLE_SPRING=true before starting your Rails console or server
I ran into this problem after I updated my Postgres database. I ended up updating to the latest ruby version and reinstalling all gems. After that everything worked again.
I tried the OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES suggestion as well, to no avail.

-bash: pg_dump: command not found

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 postgresql#9.6
Then ran:
brew services start postgresql#9.6
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?
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

Unison command not found

Recently my Unison application has stopped working on my Mac terminal saying the command cannot be found. Not sure if this was the reason but I recently reinstalled brew (which is how it was installed), which may have broken it.
Here is the error output:
mac:~ Imran$ unison sites
-bash: unison: command not found
I can see that if I locate unison unison is found in the following directories:
> /Users/Imran/unison.log /Users/Imran/unison.tar.gz
> /usr/local/Cellar/unison /usr/local/Cellar/unison/2.40.102
> /usr/local/Cellar/unison/2.40.102/COPYING
> /usr/local/Cellar/unison/2.40.102/INSTALL_RECEIPT.json
> /usr/local/Cellar/unison/2.40.102/NEWS
> /usr/local/Cellar/unison/2.40.102/README
> /usr/local/Cellar/unison/2.40.102/TODO.txt
> /usr/local/Cellar/unison/2.40.102/bin
> /usr/local/Cellar/unison/2.40.102/bin/unison
> /usr/local/Library/Formula/unison.rb
> /usr/local/Library/LinkedKegs/unison /usr/local/bin/unison
> /usr/local/opt/unison /usr/share/zsh/5.3/functions/_unison
Can someone help me get this working again? I suspect its something to do with the link to the app being broken.
If you've done a reinstall of a brew cask, you may need to manually link it again if it can't be found on your path
brew link unison
I had the same issue when trying to use Unison from Windows to Mac (where it has been installed with Brew).
You can give an explicit path for the unison executable on the server by using the command-line option
-servercmd /full/path/name/of/unison
or adding
servercmd=/full/path/name/of/unison
to your profile
Source
According to the documentation the error message bash: unison: command not found means:
Make sure Unison is installed on the host you are trying to connect to.
For anyone running into this error on macOS:
If you're using zsh (or running a newer macOS version where zsh is the default) you have to modify or create ~/.zshenv.
Add your path to the shell environment by adding one of the following snippets to ~/.zshenv.
For ARM64 (M1 Macs):
eval $(/opt/homebrew/bin/brew shellenv)
or on x86 (Intel Macs)
eval $(/usr/local/bin/brew shellenv)
or you simply source your zshrc:
source ~/.zshrc
Your user's PATH variable does not include a link to the unison binary.
Add /usr/local/Cellar/unison/2.40.102/bin/unison to your .bashrc,
$ vi ~/.bashrc
add the following,
export PATH=$PATH:/usr/local/Cellar/unison/2.40.102/bin/unison
save and quit, and then re-read your users bashrc file,
exec bash
Now try which unison again, or actually just try running it with,
$ unison

How to specify which postgres copy for rails to use

How do I specify which version of postgres rails use? When I run puma and go to localhost:3000 I get a an error
PG::ConnectionBad
fe_sendauth: no password supplied
I think the copy being used may be the manual install 9.3, as when I run:
/usr/local/Cellar/postgresql/9.4.1/bin/pg_ctl -D /usr/local/var/postgres start
I get the error:
stgres start
server starting
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.1.
I found three copies of pg_hba.conf on my system:
/Library/PostgreSQL/9.3/data/pg_hba.conf
/Users/lasernite/Library/Application Support/Postgres/var-9.4/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf
The first one I believe was from a manual install at some point. The second one is probably just some supporting copy/ignorable, and the third one is a homebrew install.
How can I make rails use the homebrew postgres install, even if it means wiping the local database? Which is fine so long as the production on heroku is instact.
I've been stuck for several days on reconfiguring my development environment from sqlite to postgres, which is very problematic as I have a production db and site live now, which is forcing me to do some code pushes without being able to verify functionality locally, but for the most part has totally crippled my ability to do any development.
Please help me!
It looks like the problem is that you're starting 9.4.1 when the database was created by 9.3.x.
The version of posgres that Rails uses should be whichever one is running. So if you want to start postgres in version 9.3.x, then you should start that version. But you have to specify the correct path for that version.
What output do you get for these?
> initdb --version
> pg_ctl --version
> postgres --version
> psql --version
It should all be the same. If it says 9.4.x and you want to use that version, then you can re-init the database like so: initdb -D /usr/local/var/postgres-4.1 and then you can start postgres postgres -D /usr/local/var/postgres-4.1. Doing it this way, you'll probably lose your local database since it sounds like that data was created by 9.3.x.
Alternatively, if those output 9.3.x, then you should just be able to use the commands without the full path to the binary: postgres -D /usr/local/var/postgres.
If you're using 9.4.x and you want to keep using 9.3.x, then try which postgres. It's probably pointing to /usr/local/bin. Then make sure that that is just a link to the homebrew version. ls -la /usr/local/bin | grep "postgres ->".
If you're using the homebrew version, you can do brew switch postgres 9.3.x to tell homebrew to use that version. Then you should be able to start postgres with postgres -D /var/local/var/postgres.

Postgresql fails to be recognised on the correct path

I'm trying to setup a new app with postgresql so I can deploy with Heroku. However, when I run the app using 'rails server' my welcome to rails screen gives this error:
PG::Error
could not connect to server: Permission denied Is the server running
locally and accepting connections on Unix domain socket
"/var/pgsql_socket/.s.PGSQL.5432"?
I'm sure this is the same issue as is covered here:
Repairing Postgresql after upgrading to OSX 10.7 Lion
But the fix by John Wang doesn't work.
I've tried adding 'export PATH=/usr/local/bin:$PATH' to the .bash_profile, .bashrc and .zshrc, none of which change the outcome. Calling which psql always returns /usr/bin/psql.
What am I doing wrong here? Any help would be much appreciated!
edit
Running /usr/local/bin/psql gives the same error and running echo $PATH gives:
/opt/local/bin:/opt/local/sbin:/Users/dave/.rvm/gems/ruby-1.9.3-p194/bin:/Users/dave/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/dave/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/dave/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/.rvm/bin
What happens if you run your locally installed psql directly?
/usr/local/bin/psql ...
If that works then it's the path you need to change. You can just try running the export in a terminal, then which psql. If that doesn't pick up the right psql then check the export worked with
echo $PATH
I'm not sure which .xxrc file you'll need to update then - not got a mac to hand I'm afraid, but at least you'll know the command will work.
Oh - I keep several different versions of PostgreSQL around and find it useful to have some aliases set up:
alias psql90='/usr/local/pgsql90/bin/psql -p 5490'
alias psql84='/usr/local/pgsql84/bin/psql -p 5484'
alias pg_dump90=...
Your $PATH is just a list of directories to check separated by ":". It starts /opt/local/bin rather than /usr/local/bin and if you look further along you'll see /usr/bin coming before /usr/local/bin. So - we need to do two things:
Find out which psql we actually want
Make sure we can edit our PATH
Firstly - find your postgresql.conf file and check what port you are running on. There are three items of interest: listen_addresses, port and unix_socket_directory. Then we'll see if there's a socket there.
ls -a <your unix_socket_directory>
You should see a "file" something like ".s.PGSQL.5432" where the 5432 is the port number from your config file. If there's no such file, it's not running and it's time to get it running. You may need to change the port number in the config file if it matches Apple's existing usage.
Then find what psql installations exist
find /usr -type f -name psql
find /opt -type f -name psql
Try and figure out which one you need, perhaps add --version to help.
Then, let's see about editing your PATH. You must have some changes in your settings file anyway, so let's see if we can find where that setting is.
grep -l 'local/bin' ~/.*rc
That should list filenames containing local/bin - have a look and see if they are editing your PATH.

Resources