如何指定 Postgresql 客户端版本以防止服务器版本不匹配?
How to specify Postgresql client version to prevent server version mismatch?
我使用homebrew-postgresql公式来管理多个Postgresql版本。当我尝试将 运行 rails db:migrate
与 :sql
作为 schema_format
时,它产生了
pg_dump -s -x -O -f /Users/ogirginc/project/blog/db/structure.sql blog_development
命令失败。
问题是服务器和pg_dump客户端的版本不匹配:
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!
当我阅读公式作者 pg_wrapper
作为 suggested 的手册页时,我的理解是;显式定义 PGCLUSTER
环境变量,如
PGCLUSTER="12/main" rails db:migrate
应该可以防止不匹配错误。
当我后退一步 运行 psql
时,它打印出
psql (10.11 (Homebrew petere/postgresql), server 12.2 (Homebrew petere/postgresql))
警告,但仍在运行。我希望 PGCLUSTER="12/main" psql
会阻止任何警告,但事实并非如此。另外,尝试了 brew link -f postgresql@12
但没有成功。
如何解决 Postgresql 服务器与其客户端之间的不匹配错误?
附加信息:
$ postgres --version
postgres (PostgreSQL) 10.11 (Homebrew petere/postgresql)
$ brew list | grep postgresql
postgresql-common
postgresql@10
postgresql@11
postgresql@12
postgresql@9.6
$ 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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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 [=14=]
-zsh
应该更加小心,因为我遇到了 10.11
的不匹配错误。但是,我没有使用那个版本。 pg_lsclusters
仅 returns 11 和 12。
事实证明,几年前,我的PATH
exported postgresql@10
。这导致 pg_wrapper
继续使用 10.11
,因为即使没有创建集群,我也安装了 postgresql@10
。
我已经卸载 postgresql@10
并更新了我的 .zshrc
。现在,一切正常。
我使用homebrew-postgresql公式来管理多个Postgresql版本。当我尝试将 运行 rails db:migrate
与 :sql
作为 schema_format
时,它产生了
pg_dump -s -x -O -f /Users/ogirginc/project/blog/db/structure.sql blog_development
命令失败。
问题是服务器和pg_dump客户端的版本不匹配:
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!
当我阅读公式作者 pg_wrapper
作为 suggested 的手册页时,我的理解是;显式定义 PGCLUSTER
环境变量,如
PGCLUSTER="12/main" rails db:migrate
应该可以防止不匹配错误。
当我后退一步 运行 psql
时,它打印出
psql (10.11 (Homebrew petere/postgresql), server 12.2 (Homebrew petere/postgresql))
警告,但仍在运行。我希望 PGCLUSTER="12/main" psql
会阻止任何警告,但事实并非如此。另外,尝试了 brew link -f postgresql@12
但没有成功。
如何解决 Postgresql 服务器与其客户端之间的不匹配错误?
附加信息:
$ postgres --version
postgres (PostgreSQL) 10.11 (Homebrew petere/postgresql)
$ brew list | grep postgresql
postgresql-common
postgresql@10
postgresql@11
postgresql@12
postgresql@9.6
$ 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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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/openssl@1.1/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 [=14=]
-zsh
应该更加小心,因为我遇到了 10.11
的不匹配错误。但是,我没有使用那个版本。 pg_lsclusters
仅 returns 11 和 12。
事实证明,几年前,我的PATH
exported postgresql@10
。这导致 pg_wrapper
继续使用 10.11
,因为即使没有创建集群,我也安装了 postgresql@10
。
我已经卸载 postgresql@10
并更新了我的 .zshrc
。现在,一切正常。