How to Create PostgreSQL Custom Builds and Debian Packages

Some time ago, I required a specific version of PostgreSQL. After searching on all the repositories, I was unable to find that specific version. It seems that the PostgreSQL community removes the old package when a new minor version comes. For example, if you need the 12.2 version but the 12.3 version is out, it’s really hard to find out the exact version. I am a developer, so I always can build that specific version for myself, but for the user, they have two major issues. The first issue is they require the “deb” package, not the binaries, and the second issue is they don’t want a complete development environment on their production/staging server. So, I have decided to write a blog to explain how to make a custom build for Debian or ubuntu and make Debian packages.

1 – Download PostgreSQL from this FTP site ( There are multiple archives available to download the desired version. After downloading you need to untar the archive.

2 – Download the Debian PostgreSQL’s package generator scripts from the site ( 

3 – Copy the “debian” folder to postgresql-$PGVER

4 – Change the directory to PostgreSQL code.

5 – The command will generate the Debian packages. This will compile the source code and run the test cases. After that, it will generate the Debian packages. 

You may face some issues based on what PostgreSQL version you are building and what version of Debian you are using.

Issue – 1: You may see some dependency unmet error messages, something like this below. In that case, you need to install all of these packages using the apt-get command.

Issue – 2: There is no debhelper-compat on LTS Debian.

You need to modify the control file:

Then you need to create a compact file:

Issue – 3: You may not find llvm on Debian 9, so there you need to add these lines in /etc/apt/sources.list. The complete list of the repo can be found here (

After fixing the issue you can restart from step 5.

Following is the list generated by the last step, which can be copied to the machine where you want to install that.


Most people have some misconception that a custom build is a hard way, but it only requires a little bit of managed effort.

The Percona Distribution for PostgreSQL is free to download and use. It is the best and most critical enterprise-level components from the open-source community, designed and tested to work together in one single source. 

Share this post

Leave a Reply