Getting Started
This tutorial installs PostgreSQL 18 and pgvector, starts a local test instance, and enables the extension in a database.
Use a supported Linux test host with internet access and curl installed. You need root or sudo access. Run the commands in order.
Install PIG
In mainland China, use https://repo.pigsty.cc/pig instead. The installer selects the RPM or DEB package for your host. See Installation for other methods.
Check the host
Check the OS code, architecture, and detected PostgreSQL installations. This command also tests repository connectivity.
Add repositories
Add PGDG and Pigsty PostgreSQL repositories, then refresh package metadata:
For China mirrors, add --mirror to this command.
Install PostgreSQL and pgvector
Review the package manager’s transaction and confirm it.
pg18 selects the PostgreSQL 18 packages. vector selects pgvector. The -v 18 option selects the extension’s PostgreSQL major version.
Check the installed extension files:
Start a test instance
This tutorial uses /pg/data-demo and port 15432 to avoid the default cluster on port 5432. Use an unused directory and port.
Create an empty data directory owned by the postgres operating-system user:
Start the instance on port 15432:
Enable and test pgvector
Connect to the test instance:
PIG reads the instance’s connection information from the specified data directory. At the psql prompt, run:
The first query returns the installed pgvector version. The second returns a distance of approximately 5.196. Exit psql with \q.
CREATE EXTENSION enables an extension in the connected database. Repeat it in each database that needs pgvector.
Stop the test instance when you finish:
The data stays in /pg/data-demo. Run the start command again to reuse the instance. See PostgreSQL management for service configuration and other operations.
Find more extensions
Before installing another extension, use info to check its setup requirements and avail to check package availability.
Select packages and versions
To use another PostgreSQL major version, replace 18 in the commands above.
See extension installation for package groups, version selection, and existing installations.
Inspect and update
pig ext status -v 18 lists installed extension files. To list extensions enabled in a database, run \dx in psql.
See extension updates when you need to upgrade a package and its database objects.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)