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 (https://www.postgresql.org/ftp/source/). There are multiple archives available to download the desired version. After downloading you need to untar the archive.
1 2 3 | PGVER=12.3 wget https://ftp.postgresql.org/pub/source/v12.3/postgresql-$PGVER.tar.gz tar -zxvf postgresql-$PGVER.tar.gz |
2 – Download the Debian PostgreSQL’s package generator scripts from the site (https://salsa.debian.org/postgresql/postgresql).
1 | git clone https://salsa.debian.org/postgresql/postgresql.git |
3 – Copy the “debian” folder to postgresql-$PGVER
1 | cp postgresql/debian postgresql-$PGVER -rf |
4 – Change the directory to PostgreSQL code.
1 | cd postgreql-$PGVER |
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.
1 2 | sudo apt-get install dpkg-dev dpkg-buildpackage -rfakeroot -b -uc -us |
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.
1 2 3 4 5 | dpkg-checkbuilddeps: error: Unmet build dependencies: bison clang-11 debhelper-compat (= 13) dh-exec (>= 0.13~) docbook-xsl (>= 1.77) f lex gdb gettext libicu-dev libio-pty-perl libipc-run-perl libkrb5-dev libldap2-dev libpam0g-dev | libpam-dev libperl-dev libreadline-de v libselinux1-dev libssl-dev libsystemd-dev libxml2-dev libxml2-utils libxslt1-dev llvm-11-dev pkg-config python3-dev systemtap-sdt-dev tcl-dev uuid-dev xsltproc zlib1g-dev | libz-dev dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting |
Issue – 2: There is no debhelper-compat on LTS Debian.
You need to modify the control file:
1 2 3 4 5 6 7 8 9 10 11 12 | $ git diff diff --git a/debian/control b/debian/control index 3b94937..534fd56 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Rules-Requires-Root: no Build-Depends: bison, clang-11 [!alpha !hppa !hurd-i386 !ia64 !kfreebsd-amd64 !kfreebsd-i386 !m68k !powerpc !riscv64 !sh4 !sparc64 !x32], - debhelper-compat (= 13), + debhelper, dh-exec (>= 0.13~), docbook-xsl (>= 1.77), dpkg-dev (>= 1.16.1~), |
Then you need to create a compact file:
1 | echo 9 > debian/compat |
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 (https://apt.llvm.org/).
1 2 | deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch main deb-src http://apt.llvm.org/stretch/ llvm-toolchain-stretch main |
1 2 | sudo apt-get update apt-get install libllvm-11-ocaml-dev libllvm11 llvm-11 llvm-11-dev llvm-11-doc llvm-11-examples llvm-11-runtime |
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.
1 2 3 4 5 6 7 8 9 | postgresql-$PGVER_amd64.deb postgresql-client-$PGVER_amd64.deb postgresql-server-dev-$PGVER_amd64.deb postgresql-plperl-$PGVER_amd64.deb postgresql-doc-$PGVER_all.deb postgresql-pltcl-$PGVER_amd64.deb postgresql-plpython3-$PGVER_amd64.deb postgresql-x_amd64.buildinfo postgresql-x_amd64.changes |
Conclusion
Most people have some misconception that a custom build is a hard way, but it only requires a little bit of managed effort.
Percona Distribution for PostgreSQL provides the best and most critical enterprise components from the open-source community, in a single distribution, designed and tested to work together.