【问题标题】:pg_config shows 9.4 instead of 9.3pg_config 显示 9.4 而不是 9.3
【发布时间】:2015-07-20 12:05:42
【问题描述】:

我使用的是 Postgres 9.3,但是我的 pg_config 指向 9.4,阻止了我 来自构建扩展 (pgTap)。

$ sudo aptitude search postgresql | grep ^i
i   postgresql-9.3                  - object-relational SQL database,
version 9.
i   postgresql-client-9.3           - front-end programs for PostgreSQL 9.3

i A postgresql-client-common        - manager for multiple PostgreSQL client
ver
i A postgresql-common               - PostgreSQL database-cluster manager

i   postgresql-contrib-9.3          - additional facilities for PostgreSQL

正如你在上面看到的,我已经安装了 9.3

$ pg_config
BINDIR = /usr/lib/postgresql/9.4/bin
DOCDIR = /usr/share/doc/postgresql-doc-9.4
HTMLDIR = /usr/share/doc/postgresql-doc-9.4
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/9.4/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/9.4/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/9.4/man
SHAREDIR = /usr/share/postgresql/9.4
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/9.4/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-tcl' '--with-perl' '--with-python' '--with-pam'
'--with-openssl' '--with-libxml' '--with-libxslt'
'--with-tclconfig=/usr/lib/tcl8.5' '--with-includes=/usr/include/tcl8.5'
'PYTHON=/usr/bin/python' '--mandir=/usr/share/postgresql/9.4/man'
'--docdir=/usr/share/doc/postgresql-doc-9.4'
'--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/'
'--datadir=/usr/share/postgresql/9.4' '--bindir=/usr/lib/postgresql/9.4/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-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 -Wformat-security -Werror=format-security
-I/usr/include/mit-krb5 -fPIC -pie -DLINUX_OOM_SCORE_ADJ=0
-fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro
-Wl,-z,now -Wl,--as-needed -L/usr/lib/mit-krb5
-L/usr/lib/x86_64-linux-gnu/mit-krb5' '--with-krb5' '--with-gssapi'
'--with-ldap' 'CPPFLAGS=-D_FORTIFY_SOURCE=2'
CC = gcc
CPPFLAGS = -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/include/tcl8.5
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
-Wformat-security -Werror=format-security -I/usr/include/mit-krb5 -fPIC -pie
-DLINUX_OOM_SCORE_ADJ=0 -fno-omit-frame-pointer
CFLAGS_SL = -fpic
LDFLAGS = -L../../../src/common -Wl,-Bsymbolic-functions -Wl,-z,relro
-Wl,-z,now -Wl,--as-needed -L/usr/lib/mit-krb5
-L/usr/lib/x86_64-linux-gnu/mit-krb5 -L/usr/lib/x86_64-linux-gnu
-Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5
-lz -ledit -lrt -lcrypt -ldl -lm
VERSION = PostgreSQL 9.4.1

针对来自pg_config(例如/usr/lib/postgresql)的任何/postgresql 位置运行ls 仅返回9.3。

运行 which pg_config 会导致: /usr/bin/pg_config

查看/usr/bin/pg_config(带vi),内容如下:

PGBINROOT="/usr/lib/postgresql/"
LATEST_SERVER_DEV=`ls $PGBINROOT*/bin/pg_config 2>/dev/null|tail -n1`

if [ -n "$LATEST_SERVER_DEV" ]; then
    exec "$LATEST_SERVER_DEV" "$@"
else
    if [ -x /usr/bin/pg_config.libpq-dev ]; then
        exec /usr/bin/pg_config.libpq-dev "$@"
  ...
  ...
  ...

现在查看/usr/lib/postgresql/9.3/bin 不会生成pg_config 文件。

使用apt-get purge postgresql-9.3 后跟apt-get install postgresql-9.3 不能解决问题。

我找到的最接近答案的是:

https://bugs.launchpad.net/ubuntu/+source/postgresql-common/+bug/789622

我已采取了所提倡的两个步骤(升级libpq5libpq-dev),但均无效。

任何关于如何发生这种情况以及如何修复它的见解(或至少解决它?)我会接受手动重新指向 pg_config 的能力(尽管实际的解释和修复会更好)。有没有办法让我在/usr/lib/postgresql/9.3 目录中实例化一个 pg_config 文件?

【问题讨论】:

标签: postgresql configuration configuration-files configure


【解决方案1】:

我通过运行解决了这个问题:

sudo apt-get install postgresql-server-dev-9.3

我仍然不知道我是如何进入那种状态的。

【讨论】:

    【解决方案2】:

    我通过运行遇到了同样的问题:

    apt-get install postgresql-server-dev-all

    在 pg9.4 实例上,该实例安装了 9.1、9.2、9.3、9.4 和 9.5 版本的软件包。

    原来这个脚本:

    /usr/bin/pg_config
    

    找到最新版本并运行它:

    #!/bin/sh
    
    # If postgresql-server-dev-* is installed, call pg_config from the latest
    # available one. Otherwise fall back to libpq-dev's version.
    #
    # (C) 2011 Martin Pitt <mpitt@debian.org>
    #
    #  This program is free software; you can redistribute it and/or modify
    #  it under the terms of the GNU General Public License as published by
    #  the Free Software Foundation; either version 2 of the License, or
    #  (at your option) any later version.
    #
    #  This program is distributed in the hope that it will be useful,
    #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #  GNU General Public License for more details.
    set -e
    PGBINROOT="/usr/lib/postgresql/"
    LATEST_SERVER_DEV=\`ls $PGBINROOT*/bin/pg_config 2>/dev/null|tail -n1\`
    
    if [ -n "$LATEST_SERVER_DEV" ]; then
        exec "$LATEST_SERVER_DEV" "$@"
    else
        if [ -x /usr/bin/pg_config.libpq-dev ]; then
        exec /usr/bin/pg_config.libpq-dev "$@"
        else
        echo "You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application." >&2
        exit 1
        fi
    fi
    

    解决方案是删除目录:/usr/lib/postgresql/9.5

    【讨论】:

    • 我对此表示赞同,因为无论它是多么糟糕的解决方案,事实证明它是唯一允许我处理依赖于 postgresql-server-dev-all 的软件然后使用 pg_config 确定 postgre 的错误版本(实际安装了 10)。
    【解决方案3】:

    Ubuntu 设计了它的 Postgres 包,因此大多数命令将采用 PGCLUSTER envvar,其值类似于 9.5/main,让您控制该命令应该使用哪个版本/集群。可悲的是pg_config 没有!但是/usr/bin/pg_config 只是一个 bash 包装器,所以我添加了如下几行:

    set -e
    PGBINROOT="/usr/lib/postgresql/"
    #redhat# PGBINROOT="/usr/pgsql-"
    
    # MY CHANGES START HERE
    if [ -n "$PGCLUSTER" ]; then
      exec "$PGBINROOT/$PGCLUSTER/bin/pg_config" "$@"
    fi
    # MY CHANGES END HERE
    
    LATEST_SERVER_DEV=`ls $PGBINROOT*/bin/pg_config 2>/dev/null|tail -n1`
    
    if [ -n "$LATEST_SERVER_DEV" ]; then
        exec "$LATEST_SERVER_DEV" "$@"
    else
        if [ -x /usr/bin/pg_config.libpq-dev ]; then
      exec /usr/bin/pg_config.libpq-dev "$@"
        else
      echo "You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application." >&2
      exit 1
        fi
    fi
    

    这不支持通常的PGCLUSTER 字符串的集群部分,但你仍然可以说PGCLUSTER=9.3 make,例如当我为我安装的 不是最新版本的版本构建 postgres 扩展时,这对我很有帮助。

    我想在这里为我的变量使用不同的名称可能更安全,但到目前为止它还没有给我带来问题。 :-)

    【讨论】:

      【解决方案4】:

      在 Debian、Ubuntu 上

      标准扩展 Makefile 将其 PG_CONFIG 变量设置为 pg_config 如果尚未设置:

      Makefile(摘录)

      [...]
      PG_CONFIG ?= pg_config
      [...]
      

      要构建和安装您的扩展程序以作为目标版本,您可以简单地:

      make install PG_CONFIG=/usr/lib/postgresql/{YOUR TARGET VERSION}/bin/pg_config
      

      【讨论】:

        猜你喜欢
        • 2015-05-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多