Files
hibernate-demo/hibernate-vector/scripts/start-postgres.sh
T

25 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Starts a throwaway PostgreSQL 16 with pgvector 0.8.7 on 127.0.0.1:55433, without Docker. Idempotent. Run as root in a disposable sandbox.
# PostgreSQL : Ubuntu 24.04 packages postgresql-16 and postgresql-server-dev-16 (apt)
# pgvector : built from the v0.8.7 tag of https://github.com/pgvector/pgvector (the Ubuntu package is 0.6.0)
# PostgreSQL refuses to run as root, so this creates a throwaway OS user (pgj).
set -euo pipefail
B="${BASE:-/tmp/hibvec-pg}"
PGPORT="${PGPORT:-55433}"
PGBIN=/usr/lib/postgresql/16/bin
if [ ! -f /usr/share/postgresql/16/extension/vector.control ] || ! grep -q "0.8.7" /usr/share/postgresql/16/extension/vector.control; then
apt-get install -y postgresql-16 postgresql-server-dev-16 build-essential git >/dev/null
rm -rf /tmp/pgvector-src
git clone -q --depth 1 --branch v0.8.7 https://github.com/pgvector/pgvector.git /tmp/pgvector-src
make -C /tmp/pgvector-src -s && make -C /tmp/pgvector-src -s install
fi
id pgj >/dev/null 2>&1 || useradd -m pgj
mkdir -p "$B"; chown pgj "$B"
if [ ! -f "$B/data/PG_VERSION" ]; then
su pgj -c "cd /tmp && $PGBIN/initdb -D $B/data -U postgres -A trust -E UTF8 >/dev/null"
fi
su pgj -c "$PGBIN/pg_ctl -D $B/data -o '-p $PGPORT -k /tmp' -l $B/pg.log -w start" || true
psql -h 127.0.0.1 -p "$PGPORT" -U postgres -Atc "select 1 from pg_database where datname='vec'" | grep -q 1 \
|| psql -h 127.0.0.1 -p "$PGPORT" -U postgres -Atc "create database vec"
psql -h 127.0.0.1 -p "$PGPORT" -U postgres -d vec -Atc "select version()"