apt安装的postgres版本与pg_config版本不匹配

apt安装的postgres版本与pg_config版本不匹配

使用全新安装的 Ubuntu 14.04,我们添加了必要的 apt 仓库,更新了 apt,然后安装了 Postgres-9.5。但是,尝试安装[电子邮件保护]我们收到一个错误...

Error: could not determine PostgreSQL version from '10.0'

这看起来有点奇怪,所以我尝试了以下方法......

psql -c "select version()"

返回...

PostgreSQL 9.5.9 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, 64-bit

为了再检查一下,我尝试......

pg_config 

得出以下结论...

BINDIR = /usr/lib/postgresql/10/bin
DOCDIR = /usr/share/doc/postgresql-doc-10
HTMLDIR = /usr/share/doc/postgresql-doc-10
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/10/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/10/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/10/man
SHAREDIR = /usr/share/postgresql/10
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/10/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-tclconfig=/usr/lib/x86_64-linux-gnu/tcl8.6' '--with-includes=/usr/include/tcl8.6' 'PYTHON=/usr/bin/python' '--mandir=/usr/share/postgresql/10/man' '--docdir=/usr/share/doc/postgresql-doc-10' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/10' '--bindir=/usr/lib/postgresql/10/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' '--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' '--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' '--with-selinux' 'CPPFLAGS=-D_FORTIFY_SOURCE=2'
CC = gcc
CPPFLAGS = -DFRONTEND -I/usr/include/x86_64-linux-gnu -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -L../../src/common -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/x86_64-linux-gnu/mit-krb5 -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm
VERSION = PostgreSQL 10.0

这反过来根本就没有任何意义。我们只想安装旧版 9.5,以避免陷入各种软件包升级的泥潭。我错过了什么?

答案1

最终,安装了另一个未指定版本的依赖项(libpq-dev),因此它会安装最新版本(10),其中包含其自己的版本pg_config,这反过来会导致依赖于从中获取版本的下游包中断。

答案2

要删除的 PostgreSQL 版本:10
要安装的 PostgreSQL 版本:9.5

1.停止PostgreSQL集群:

$ sudo /etc/init.d/postgresql stop

2. 彻底删除 postgreSQL:

$ sudo apt-get purge postgr*
$ sudo apt-get autoremove

# check /usr/share/postgresql/ directory and remove '10' subdirectory if needed:
$ sudo rm -rf /usr/share/postgresql/10

3.安装软件包:

$ sudo apt-get install postgresql-server-dev-9.5 postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5 libpq-dev
$ psql --version
...
psql (PostgreSQL) 9.5.*

(3.1.)更改配置(如果需要):

$ sudo nano /etc/postgresql/9.5/main/pg_hba.conf
...

4.启动PostgreSQL集群:

$ sudo /etc/init.d/postgresql start
...
[ ok ] Starting postgresql (via systemctl): postgresql.service.

5.检查安装的版本:

pg_config

相关内容