Mind Chasers Inc.
Mind Chasers Inc.

Quick Install of PostgreSQL 11 from Git on Ubuntu Linux 18.04

We review basic steps to clone, build, and configure PostgreSQL Release 11 on Ubuntu Linux 18.04. PostgreSQL is one of the most advanced and popular relational databases in the world. And best of all, it's open source.


PostgreSQL is a powerful, stable, and highly configurable open source relational database. PostgreSQL 11 has recently been released. Since we're developers & our database is a core, networked system function, we want to work with the cutting edge release and its source to facilitate optimization, customization, and experimentation. Below is a basic guide on how we built and configured PostgreSQL from Git on Ubuntu Linux 18.04.

Install and Build from Git

Before we begin, let's see if we have PostgreSQL packages already installed on our Ubuntu 18.04 system. We show various ways below to detect whether remants of postgres exist on our system. As you can, our system is clean of previous releases.

$ which psql

$ ps -e | grep post

$ dpkg -l | grep postgres

$ dpkg -l | grep libpq

$ldconfig -p | grep libpq

If it is installed, you can perform a remove or purge. Note that a purge will remove the configuration files along with the packages.

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

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

$ mkdir -p /build; cd /build	

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

$ cd postgresql/

We're going to work with the release 11 branch:

$ git branch -r
  origin/HEAD -> origin/master

$ git checkout REL_11_STABLE
Switched to branch 'REL_11_STABLE'
Your branch is up to date with 'origin/REL_11_STABLE'.
 $ ls
aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.in  HISTORY  Makefile  README  README.git  src

We can see from the directory list above, that we're dealing with an autotools project.

Also, we always prefer to build outside the source directory whenever possible, 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., libreadline6-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

$ sudo apt install libreadline6-dev systemtap-sdt-dev zlib1g-dev libssl-dev libpam0g-dev python-dev

$ openssl version 	
OpenSSL 1.1.0g  2 Nov 2017	# we're using Ubuntu's package version

$ mkdir build; cd build  	# /build/postgresql/build

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

$ make
All of PostgreSQL successfully made. Ready to install.

Note that configure has many build and install options. Run ../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'

Basic Configure of PostgreSQL

We want to work with a separate user account, and we'll follow the convention of using the user account postgres.

$ sudo adduser --system --home /usr/local/pgsql/data --shell /bin/bash --group postgres
Adding system user `postgres' (UID 123) ...
Adding new group `postgres' (GID 130) ...
Adding new user `postgres' (UID 123) with group `postgres' ...
Creating home directory `/usr/local/pgsql/data' ... 

$ sudo adduser postgres ssl-cert
Adding user `postgres' to group `ssl-cert' ...
Adding user postgres to group ssl-cert

$ sudo adduser postgres sudo		# or optionally perform a visudo
Adding user `postgres' to group `sudo' ...
Adding user postgres to group sudo

$ sudo passwd postgres			# set our user passwd

$ ls -l /usr/local/pgsql
total 20
drwxr-xr-x 2 root     root     4096 Oct 10 12:35 bin
drwxr-xr-x 2 postgres postgres 4096 Oct 10 12:38 data
drwxr-xr-x 6 root     root     4096 Oct 10 12:35 include
drwxr-xr-x 4 root     root     4096 Oct 10 12:35 lib
drwxr-xr-x 6 root     root     4096 Oct 10 12:35 share

$ su postgres

$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data --pwprompt	# create a superuser password

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

Now let's start the server but first modify the PATH environment variable to include /usr/local/pgsql/bin

$ cd /usr/local/pgsql/data

$ echo 'export PATH=$PATH:/usr/local/pgsql/bin' >> .bashrc	# use single quotes so not to expand $PATH

$ echo 'export PGDATA=/usr/local/pgsql/data' >> .bashrc

$ source ./.bashrc

$ pg_ctl start -l logfile
server starting

$ ps -e | grep postgres
 1553 pts/0    00:00:00 postgres
 1555 ?        00:00:00 postgres
 1556 ?        00:00:00 postgres
 1557 ?        00:00:00 postgres
 1558 ?        00:00:00 postgres
 1559 ?        00:00:00 postgres
 $ psql
 psql (10.0)
Type "help" for help.


Obviously, there's more work to do to get this working in your system including access permissions, which may be set via the pg_hba.conf file, and inclusion in your startup process. However, for our purpose of exercising and testing a postgreSQL database server that we built from a git branch, we're ready to begin testing with it.

Didn't find an answer to your question? Post your issue below or in our new FORUM, and we'll try our best to help you find a solution.

And please note that we update our site daily with new content related to our open source approach to network security and system design. If you would like to be notified about these changes, then please follow us on Twitter and join our mailing list.

subscribe to mailing list:

Please help us improve this article by adding your comment or question:

your email address will be kept private
authenticate with a 3rd party for enhanced features, such as image upload
previous month
next month