Install the pgai extension from source
Install the pgai extension from source on macOS and Linux.
Install the pgai extension from source
Section titled “Install the pgai extension from source”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 PostgreSQL 16 with plpython3u on macOS, Ubuntu, Debian, CentOS, or 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:Terminal window 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:
Terminal window git clone https://github.com/timescale/pgai.git --branch extension-0.8.0cd pgai -
Install the
pgaiPostgreSQL extension:Terminal window sudo just ext installWrite access requiredThe 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 PostgreSQL’ 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:
Terminal window sudo projects/extension/build.py install - pgai’s Python dependencies (in
-
Connect to your database with a postgres client like psql v16 or PopSQL.
Terminal window psql -d "postgres://<username>:<password>@<host>:<port>/<database-name>" -
Create the pgai extension:
CREATE EXTENSION IF NOT EXISTS ai CASCADE;The
CASCADEautomatically installspgvectorandplpython3uextensions.