pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: coolaj86 (@coolaj86) <noreply+coolaj86@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #932: doc: How to build with relocatable postgres
Date: Tue, 02 Dec 2025 22:14:34 +0000
Message-ID: <gh-pgvector-pgvector-932@github.com> (raw)

I'm not a C/C++ developer, so although this is probably obvious to many who build postgres extensions regularly, figuring out these few steps took an embarrassing amount of time, so I'm documenting this here for my future self and others equally ignorant to myself.

If any of the maintainers care to drop in their knowledge about how to do this in a simpler way (i.e. getting a relocatable distributable using the postgres source without fully compiling it first), that would be great.

# 1. Building postgres

I won't go through all of the steps here, but suffice it to say that:
- this is the official tarball: https://ftp.postgresql.org/pub/source/v18.1/postgresql-18.1.tar.gz
- and the official build docs: https://www.postgresql.org/docs/current/install-make.html 
   ```sh
   wget -c https://ftp.postgresql.org/pub/source/v18.1/postgresql-18.1.tar.gz
   tar -xvf postgresql-18.1.tar.gz

   # ... a bunch of stuff to compile and build in relocatable fashion ...
   ```
- but I'm using [pg-build-linux](https://github.com/bnnanet/pg-essentials/blob/main/pg-build-linux) and [pg-build-macos](https://github.com/bnnanet/pg-essentials/blob/main/pg-build-macos) from [pg-essentials](https://webinstall.dev/pg-essentials) which builds a relocatable postgres, which is not officially supported and took me _days_ to figure out a year or so ago
   ```sh
   curl https://webi.sh/pg-essentials | sh
   . ~/.config/envman/PATH.env

   # this will install all necessary build tooling (make, llvm, etc) on Debian and alpine (musl) systems 
   pg-build 'custom+pgvector' 18.1
   ```
   ```
   tar xvf ./postgres-18.1.0-x86_64-linux-gnu.tar.gz
   ```

It's important that the `include` folder isn't trimmed because the source generated for this through the build process is _NOT_ the same as what's in the original source. One mistake that I made was trying to use the source's `include`.

# 2. Set `PG_CONFIG` and build

To get `$HOME/postgres-18.1.0-x86_64-linux-gnu/src/include/server` instead of failing to find the one that doesn't exist in `/usr/include`, `PG_CONFIG` must be set:

```sh
export PG_CONFIG="$HOME/postgres-18.1.0-x86_64-linux-gnu/bin/pg_config"
```

```sh
git clone https://github.com/pgvector/pgvector.git
pushd ./pgvector/
make
make install
```

`pgvector` will be installed to:
```sh
$HOME/postgres-18.1.0-x86_64-linux-gnu/include/server/extension/vector
$HOME/postgres-18.1.0-x86_64-linux-gnu/lib/bitcode/vector
$HOME/postgres-18.1.0-x86_64-linux-gnu/lib/bitcode/vector.index.bc
$HOME/postgres-18.1.0-x86_64-linux-gnu/lib/vector.so
$HOME/postgres-18.1.0-x86_64-linux-gnu/share/extension/vector--0.1.0--0.1.1.sql
$HOME/postgres-18.1.0-x86_64-linux-gnu/share/extension/vector--[...].sql
$HOME/postgres-18.1.0-x86_64-linux-gnu/share/extension/vector--0.8.1.sql
$HOME/postgres-18.1.0-x86_64-linux-gnu/share/extension/vector.control
```

# 3. Relocate

The resulting folder can be relocated anywhere (e.g. `/home/user1/.local/opt/postgres`) and will function correctly and `CREATE EXTENSION vector;` will work.

My guess is that the bitcode is tied to the version of llvm used (`llvm-19` is stable for Debian Trixie and Ubuntu 24.04).

I imagine those individual files could be put into a tarball and extracted into any postgres folder that matches the installed versions of `glibc`, `llvm`, and `postgres`.

view thread (3+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-932@github.com>
Permalink:  ../gh-pgvector-pgvector-932@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox