描述

Ubuntu 16.04上安装的PostgreSQL11 版本,但是libpq-dev安装的是13版本。

编译安装repmgr的时候,会通过pg_config获取数据库信息,获取到13版本信息,但是13版本的相关文件不存在,导致编译失败。

需要调整libpq-dev的版本为数据库相同版本,来解决编译安装repmgr的问题。

1.问题

编译repmgr的时候,失败:

/usr/lib/postgresql/13/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory

安装的11版本数据库,编译repmgr时却寻找13版本包

postgres@xxxxxx:/tmp/repmgr/repmgr-5.3.3$ ./configure
checking for a sed that does not truncate output... /bin/sed
checking for pg_config... /usr/bin/pg_config
configure: building against PostgreSQL 13.3 (Ubuntu 13.3-1.pgdg16.04+1)
checking for gnused... no
checking for gsed... no
checking for sed... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating Makefile.global
config.status: creating config.h


postgres@xxxxxx:/tmp/repmgr/repmgr-5.3.3$ make
Makefile.global:26: /usr/lib/postgresql/13/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
Building against PostgreSQL
make: *** No rule to make target '/usr/lib/postgresql/13/lib/pgxs/src/makefiles/pgxs.mk'.  Stop.

通过 pg_config --version查看pg_config版本,应该是通过 pg_config 获取postgresql数据库信息

swift@xxxxxx:~$ pg_config
BINDIR = /usr/lib/postgresql/13/bin
DOCDIR = /usr/share/doc/postgresql-doc-13
HTMLDIR = /usr/share/doc/postgresql-doc-13
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/13/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/13/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/13/man
SHAREDIR = /usr/share/postgresql/13
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/13/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE =  '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' 'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/13/man' '--docdir=/usr/share/doc/postgresql-doc-13' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/13' '--bindir=/usr/lib/postgresql/13/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 13.3-1.pgdg16.04+1)' '--enable-nls' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-6.0' 'CLANG=/usr/bin/clang-6.0' '--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' 'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -pie -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' 'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -I/usr/include/x86_64-linux-gnu -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -pie -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-6.0/lib -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lrt -ldl -lm
VERSION = PostgreSQL 13.3 (Ubuntu 13.3-1.pgdg16.04+1)

查看安装包,libpg-dev和postgresql版本不一致

安装包信息

postgresql 版本11.5-1.pgdg16.04+1

user@xxxxxx:/etc/apt/sources.list.d$ dpkg -l|grep post
ii  pgdg-keyring                          2018.2                                          all          keyring for apt.postgresql.org
ii  postgresql-11                         11.5-1.pgdg16.04+1                              amd64        object-relational SQL database, version 11 server
ii  postgresql-client-11                  11.5-1.pgdg16.04+1                              amd64        front-end programs for PostgreSQL 11
ii  postgresql-client-common              204.pgdg16.04+1                                 all          manager for multiple PostgreSQL client versions
ii  postgresql-common                     204.pgdg16.04+1                                 all          PostgreSQL database-cluster manager

libpq版本13.3-1.pgdg16.04+1

user@xxxxxx:/etc/apt/sources.list.d$ dpkg -l|grep libpq
ii  libpq-dev                             13.3-1.pgdg16.04+1                              amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64                          13.3-1.pgdg16.04+1                              amd64        PostgreSQL C client library

2.原因

libpg-dev和postgresql版本不一致,导致编译repmgr的过程中,通过pg_config获取数据库信息,但是找不到对应版本的文件,所以出现了编译失败的问题。

3.解决方法

针对libpq-dev进行降级,和数据库同版本。

3.1配置postgresql的旧包源

/etc/apt/sources.list.d/postgresql.list

# 历史包
deb https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive main
deb-src https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive main

这里的操作系统是Ubuntu 16.04codenamexenial

3.2更新apt存储库缓存

sudo apt update

搜索 libpq-dev 软件来源,可以看到存在和数据库版本相同的11.5-1.pgdg16.04+1版本

user@xxxxxx:/etc/apt/sources.list.d$ apt-cache madison libpq-dev|grep 11.5
 libpq-dev | 11.5-3.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main amd64 Packages
 libpq-dev | 11.5-2.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main amd64 Packages
 libpq-dev | 11.5-1.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main amd64 Packages
postgresql-11 | 11.5-1.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main Sources
postgresql-11 | 11.5-2.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main Sources
postgresql-11 | 11.5-3.pgdg16.04+1 | https://apt-archive.postgresql.org/pub/repos/apt xenial-pgdg-archive/main Sources

3.3安装相同版本libpq-dev软件包

因为这里想要安装相同版本的包,即11.5-1.pgdg16.04+1,但是libpq5已经安装了13.3-1.pgdg16.04+1,如果卸载的话,会把数据库卸载掉,不能卸载,只能降级。

这里在安装 postgresql-server-dev-11=11.5-1.pgdg16.04+1 libpq-dev=11.5-1.pgdg16.04+1 的时候,同时指定了libpq5的版本(libpq5=11.5-1.pgdg16.04+1

# 只下载包,可以通过这种形式查看相关包,防止异常,下载文件位于 /var/cache/apt/archives/ ,后续可通过相关deb包,通过 dpkg -i *.deb 安装
sudo apt install libpq-dev=11.5-1.pgdg16.04+1 libpq5=11.5-1.pgdg16.04+1 -d

# 可联网,直接安装,进行降级
sudo apt install libpq-dev=11.5-1.pgdg16.04+1 libpq5=11.5-1.pgdg16.04+1

# 降级libpq-dev的同时,如果需要安装相同版本的 postgresql-server-dev-11,可以同步进行
# 只下载相关包,不直接安装,可用于打包离线安装包,用于内网机器。
sudo apt install postgresql-server-dev-11=11.5-1.pgdg16.04+1 libpq-dev=11.5-1.pgdg16.04+1 libpq5=11.5-1.pgdg16.04+1 -d

# 联网机器,可直接安装
sudo apt install postgresql-server-dev-11=11.5-1.pgdg16.04+1 libpq-dev=11.5-1.pgdg16.04+1 libpq5=11.5-1.pgdg16.04+1

标签: PostgreSQL

添加新评论