Quick Install of PostgreSQL 10 from Git

Notes on switching from Ubuntu 16.04 maintained PostgreSQL 9.5 to release 10 built from source out of the official git repository. We remove the packaged version and configure & build the new version for development.

advertisement

PostgreSQL 10 has recently been released. Since we're developers and our database is a core system function (e.g., Use with Django), we want to work with cutting edge technology and the source to facilitate optimization, customization, and experimentation.

Before we begin, let's see if we have postgreSQL packages already installed on our system via our Ubuntu 16.04 distribution.

$ dpkg -l | grep postgres
ii  postgresql                                 9.5+173                                       all          object-relational SQL database (supported version)
ii  postgresql-9.5                             9.5.9-0ubuntu0.16.04                          amd64        object-relational SQL database, version 9.5 server
ii  postgresql-client                          9.5+173                                       all          front-end programs for PostgreSQL (supported version)
ii  postgresql-client-9.5                      9.5.8-0ubuntu0.16.04.1                        amd64        front-end programs for PostgreSQL 9.5
ii  postgresql-client-common                   173                                           all          manager for multiple PostgreSQL client versions
ii  postgresql-common                          173                                           all          PostgreSQL database-cluster manager
ii  postgresql-contrib-9.5                     9.5.9-0ubuntu0.16.04                          amd64        additional facilities for PostgreSQL

Let's remove postgresql including the configuration files. However, let's first make sure we know how Ubuntu had everything configured.

$ ps -ef | grep postgres
postgres  3916     1  0 11:12 ?        00:00:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf

$ ls /etc/postgresql/9.5/main/
environment  pg_ctl.conf  pg_hba.conf  pg_ident.conf  postgresql.conf  start.conf

$ sudo ls /var/lib/postgresql/9.5/main/
base	 pg_commit_ts  pg_multixact  pg_serial	   pg_stat_tmp	pg_twophase  postgresql.auto.conf
global	 pg_dynshmem   pg_notify     pg_snapshots  pg_subtrans	PG_VERSION   postmaster.opts
pg_clog  pg_logical    pg_replslot   pg_stat	   pg_tblspc	pg_xlog      postmaster.pid

$ which psql
/usr/bin/psql

$ ls -l /usr/bin/psql
lrwxrwxrwx 1 root root 37 Mar 31  2016 /usr/bin/psql -> ../share/postgresql-common/pg_wrapper

We perform a purge rather than remove since we want to remove the configuration files along with the packages.

$ sudo apt purge postgresql-client-common postgresql-common postgresql

Let's make sure everything has been removed. If not, we'll remove it:

$ dpkg -l | grep postgresql

$ dpkg -l | grep libpq
ii  libpq-dev                                  9.5.9-0ubuntu0.16.04                          amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64                               9.5.9-0ubuntu0.16.04                          amd64        PostgreSQL C client library

$ sudo apt purge libpq5

$ sudo apt autoremove	 # general cleanup

$ ls /etc/postgresql
ls: cannot access /etc/postgresql: No such file or directory

$ ls /var/lib/posgresql
ls: cannot access /var/lib/posgresql: No such file or directory

$ ls /usr/bin/psql
ls: cannot access /usr/bin/psql: No such file or directory

$ ldconfig -p | grep libpq

Next let's download the git repo. We'll follow the official postgreSQL documentation, and there's a wiki page for Working with Git

$ cd /build/	  # this is where we keep our git clones / projects

$ git clone git://git.postgresql.org/git/postgresql.git

$ cd postgresql/

We're going to work with the 10_0 git branch, so let's do the following, which creates a local branch that tracks the remote branch:

$ git tag -l | grep 10_0
REL_10_0

$ git checkout REL_10_0

$ git log
commit 5df0e99bea1c3e5fbffa7fbd0982da88ea149bb6
Author: Tom Lane
Date:   Mon Oct 2 17:09:15 2017 -0400

    Stamp 10.0.
 ...
 
 $ ls
 aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.in  HISTORY  Makefile  README  README.git  src

We prefer to build outside the source directory, so let's create a new build directory and run configure from there. Note that you may need to install some packages before configure will succeed (e.g., libreadline-dev, systemtap-sdt-dev, zlib1g-dev, libssl-dev, libpam0g-dev, and python-dev). Also, make sure you have flex and bison installed. If you get stuck on finding a package missing during configure, then take a look at the Ubuntu Packages Search page.

$ openssl version	# we're using Ubuntu's package version
OpenSSL 1.0.2g  1 Mar 2016

$ mkdir build

$ cd build  	# /build/postgresql/build

$ ../configure --with-python --with-openssl --with-pam --enable-debug --enable-depend

$ make

Note that configure has many build and install options. Type ../postgresql/configure --help for more information.

Next we need to install postgreSQL. We're happy to stay with the default path of /usr/local/postgresql. However, the default path can be overridden with the use of configure options (e.g., --prefix=<default path>)

$ sudo make install

Let's now do some checking and general housekeeping:

$ cd /usr/local/pgsql/
$ tree -d -L 2
.
├── bin
├── include
│   ├── informix
│   ├── internal
│   ├── libpq
│   └── server
├── lib
│   ├── pgxs
│   └── pkgconfig
└── share
    ├── extension
    ├── timezone
    ├── timezonesets
    └── tsearch_data

 $ find . -name '*.conf.sample'
./share/pg_ident.conf.sample
./share/pg_hba.conf.sample
./share/recovery.conf.sample
./share/postgresql.conf.sample
./share/pg_service.conf.sample

export PATH=$PATH:/usr/local/pgsql/		# add this to your .bashrc

Help us improve this article by adding your comment or question:

email addresses are neither displayed nor shared