Install the pgai extension from source
July 10, 2025 · View on GitHub
⚠️ Note:
For Windows users, we recommend using the pgai Docker image to run the pgai extension. These instructions have only been tested on macOS and Linux.
To install pgai from source on a PostgreSQL server:
-
Install the prerequisite software system-wide
-
PostgreSQL: Version 16 or newer is required.
-
Python3: if running
python3 --versionin Terminal returnscommand not found, download and install the latest version of Python3. -
Pip: if running
pip --versionin Terminal returnscommand not found, install it with one of the pip supported methods. -
PL/Python: follow How to install Postgres 16 with plpython3u: Recipes for macOS, Ubuntu, Debian, CentOS, Docker.
macOS: the standard PostgreSQL brew in Homebrew does not include the
plpython3extension. These instructions show how to install from an alternate tap.-
Postgresql plugin for the asdf version manager: set the
--with-pythonoption when installing PostgreSQL:POSTGRES_EXTRA_CONFIGURE_OPTIONS=--with-python asdf install postgres 16.3
-
-
pgvector: follow the install instructions from the official repository. This extension is automatically added to your PostgreSQL database when you install the pgai extension.
-
-
Clone the pgai repo at the latest tagged release:
git clone https://github.com/timescale/pgai.git --branch extension-0.8.0 cd pgai -
Install the
pgaiPostgreSQL extension:sudo just ext installNote: The install requires write access to system-owned paths to create the following files:
- pgai's Python dependencies (in
/usr/local/lib/pgai) - pgai's extension files (
ai.controlandai--*.sql) (in Postgres' extension directory, typically/usr/share/postgresql/<pg version>/extension, but configurable. Usepg_config --sharedirto determine this path) If you would prefer to not run the install command usingsudo, it must be run as a user with write access to the above paths.
We use just to run project commands. If you don't have just you can install the extension with:
sudo projects/extension/build.py install - pgai's Python dependencies (in
-
Connect to your database with a postgres client like psql v16 or PopSQL.
psql -d "postgres://<username>:<password>@<host>:<port>/<database-name>" -
Create the pgai extension:
CREATE EXTENSION IF NOT EXISTS ai CASCADE;The
CASCADEautomatically installspgvectorandplpython3uextensions.