DEV Community

Franck Pachot for YugabyteDB

Posted on • Edited 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:2.18.0.1-b4 
docker exec -it $(
docker run -d yugabytedb/yugabyte:2.18.0.1-b4 /home/yugabyte/bin/yugabyted start --advertise_address=0.0.0.0 --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 https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
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 README.md

dnf -y install gsl gsl-devel
git clone https://github.com/chanukyasds/pg_math.git
cd pg_math
make
make install
Enter fullscreen mode Exit fullscreen mode

Install in YugabyteDB

I can explore the necessary files with pg_config and ldd:
pg_config

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 (1)

Collapse
 
v_systems profile image
V_Systems

Apply your GLSL skills to the V Shader Hackathon, running until 22 May 2025!
Create unique Shader art to win up to $1000 :)

  • Create your original Shader
  • Upload the Javascript to the V Systems blockchain to turn it into an NFT
  • Be one of the 16 winners of prizes ranging $500-$1000

How to join: medium.com/vsystems/13-26-april-cr...

Any questions? Join our community!