3

How can I download, compile, make & install ONLY the libpq source on a server (Ubuntu) that DOES NOT have PostgreSQL installed?

I have found the libpq source here. However it does NOT seem to be separable from the entire PostgreSQL. Thanks in advance.

I DO NOT want to install the entire PostgreSQL. I want to use libpq as a C interface to PostgreSQL on a DIFFERENT server (also Ubuntu) that DOES have it installed.

I also found this old link which indicates that the above is POSSIBLE but not HOW to do it.

Community
  • 1
  • 1

2 Answers2

10

I have found the libpq source here. However it does NOT seem to be separable from the entire PostgreSQL.

It has to be configured with the entire source tree because that's what generates the necessary Makefile parts. But once configured, make && make install can run inside the src/interfaces/libpq directory alone, and the rest being left out completely.

In steps:

  1. download the source code archive, for example https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.bz2
  2. unpack into a build directory: tar xjf ~/Downloads/postgresql-9.4.1.tar.bz2
  3. apt-get install libssl-dev if it's not installed already
  4. cd into it and configure: cd postgresql-9.4.1; ./configure --with-openssl --without-readline
  5. Assuming configure succeeds, cd into src/interfaces/libpq and run make
  6. still in the libpq directory, run make install as root: sudo make install.

That will install into /usr/local/pgsql and subdirectories as a library independent and insulated from the one packaged in Ubuntu if it happens to be installed. To install it elsewhere, specify the location with the --prefix option to configure.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • If only the OP would accept this answer as correct... @Loveandpeace ... FYI, details of the `--without-readline` option can be found [here](http://www.postgresql.org/docs/9.4/static/install-requirements.html). – villapx Mar 11 '16 at 15:02
5

Besides downloading and configuration, the steps are:

cd src/interfaces/libpq; make; make install; cd -
cd src/bin/pg_config; make install; cd -
cd src/backend; make generated-headers; cd -
cd src/include; make install; cd -

These steps will give you the library and headers of libpq, and a binary called pg_config, and all postgresql backend headers, so that you could compile things like libpqxx correctly.

(I've just tested with postgresql-9.6.5.)

Sherwood Wang
  • 685
  • 9
  • 19
  • This looks short and sweet, does this still work for Postgres 12? – Jay Jun 14 '20 at 05:37
  • Looks ok on pg12, with your instructions I got me a `libpq.so.5.12`. Still not sure it's enough, the library I want to use is [taopq](https://github.com/taocpp/taopq) (api looks cleaner and more like what I did in Python) – Jay Jun 15 '20 at 16:51