How to Create PostgreSQL Custom Builds and RPM Packages

As a developer, there is sometimes a need to create custom builds of PostgreSQL. This may arise because a developer wants to install specific versions of PostgreSQL RPMs, which can be hard to find among previously released versions. A developer might require a specific version to perform a proof of concept (POC) or to create a development environment compatible with their application. So, I decided to write a blog to explain how to make a custom build for Rocky or RHEL and make RPM packages.

NOTE: I am using Rocky Linux 8 for performing a demo.

  • Make sure to install below pre-requisites requirements:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf install -y docbook-xsl libxslt-devel clang-devel python3-devel perl-generators bison e2fsprogs-devel flex gettext git glibc-devel krb5-devel libicu-devel libselinux-devel libuuid-devel libxml2-devel libxslt-devel clang llvm-devel openldap-devel openssl-devel pam-devel patch perl perl-ExtUtils-MakeMaker perl-ExtUtils-Embed readline-devel rpmdevtools selinux-policy systemd systemd-devel systemtap-sdt-devel tcl-devel vim wget zlib-devel lz4-devel git rpmdevtools rpmlint libcurl-devel curl pgdg-srpm-macros
sudo dnf --enablerepo=devel install perl-IPC-Run -y
sudo dnf group install "Development Tools" -y
Enter fullscreen mode Exit fullscreen mode
  • Clone the PostgreSQL’s rpms repository:
 git clone git://git.postgresql.org/git/pgrpms.git ~/pgrpms
Enter fullscreen mode Exit fullscreen mode
  • Firstly, define the PostgreSQL version you want to create a custom build. For example, if you want to choose 15.5 version of PostgreSQL then define version as below:
PGMAJVER=15
PGMINVER=5
VERSION="${PGMAJVER}.${PGMINVER}"
CONFIG_FILE="$HOME/pgrpms/rpm/redhat/main/non-common/postgresql-${PGMAJVER}/main/postgresql-${PGMAJVER}.spec"
GLOBAL_FILE="$HOME/pgrpms/rpm/redhat/global/Makefile.global-PG${PGMAJVER}"
Enter fullscreen mode Exit fullscreen mode
  • Update the version settings as per your desired version by running below command:
cd ~/pgrpms
git checkout $(git log --pretty=format:"%H %s" | grep "Update to ${VERSION}" | awk '{print $1}' | head -n 1)
sed -i '/git pull/s/^/#/' "$GLOBAL_FILE"
Enter fullscreen mode Exit fullscreen mode
  • Now navigate to desired version directory
cd ~/pgrpms/rpm/redhat/$PGMAJVER/postgresql-$PGMAJVER/EL-8
Enter fullscreen mode Exit fullscreen mode
  • Now execute the below command to start RPM packages compilation
make build$PGMAJVER
Enter fullscreen mode Exit fullscreen mode

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

The following list has been generated in the final step. It can be copied to the target machine for installation.

postgresql$PGMAJVER-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-server-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-contrib-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-plperl-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-plpython3-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-libs-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-llvmjit-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-devel-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-test-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-pltcl-$VERSION .rhel8.x86_64.rpm
postgresql$PGMAJVER-docs-$VERSION .rhel8.x86_64.rpm
Enter fullscreen mode Exit fullscreen mode

Conclusion:
Many people hold the misconception that a custom build is challenging, but it simply requires a bit of structured effort.
AgensSQL by Bitnine Global Inc. offers enhanced database features compared to the standard PostgreSQL database, providing stability and up-to-date functionalities to meet modern enterprise requirements.


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top