# Postgres - Install on Redhat 9

\*\*To install the `pgvector` extension\*\* (the popular open-source vector similarity search extension for PostgreSQL, which provides the `vector` data type and operators) on \*\*Red Hat Enterprise Linux (RHEL) 9\*\* with \*\*PostgreSQL 16\*\*, follow these steps.

\*\*`vector.control`\*\* is the control file that comes bundled with the `pgvector` extension — it's not a separate extension. The extension name is simply \*\*`vector`\*\*.

\### Recommended Method: Install via PGDG Repository (Easiest &amp; Recommended)

The official PostgreSQL Yum Repository (PGDG) provides pre-built RPM packages for `pgvector` on RHEL 9.

1\. \*\*Add the official PostgreSQL repository\*\* (if not already added):  
 ```bash  
 sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86\_64/pgdg-redhat-repo-latest.noarch.rpm  
 ```

2\. \*\*Disable the built-in RHEL PostgreSQL module\*\* (to avoid conflicts):  
 ```bash  
 sudo dnf -qy module disable postgresql  
 ```

3\. \*\*Install PostgreSQL 16\*\* (if not already installed):  
 ```bash  
 sudo dnf install -y postgresql16-server postgresql16-devel  
 ```

\- Initialize the database (only if this is a fresh install):  
 ```bash  
 sudo /usr/pgsql-16/bin/postgresql-16-setup initdb  
 sudo systemctl enable --now postgresql-16  
 ```

4\. \*\*Install pgvector for PostgreSQL 16\*\*:  
 ```bash  
 sudo dnf install -y pgvector\_16  
 ```

 This installs the extension files (including `vector.control`, `vector--\*.sql`, and `vector.so`) into the correct PostgreSQL 16 directories.

\### Alternative: Compile from Source (if you prefer or need a specific version)

If the RPM is not available or you want the latest development version:

1\. Install dependencies:  
 ```bash  
 sudo dnf install -y git make gcc postgresql16-devel  
 ```

2\. Clone and build:  
 ```bash  
 cd /tmp  
 git clone --branch v0.8.1 https://github.com/pgvector/pgvector.git  
 cd pgvector  
 make  
 sudo make install  
 ```

 (Use the latest tag from https://github.com/pgvector/pgvector/releases instead of `v0.8.1` if desired.)

\### Enable the Extension in Your Database

1\. Connect to your PostgreSQL 16 database (as superuser):  
 ```bash  
 sudo -u postgres psql  
 ```

 Or connect to a specific database:  
 ```bash  
 psql -U postgres -d your\_database\_name  
 ```

2\. Create the extension (run this in every database where you want to use vectors):  
 ```sql  
 CREATE EXTENSION IF NOT EXISTS vector;  
 ```

3\. Verify it's installed:  
 ```sql  
 \\dx  
 ```

 You should see `vector` listed.

 Or check the version:  
 ```sql  
 SELECT vector\_version();  
 ```

\### Troubleshooting Tips  
\- If you get `could not load library "/usr/pgsql-16/lib/vector.so"`, verify the file exists and has correct permissions.  
\- If using a custom PostgreSQL install, ensure `pg\_config` points to the right version.  
\- For multiple PostgreSQL versions, always use the `\_16` suffix in package names (e.g., `pgvector\_16`).

This should get you up and running with vector support on PostgreSQL 16 on RHEL 9. Let me know if you run into any errors!