DEV Community

Franck Pachot for YugabyteDB

Posted on • Updated on

Compile pg_math for YugabyteDB (wrapper on GNU Scientific Library distribution functions)

Many extensions are easy to compile on PostgreSQL and install on YugabyteDB. The most important is to compile it in the right version of PostgreSQL and identify all files and dependencies.
In the first post of this series, I did it in a Dockerfile.
Here I'll run similar commands on a Docker container started from the YugabyteDB 2.18 image, that is built with Alma8, to install pg_math, a wrapper for GSL (GNU Scientific Library) statistical distribution functions.

Start YugabyteDB

As this extension comes as a dynamic library that doesn't need to be pre-loaded, I can already start YugabyteDB and will install the extension just before the CREATE EXTENSION.

I start this test container and connect to it:

docker pull   yugabytedb/yugabyte: 
docker exec -it $(
docker run -d yugabytedb/yugabyte: /home/yugabyte/bin/yugabyted start --advertise_address= --background=false
) bash
Enter fullscreen mode Exit fullscreen mode

Install postgresql11-devel

YugabyteDB is compatible with PostgreSQL 11.2 and then I'll build my extension with PostgreSQL 11:

dnf update -y
dnf groupinstall -y 'Development Tools'
dnf install -y
dnf install epel-release -y redhat-rpm-config
dnf --enablerepo=powertools install perl-IPC-Run -y
dnf -qy module disable postgresql
dnf install -y postgresql11-devel
export PATH="/usr/pgsql-11/bin:${PATH}" # add pg_config to the path
Enter fullscreen mode Exit fullscreen mode

This is needed to build the extension. The idea is to build it in an ephemeral container and just get the necessary files to deploy to YugabyteDB nodes

Build pg_math extension

I follow the instructions from pg_math

dnf -y install gsl gsl-devel
git clone
cd pg_math
make install
Enter fullscreen mode Exit fullscreen mode

Install in YugabyteDB

I can explore the necessary files with pg_config and ldd:

I get all files from the extension (lib and share/extension) as well as the dependencies (GSL - GNU Scientific Library):

cd /usr/pgsql-11
cp /usr/lib64/*gsl* lib
tar -cvf /tmp/extensions.tar lib share/extension
cd $YB_HOME/postgres
tar --skip-old-files -xvf /tmp/extensions.tar
Enter fullscreen mode Exit fullscreen mode

Test the extension

Now ready to CREATE EXTENSION and test it:
Image description

When the repo for the extension contains regression tests, it is a good practice to run them.

Top comments (0)