Files
programming/PostgreSQL/build_rdbms_01/install_pgvector.sh
T
2026-10-11 16:45:57 +02:00

54 lines
1.9 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=install_common.sh
source "$SCRIPT_DIR/install_common.sh"
readonly STAGING_DIR="${STAGING_DIR:-$SCRIPT_DIR/tmp}"
readonly POSTGRES_ROOT="${POSTGRES_ROOT:-/app/postgres/rdbms}"
readonly PGVECTOR_REPOSITORY="${PGVECTOR_REPOSITORY:-pgvector/pgvector}"
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
show_help "$0" "Build and install pgvector for an existing PostgreSQL installation."
exit 0
fi
POSTGRES_VERSION="$(parse_postgresql_version "$@")"
readonly POSTGRES_VERSION
validate_postgresql_version "$POSTGRES_VERSION"
require_tools curl tar make
readonly PREFIX="${PREFIX:-$POSTGRES_ROOT/$POSTGRES_VERSION}"
readonly PG_CONFIG="$PREFIX/bin/pg_config"
require_postgresql_installation "$PREFIX"
reset_staging_dir "$STAGING_DIR"
readonly PGVECTOR_TAG="${PGVECTOR_TAG:-$(latest_tag "$PGVECTOR_REPOSITORY")}"
[[ -n "$PGVECTOR_TAG" ]] || die "could not determine the latest pgvector release"
readonly PGVECTOR_VERSION="${PGVECTOR_TAG#v}"
readonly PGVECTOR_DIR="$STAGING_DIR/pgvector-$PGVECTOR_VERSION"
printf 'Building pgvector %s\n' "$PGVECTOR_TAG"
download_source "$STAGING_DIR" "$PGVECTOR_REPOSITORY" "$PGVECTOR_TAG" \
"pgvector-$PGVECTOR_VERSION.tar.gz" "$PGVECTOR_DIR"
cd "$PGVECTOR_DIR"
make -j"${JOBS:-$(nproc)}" PG_CONFIG="$PG_CONFIG"
make install PG_CONFIG="$PG_CONFIG"
test -f "$PREFIX/lib/vector.so"
test -f "$PREFIX/share/extension/vector.control"
readonly SAVED_SOURCE_DIR="$(copy_install_source "$PGVECTOR_DIR" "$PREFIX" "pgvector-$PGVECTOR_TAG")"
write_install_recipe "$SAVED_SOURCE_DIR" "$POSTGRES_VERSION" "$PREFIX" <<'RECIPE'
cd "$SCRIPT_DIR"
# Configure
# pgvector uses PGXS directly and does not require a separate configure step.
# Make
make -j"$JOBS" PG_CONFIG="$PG_CONFIG"
# Make install
make install PG_CONFIG="$PG_CONFIG"
RECIPE