Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Dec 9, 2024
1 parent 2e08351 commit ea13cd2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 133 deletions.
39 changes: 12 additions & 27 deletions scripts/install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,22 @@ PGUSER=${3:-postgres}
PGPASSWORD=${4:-postgres}
PGDATABASE=${5:-postgres}

# Function to export variables
export_var() {
local name=$1
local value=$2
export "$name=$value"
# Only export to GITHUB_ENV if running in GitHub Actions
if [ -n "$GITHUB_ENV" ]; then
echo "$name=$value" >> $GITHUB_ENV
fi
}

# Install PostgreSQL
brew install "postgresql@$PG_VERSION"
brew link --force "postgresql@$PG_VERSION"

# Add PostgreSQL binaries to PATH
PG_PATH="/usr/local/opt/postgresql@$PG_VERSION/bin"
# For Apple Silicon Macs
if [ -d "/opt/homebrew/opt/postgresql@$PG_VERSION/bin" ]; then
PG_PATH="/opt/homebrew/opt/postgresql@$PG_VERSION/bin"
fi
export PATH="$PG_PATH:$PATH"
# Only add to GITHUB_PATH if running in GitHub Actions
if [ -n "$GITHUB_PATH" ]; then
echo "$PG_PATH" >> $GITHUB_PATH
fi

# Start PostgreSQL
brew services start "postgresql@$PG_VERSION"

# Wait for PostgreSQL to start
sleep 3

# Set password and create database/user
Expand All @@ -56,22 +41,22 @@ make install
cd ..
rm -rf pgvector

# Create and configure pgvector extension
# Create pgvector extension
psql -d $PGDATABASE -c 'CREATE EXTENSION IF NOT EXISTS vector;'

# Export environment variables
export_var "PGHOST" "localhost"
export_var "PGUSER" "$PGUSER"
export_var "PGPASSWORD" "$PGPASSWORD"
export_var "PGDATABASE" "$PGDATABASE"
export PGHOST=localhost
export PGUSER=$PGUSER
export PGPASSWORD=$PGPASSWORD
export PGDATABASE=$PGDATABASE

# Verify installation
echo "Checking PostgreSQL installation..."
psql -d $PGDATABASE -c "SELECT version();"
echo "Checking available extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
echo "Checking installed extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"
# Export to GITHUB_ENV if running in GitHub Actions
if [ -n "$GITHUB_ENV" ]; then
echo "PGHOST=$PGHOST" >> $GITHUB_ENV
echo "PGUSER=$PGUSER" >> $GITHUB_ENV
echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV
echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV
fi

# Print success message
echo "PostgreSQL and pgvector have been successfully installed!"
Expand Down
66 changes: 16 additions & 50 deletions scripts/install-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PGUSER=${3:-postgres}
PGPASSWORD=${4:-postgres}
PGDATABASE=${5:-postgres}

# Install PostgreSQL
echo "Installing PostgreSQL ${PG_VERSION}..."
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
sudo apt-get update
Expand All @@ -19,55 +20,20 @@ sudo pg_dropcluster --stop ${PG_VERSION} main || true
sudo pg_createcluster ${PG_VERSION} main --start || true
sudo systemctl start postgresql

# Create runner user and grant permissions
sudo -u postgres psql -c "CREATE USER runner WITH SUPERUSER;"

# Verify PostgreSQL installation and version
echo "Checking PostgreSQL version..."
PG_ACTUAL_VERSION=$(sudo -u postgres psql -t -c "SHOW server_version;" | xargs)
echo "PostgreSQL actual version: ${PG_ACTUAL_VERSION}"
PG_MAJOR_VERSION=$(echo ${PG_ACTUAL_VERSION} | cut -d. -f1)
echo "PostgreSQL major version: ${PG_MAJOR_VERSION}"

# Remove any existing pgvector installations
sudo apt-get remove -y postgresql-*-pgvector || true
sudo rm -f /usr/lib/postgresql/*/lib/vector.so
sudo rm -f /usr/share/postgresql/*/extension/vector*

# Install build dependencies and pgvector
echo "Installing pgvector..."
# Always build from source to match PostgreSQL version
echo "Building pgvector from source..."
sudo apt-get install -y postgresql-server-dev-${PG_MAJOR_VERSION} build-essential git
sudo apt-get install -y postgresql-server-dev-${PG_VERSION} build-essential git
git clone --branch v${PGVECTOR_VERSION} https://github.com/pgvector/pgvector.git
cd pgvector
make clean
PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin/pg_config make
sudo PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin/pg_config make install
PG_CONFIG=/usr/lib/postgresql/${PG_VERSION}/bin/pg_config make
sudo PG_CONFIG=/usr/lib/postgresql/${PG_VERSION}/bin/pg_config make install
cd ..
rm -rf pgvector

# Configure PostgreSQL authentication for CI
echo "local all postgres trust" | sudo tee /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
echo "local all runner trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
echo "local all all trust" | sudo tee -a /etc/postgresql/${PG_VERSION}/main/pg_hba.conf

# Restart PostgreSQL to ensure pgvector is loaded
# Configure PostgreSQL authentication
echo "local all all trust" | sudo tee /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
sudo systemctl restart postgresql

# Verify pgvector installation
echo "Verifying pgvector installation..."
echo "Installed extensions:"
sudo -u postgres psql -d postgres -c "SELECT * FROM pg_extension;" || true
echo "Available extensions:"
sudo -u postgres psql -d postgres -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" || true

# List extension directory contents
echo "Checking extension files..."
echo "PostgreSQL ${PG_MAJOR_VERSION} extension directory:"
ls -la /usr/share/postgresql/${PG_MAJOR_VERSION}/extension/ || true
echo "PostgreSQL ${PG_MAJOR_VERSION} lib directory:"
ls -la /usr/lib/postgresql/${PG_MAJOR_VERSION}/lib/ || true

# Set password and create database
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$PGPASSWORD';"
if [ "$PGUSER" != "postgres" ]; then
Expand All @@ -78,7 +44,7 @@ if [ "$PGDATABASE" != "postgres" ]; then
sudo -u postgres createdb -O $PGUSER $PGDATABASE
fi

# Create and configure pgvector extension
# Create pgvector extension
sudo -u postgres psql -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;"

# Export environment variables
Expand All @@ -87,18 +53,18 @@ export PGUSER=$PGUSER
export PGPASSWORD=$PGPASSWORD
export PGDATABASE=$PGDATABASE

# Export to GITHUB_ENV only if running in GitHub Actions
# Export to GITHUB_ENV if running in GitHub Actions
if [ -n "$GITHUB_ENV" ]; then
echo "PGHOST=$PGHOST" >> $GITHUB_ENV
echo "PGUSER=$PGUSER" >> $GITHUB_ENV
echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV
echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV
fi

# Verify installation
echo "Checking PostgreSQL installation..."
psql -d $PGDATABASE -c "SELECT version();"
echo "Checking available extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
echo "Checking installed extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"
# Print success message
echo "PostgreSQL and pgvector have been successfully installed!"
echo "Connection details:"
echo " Host: localhost"
echo " User: $PGUSER"
echo " Database: $PGDATABASE"
echo " Password: [hidden]"
77 changes: 21 additions & 56 deletions scripts/install-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,30 @@ PGUSER=${3:-postgres}
PGPASSWORD=${4:-postgres}
PGDATABASE=${5:-postgres}

# Function to export variables
export_var() {
local name=$1
local value=$2
export "$name=$value"
# Only export to GITHUB_ENV if running in GitHub Actions
if [ -n "$GITHUB_ENV" ]; then
echo "$name=$value" >> $GITHUB_ENV
fi
}

# Set environment variables
export_var "PGDATA" "/c/data/postgres"
export_var "PGHOST" "localhost"
export_var "PGUSER" "$PGUSER"
export_var "PGPASSWORD" "$PGPASSWORD"
export_var "PGDATABASE" "$PGDATABASE"
export PGDATA="/c/data/postgres"
export PGHOST=localhost
export PGUSER=$PGUSER
export PGPASSWORD=$PGPASSWORD
export PGDATABASE=$PGDATABASE

# Export to GITHUB_ENV if running in GitHub Actions
if [ -n "$GITHUB_ENV" ]; then
echo "PGDATA=$PGDATA" >> $GITHUB_ENV
echo "PGHOST=$PGHOST" >> $GITHUB_ENV
echo "PGUSER=$PGUSER" >> $GITHUB_ENV
echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV
echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV
fi

# Initialize PostgreSQL if not already initialized
# Initialize PostgreSQL if not initialized
if [ ! -d "$PGDATA" ]; then
# Create a temporary password file
PWFILE=$(mktemp)
echo "$PGPASSWORD" > "$PWFILE"
mkdir -p "$PGDATA"
initdb -D "$PGDATA" -U $PGUSER -E UTF8

initdb -D "$PGDATA" -U $PGUSER --pwfile="$PWFILE"
rm -f "$PWFILE"

# Configure PostgreSQL for password authentication
echo "host all all 127.0.0.1/32 md5" >> "$PGDATA/pg_hba.conf"
# Configure PostgreSQL authentication
echo "host all all 127.0.0.1/32 md5" > "$PGDATA/pg_hba.conf"
echo "host all all ::1/128 md5" >> "$PGDATA/pg_hba.conf"

# Configure logging
cat >> "$PGDATA/postgresql.conf" << EOL
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d.log'
log_rotation_age = 1d
EOL

# Create log directory
mkdir -p "$PGDATA/log"
fi

# Start PostgreSQL
Expand All @@ -58,20 +41,12 @@ pg_ctl -D "$PGDATA" -w start
# Wait for PostgreSQL to start
sleep 3

# Show PostgreSQL logs
echo "PostgreSQL log content:"
if [ -f "$PGDATA/log/postgresql-$(date +%Y-%m-%d).log" ]; then
cat "$PGDATA/log/postgresql-$(date +%Y-%m-%d).log"
else
echo "Log file not found. PostgreSQL is still running, continuing..."
fi

# Create database if it doesn't exist
if [ "$PGDATABASE" != "postgres" ]; then
PGPASSWORD=$PGPASSWORD createdb -h localhost -U $PGUSER $PGDATABASE || true
fi

# Install build tools and dependencies if running in MSYS2
# Install build tools if running in MSYS2
if command -v pacman &> /dev/null; then
pacman -S --noconfirm \
mingw-w64-x86_64-gcc \
Expand All @@ -86,24 +61,14 @@ export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH"
# Build and install pgvector
git clone --branch "v$PGVECTOR_VERSION" https://github.com/pgvector/pgvector.git
cd pgvector
make clean
PG_CONFIG=/mingw64/bin/pg_config make
PG_CONFIG=/mingw64/bin/pg_config make install
cd ..
rm -rf pgvector

# Create and configure pgvector extension
echo "Creating pgvector extension..."
# Create pgvector extension
PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;"

# Verify installation
echo "Checking PostgreSQL installation..."
PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT version();"
echo "Checking available extensions..."
PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
echo "Checking installed extensions..."
PGPASSWORD=$PGPASSWORD psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"

# Print success message
echo "PostgreSQL and pgvector have been successfully installed!"
echo "Connection details:"
Expand Down

0 comments on commit ea13cd2

Please sign in to comment.