Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg_config shows 9.4 instead of 9.3

I am using Postgres 9.3, however my pg_config points at 9.4, preventing me from building extensions (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

As you can see above I have 9.3 installed

$ 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

Running ls against any of the /postgresql locations from pg_config (e.g. /usr/lib/postgresql) only return 9.3.

Running which pg_config results in: /usr/bin/pg_config

Looking into /usr/bin/pg_config (with vi), the following are the contents:

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 "$@"
  ...
  ...
  ...

Now looking in /usr/lib/postgresql/9.3/bin does NOT produce a pg_config file.

using apt-get purge postgresql-9.3 followed by apt-get install postgresql-9.3 does NOT fix the problem.

The closest I have found to an answer is this:

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

I have taken both steps advocated (upgrading libpq5 and libpq-dev) to no effect.

Any insights into how this could have happened, and how to fix it (or at least work around it?) I would settle for the ability to manually repoint pg_config (though an actual explanation and fix would be better). Is there just a way for me to instantiate a pg_config file in the /usr/lib/postgresql/9.3 directory?

like image 324
Abraham P Avatar asked May 09 '15 17:05

Abraham P


People also ask

What is Pg_config file?

The view pg_config describes the compile-time configuration parameters of the currently installed version of PostgreSQL. It is intended, for example, to be used by software packages that want to interface to PostgreSQL to facilitate finding the required header files and libraries.

What package contains Pg_config?

The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory.


3 Answers

This got fixed for me by running:

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

I still don't really know how I got into that state though.

like image 67
Abraham P Avatar answered Oct 06 '22 09:10

Abraham P


I got into the same problem by running :

apt-get install postgresql-server-dev-all

on a pg9.4 instance, which installed the package for versions 9.1, 9.2, 9.3, 9.4 and 9.5.

It turns out that this script :

/usr/bin/pg_config

finds the latest version and runs it :

#!/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 <[email protected]>
#
#  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

The solution was to remove the directory : /usr/lib/postgresql/9.5

like image 36
Max L. Avatar answered Oct 06 '22 11:10

Max L.


Ubuntu designs its Postgres packages so that most commands will take a PGCLUSTER envvar with a value like 9.5/main to let you control which version/cluster the command should use. Sadly pg_config doesn't! But /usr/bin/pg_config is just a bash wrapper, so I added a few lines like so:

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

That doesn't support the cluster part of the usual PGCLUSTER string, but you can still say PGCLUSTER=9.3 make e.g. This helps me when I'm building postgres extensions for a version I have installed that isn't the most recent.

I guess it might be safer to use a different name for my variable here, but it hasn't caused me problems so far. :-)

like image 24
Paul A Jungwirth Avatar answered Oct 06 '22 09:10

Paul A Jungwirth