You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL中vector扩展缺失及pgvector编译报错求助

PostgreSQL vector扩展安装问题解决方案

一、优先使用包管理器安装(规避编译错误)

Ubuntu/Debian

  1. 添加pgvector官方仓库:
    curl -fsSL https://packages.timescale.com/install.sh | sudo bash
    sudo apt update
    
  2. 安装对应PostgreSQL版本的pgvector:
    sudo apt install postgresql-15-pgvector  # 将15替换为你的PostgreSQL主版本号
    

CentOS/RHEL

  1. 添加Timescale YUM仓库:
    sudo tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
    [timescale_timescaledb]
    name=timescale_timescaledb
    baseurl=https://packagecloud.io/timescale/timescaledb/el/8/\$basearch
    repo_gpgcheck=1
    gpgcheck=0
    enabled=1
    gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    EOL
    
  2. 安装对应版本的pgvector:
    sudo yum install pgvector_15  # 将15替换为你的PostgreSQL版本号
    

macOS(Homebrew)

brew install pgvector

二、手动编译安装(解决编译报错)

1. 安装PostgreSQL开发依赖

  • Ubuntu/Debian:
    sudo apt install postgresql-server-dev-15 build-essential  # 替换版本号为你的PostgreSQL版本
    
  • CentOS/RHEL:
    sudo yum install postgresql15-devel gcc make  # 替换版本号为你的PostgreSQL版本
    
  • macOS:
    brew install postgresql@15  # 确保安装对应版本的PostgreSQL开发包
    

2. 解决pgxs.mk找不到的问题

编译时指定PGXS路径(先找到路径再替换):

# 查找pgxs.mk的位置
find / -name pgxs.mk 2>/dev/null
# 示例编译命令,替换为实际找到的路径
make PGXS=/usr/lib/postgresql/15/lib/pgxs/src/makefiles/pgxs.mk
sudo make PGXS=/usr/lib/postgresql/15/lib/pgxs/src/makefiles/pgxs.mk install

3. 解决uname进程创建失败问题

确保uname命令可用:

# 检查uname是否存在
which uname
# 若不存在则安装coreutils
# Ubuntu/Debian
sudo apt install coreutils
# CentOS/RHEL
sudo yum install coreutils

三、验证安装并启用扩展

  1. 连接到目标数据库:
    psql -d vector_db -U postgres
    
  2. 创建vector扩展:
    CREATE EXTENSION IF NOT EXISTS vector;
    
  3. 验证安装结果:
    SELECT * FROM pg_extension WHERE extname = 'vector';
    

四、代码补充修改

在创建数据库的代码后,添加启用vector扩展的逻辑:

# 创建数据库后新增这段代码
conn_db = psycopg2.connect(f"{connection_string}/{db_name}")
conn_db.autocommit = True
with conn_db.cursor() as c:
    c.execute("CREATE EXTENSION IF NOT EXISTS vector;")
conn_db.close()

内容的提问来源于stack exchange,提问作者Fatima Fatima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 01:28:09