5

How to Create PostgreSQL Custom Builds and Debian Packages

 3 years ago
source link: https://www.percona.com/blog/2021/01/28/how-to-create-postgresql-custom-builds-and-debian-packages/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
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 (https://www.postgresql.org/ftp/source/). There are multiple archives available to download the desired version. After downloading you need to untar the archive.

Download and unzip the archive file
Shell
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). 

clone the repository
Shell
git clone https://salsa.debian.org/postgresql/postgresql.git

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

copy folder
Shell
cp postgresql/debian postgresql-$PGVER -rf

4 – Change the directory to PostgreSQL code.

change direcoty
Shell
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. 

Shell
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.

Dependency errors
Shell
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:

Modify control file
Shell
$ 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:

Create compact file
Shell
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/).

Add repositories
Shell
deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch main
deb-src http://apt.llvm.org/stretch/ llvm-toolchain-stretch main
Install llvm
Shell
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.

Shell
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.

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. 


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK