第五期L1 第11课 使用Docker运行PostgreSQL数据库
执行到 make 这一步时报错如下:
Turn off this advice by setting config variable advice.detachedHead to false
# cd pgvector
# make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/usr/include/postgresql/17/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -c -o src/bitutils.o src/bitutils.c
src/bitutils.c:1:10: fatal error: postgres.h: No such file or directory
1 | #include "postgres.h"
| ^~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: src/bitutils.o] Error 1
# ls
CHANGELOG.md Dockerfile LICENSE Makefile Makefile.win META.json README.md sql src test vector.control
这个编译错误表明缺少 PostgreSQL 开发头文件postgres.h
AI给了这么多处理步骤,实际操作还是不行:
路径不匹配:编译器在 /usr/include/postgresql/17/server
查找头文件,但您的系统可能安装在不同位置
解决方案
第一步:安装 PostgreSQL 开发包
根据您的系统选择命令:
# Ubuntu/Debian 系统sudo apt updatesudo apt install -y postgresql-server-dev-17# CentOS/RHEL 系统sudo yum install -y postgresql17-devel# Alpine Linuxsudo apk add postgresql17-dev
第二步:确认头文件位置
# 查找 postgres.h 文件位置sudo find / -name postgres.h 2>/dev/null# 示例输出可能为:# /usr/include/postgresql/14/server/postgres.h# /usr/include/postgresql/15/server/postgres.h# /usr/include/postgresql/17/server/postgres.h
第三步:设置正确的包含路径
在 pgvector 目录中执行:
# 如果找到的是 17 版本make PG_CONFIG=/usr/lib/postgresql/17/bin/pg_config# 如果找到的是其他版本(如 15)make PG_CONFIG=/usr/lib/postgresql/15/bin/pg_config
第四步:如果版本不匹配,指定路径
# 手动指定包含路径make INCLUDEDIR=/usr/include/postgresql/17/server
完整安装流程
# 1. 安装依赖sudo apt install -y postgresql-server-dev-17 build-essential git# 2. 克隆仓库git clone --branch v0.7.0 https://github.com/pgvector/pgvector.gitcd pgvector# 3. 编译安装makesudo make install# 4. 在 PostgreSQL 中启用扩展sudo -u postgres psql -c "CREATE EXTENSION vector;"
麻烦老师或者各位大佬帮忙解答一下可以吗?