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
- Clone the PostgreSQL’s rpms repository:
git clone git://git.postgresql.org/git/pgrpms.git ~/pgrpms
- 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}"
- 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"
- Now navigate to desired version directory
cd ~/pgrpms/rpm/redhat/$PGMAJVER/postgresql-$PGMAJVER/EL-8
- Now execute the below command to start RPM packages compilation
make build$PGMAJVER
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
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.