ogirginc
ogirginc

Reputation: 5260

How to specify Postgresql client version to prevent server version mismatch?

I use homebrew-postgresql formula to manage multiple Postgresql version. When I tried to run rails db:migrate with :sql as the schema_format, it produced

pg_dump -s -x -O -f /Users/ogirginc/project/blog/db/structure.sql blog_development 

command and failed.

The problem is the version mismatch between the server and the pg_dump client:

pg_dump: server version: 12.2 (Homebrew petere/postgresql); pg_dump version: 10.11 (Homebrew petere/postgresql)
pg_dump: aborting because of server version mismatch
rails aborted!

When I have read the man pages of pg_wrapper as suggested by the author of the formula, my understanding was; the explicit defining PGCLUSTER environment variable like

PGCLUSTER="12/main" rails db:migrate

should have prevented the mismatch error.

When I take a step back and run psql, it printed out the

psql (10.11 (Homebrew petere/postgresql), server 12.2 (Homebrew petere/postgresql))

warning, yet functioning. I was hoping PGCLUSTER="12/main" psql would prevent any warnings but, it didn't. Also, tried brew link -f postgresql@12 but, no luck.

How can I solve this mismatch error between the Postgresql server and its' clients?


Additional info:

$ postgres --version
postgres (PostgreSQL) 10.11 (Homebrew petere/postgresql)

$ brew list | grep postgresql
postgresql-common
postgresql@10
postgresql@11
postgresql@12
[email protected]

$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory                        Log file
11  main    5432 online ogirginc /usr/local/var/lib/postgresql/11/main /usr/local/var/log/postgresql/postgresql-11-main.log
12  main    5432 online ogirginc /usr/local/var/lib/postgresql/12/main /usr/local/var/log/postgresql/postgresql-12-main.log

$ pg_config
BINDIR = /usr/local/Cellar/postgresql@10/10.11/bin
DOCDIR = /usr/local/Cellar/postgresql@10/10.11/share/doc
HTMLDIR = /usr/local/Cellar/postgresql@10/10.11/share/doc
INCLUDEDIR = /usr/local/Cellar/postgresql@10/10.11/include
PKGINCLUDEDIR = /usr/local/Cellar/postgresql@10/10.11/include
INCLUDEDIR-SERVER = /usr/local/Cellar/postgresql@10/10.11/include/server
LIBDIR = /usr/local/Cellar/postgresql@10/10.11/lib
PKGLIBDIR = /usr/local/Cellar/postgresql@10/10.11/lib
LOCALEDIR = /usr/local/Cellar/postgresql@10/10.11/share/locale
MANDIR = /usr/local/Cellar/postgresql@10/10.11/share/man
SHAREDIR = /usr/local/Cellar/postgresql@10/10.11/share
SYSCONFDIR = /usr/local/Cellar/postgresql@10/10.11/etc
PGXS = /usr/local/Cellar/postgresql@10/10.11/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/usr/local/Cellar/postgresql@10/10.11' '--enable-dtrace' '--enable-nls' '--with-bonjour' '--with-gssapi' '--with-icu' '--with-ldap' '--with-libxml' '--with-libxslt' '--with-openssl' '--with-uuid=e2fs' '--with-pam' '--with-perl' '--with-python' '--with-tcl' 'XML2_CONFIG=:' '--with-includes=/usr/local/opt/gettext/include:/usr/local/opt/icu4c/include:/usr/local/opt/openldap/include:/usr/local/opt/[email protected]/include:/usr/local/opt/readline/include:/usr/local/opt/tcl-tk/include' '--with-libraries=/usr/local/opt/gettext/lib:/usr/local/opt/icu4c/lib:/usr/local/opt/openldap/lib:/usr/local/opt/[email protected]/lib:/usr/local/opt/readline/lib:/usr/local/opt/tcl-tk/lib' '--with-extra-version= (Homebrew petere/postgresql)' 'CC=clang' 'PKG_CONFIG_PATH=/usr/local/opt/e2fsprogs/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/[email protected]/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig:/usr/local/opt/tcl-tk/lib/pkgconfig' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.15'
CC = clang
CPPFLAGS = -I/usr/local/Cellar/icu4c/64.2/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I/usr/local/opt/gettext/include -I/usr/local/opt/icu4c/include -I/usr/local/opt/openldap/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/readline/include -I/usr/local/opt/tcl-tk/include
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2
CFLAGS_SL =
LDFLAGS = -L/usr/local/opt/gettext/lib -L/usr/local/opt/icu4c/lib -L/usr/local/opt/openldap/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/tcl-tk/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lintl -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm
VERSION = PostgreSQL 10.11 (Homebrew petere/postgresql)

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.4
BuildVersion:   19E287

$ echo $0
-zsh

Upvotes: 3

Views: 2392

Answers (1)

ogirginc
ogirginc

Reputation: 5260

Should have been more careful because, I was getting a mismatch error for 10.11. However, I wasn't using that version. pg_lsclusters only returns the 11 & 12.

Turns out, a couple of years ago, I have exported postgresql@10 to my PATH. It was causing, pg_wrapper to keep using 10.11 because, I had installed postgresql@10 even though no cluster was created.

I have uninstalled postgresql@10 and updated my .zshrc. Now, all works fine.

Upvotes: 3

Related Questions