@@ -8,6 +8,7 @@ PGUSER=${3:-postgres}
88PGPASSWORD=${4:- postgres}
99PGDATABASE=${5:- postgres}
1010
11+ # Install PostgreSQL
1112echo " Installing PostgreSQL ${PG_VERSION} ..."
1213sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
1314sudo apt-get update
@@ -19,55 +20,20 @@ sudo pg_dropcluster --stop ${PG_VERSION} main || true
1920sudo pg_createcluster ${PG_VERSION} main --start || true
2021sudo systemctl start postgresql
2122
22- # Create runner user and grant permissions
23- sudo -u postgres psql -c " CREATE USER runner WITH SUPERUSER;"
24-
25- # Verify PostgreSQL installation and version
26- echo " Checking PostgreSQL version..."
27- PG_ACTUAL_VERSION=$( sudo -u postgres psql -t -c " SHOW server_version;" | xargs)
28- echo " PostgreSQL actual version: ${PG_ACTUAL_VERSION} "
29- PG_MAJOR_VERSION=$( echo ${PG_ACTUAL_VERSION} | cut -d. -f1)
30- echo " PostgreSQL major version: ${PG_MAJOR_VERSION} "
31-
32- # Remove any existing pgvector installations
33- sudo apt-get remove -y postgresql-* -pgvector || true
34- sudo rm -f /usr/lib/postgresql/* /lib/vector.so
35- sudo rm -f /usr/share/postgresql/* /extension/vector*
36-
23+ # Install build dependencies and pgvector
3724echo " Installing pgvector..."
38- # Always build from source to match PostgreSQL version
39- echo " Building pgvector from source..."
40- sudo apt-get install -y postgresql-server-dev-${PG_MAJOR_VERSION} build-essential git
25+ sudo apt-get install -y postgresql-server-dev-${PG_VERSION} build-essential git
4126git clone --branch v${PGVECTOR_VERSION} https://github.com/pgvector/pgvector.git
4227cd pgvector
43- make clean
44- PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION} /bin/pg_config make
45- sudo PG_CONFIG=/usr/lib/postgresql/${PG_MAJOR_VERSION} /bin/pg_config make install
28+ PG_CONFIG=/usr/lib/postgresql/${PG_VERSION} /bin/pg_config make
29+ sudo PG_CONFIG=/usr/lib/postgresql/${PG_VERSION} /bin/pg_config make install
4630cd ..
4731rm -rf pgvector
4832
49- # Configure PostgreSQL authentication for CI
50- echo " local all postgres trust" | sudo tee /etc/postgresql/${PG_VERSION} /main/pg_hba.conf
51- echo " local all runner trust" | sudo tee -a /etc/postgresql/${PG_VERSION} /main/pg_hba.conf
52- echo " local all all trust" | sudo tee -a /etc/postgresql/${PG_VERSION} /main/pg_hba.conf
53-
54- # Restart PostgreSQL to ensure pgvector is loaded
33+ # Configure PostgreSQL authentication
34+ echo " local all all trust" | sudo tee /etc/postgresql/${PG_VERSION} /main/pg_hba.conf
5535sudo systemctl restart postgresql
5636
57- # Verify pgvector installation
58- echo " Verifying pgvector installation..."
59- echo " Installed extensions:"
60- sudo -u postgres psql -d postgres -c " SELECT * FROM pg_extension;" || true
61- echo " Available extensions:"
62- sudo -u postgres psql -d postgres -c " SELECT * FROM pg_available_extensions WHERE name = 'vector';" || true
63-
64- # List extension directory contents
65- echo " Checking extension files..."
66- echo " PostgreSQL ${PG_MAJOR_VERSION} extension directory:"
67- ls -la /usr/share/postgresql/${PG_MAJOR_VERSION} /extension/ || true
68- echo " PostgreSQL ${PG_MAJOR_VERSION} lib directory:"
69- ls -la /usr/lib/postgresql/${PG_MAJOR_VERSION} /lib/ || true
70-
7137# Set password and create database
7238sudo -u postgres psql -c " ALTER USER postgres WITH PASSWORD '$PGPASSWORD ';"
7339if [ " $PGUSER " != " postgres" ]; then
@@ -78,7 +44,7 @@ if [ "$PGDATABASE" != "postgres" ]; then
7844 sudo -u postgres createdb -O $PGUSER $PGDATABASE
7945fi
8046
81- # Create and configure pgvector extension
47+ # Create pgvector extension
8248sudo -u postgres psql -d $PGDATABASE -c " CREATE EXTENSION IF NOT EXISTS vector;"
8349
8450# Export environment variables
@@ -87,18 +53,18 @@ export PGUSER=$PGUSER
8753export PGPASSWORD=$PGPASSWORD
8854export PGDATABASE=$PGDATABASE
8955
90- # Export to GITHUB_ENV only if running in GitHub Actions
56+ # Export to GITHUB_ENV if running in GitHub Actions
9157if [ -n " $GITHUB_ENV " ]; then
9258 echo " PGHOST=$PGHOST " >> $GITHUB_ENV
9359 echo " PGUSER=$PGUSER " >> $GITHUB_ENV
9460 echo " PGPASSWORD=$PGPASSWORD " >> $GITHUB_ENV
9561 echo " PGDATABASE=$PGDATABASE " >> $GITHUB_ENV
9662fi
9763
98- # Verify installation
99- echo " Checking PostgreSQL installation... "
100- psql -d $PGDATABASE -c " SELECT version(); "
101- echo " Checking available extensions... "
102- psql -d $PGDATABASE -c " SELECT * FROM pg_available_extensions WHERE name = 'vector'; "
103- echo " Checking installed extensions... "
104- psql -d $PGDATABASE -c " SELECT * FROM pg_extension WHERE extname = 'vector'; "
64+ # Print success message
65+ echo " PostgreSQL and pgvector have been successfully installed! "
66+ echo " Connection details: "
67+ echo " Host: localhost "
68+ echo " User: $PGUSER "
69+ echo " Database: $PGDATABASE "
70+ echo " Password: [hidden] "
0 commit comments