✅ 宝塔 PostgreSQL 安装UUID指南

😊补充:没有安装成功 的扩展

如果你在使用springAI中检索事增强RAG在自动或者手动创建数据库的时候报错如下:主要信息

#error "please use configure's --with-uuid switch to select a UUID library"

你遇到的错误非常典型: 因为 uuid-ossp 扩展依赖系统上的 UUID 库 (如 libuuidOSSP UUID)在 ✅ 宝塔 PostgreSQL 安装 contrib 扩展完整指南 中没有安装成功。

根据原始编译参数并执行 #configure 中没有指定 没有指定 --with-uuid 参数,导致编译器不知道用哪个 UUID 实现。


✅ 正确解决方案

你需要 重新配置 PostgreSQL 源码,并启用对 UUID 库的支持。

在PotgreSQL中创建uuid-ossp

bash 复制代码
 CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

安装失败

第一步:确认系统是否安装了 UUID 开发库

对于 OpenCloudOS / CentOS 系列:
bash 复制代码
# 安装 libuuid 开发包(通常来自 util-linux)
yum install -y libuuid-devel
# 或(某些版本叫)
dnf install -y libuuid-devel

💡 uuid-ossp 在现代 PostgreSQL 中默认使用 libuuid(来自 util-linux) ,而不是老式的 ossp-uuid

验证是否安装成功:

bash 复制代码
ls /usr/include/uuid/uuid.h

如果存在,说明开发头文件已就位。


第二步:回到 PostgreSQL 源码根目录,重新 configure

bash 复制代码
cd /tmp/postgresql-16.1

先清理旧配置(可选):如果提示命令不存在,跳过即可

bash 复制代码
make distclean   

然后重新运行 configure加上 --with-uuid=bsd--with-uuid=e2fs

✅ 在大多数 Linux 发行版(包括 OpenCloudOS/CentOS)中,应使用:

bash 复制代码
./configure \
  --prefix=/www/server/pgsql \
  --without-readline \
  --with-uuid=e2fs

📌 说明:

  • e2fs 表示使用 libuuid(由 util-linux 提供,即 libuuid-devel 安装的内容)

  • 不要使用 --with-uuid=ossp,除非你手动安装了 ossp-uuid(不推荐)


第三步:编译 uuid-ossp

bash 复制代码
cd contrib/uuid-ossp
make clean
make
make install

注意如果没有安装yum install -y libuuid-devel的话会报错

root@VM-4-5-opencloudos contrib# cd uuid-ossp/

root@VM-4-5-opencloudos uuid-ossp# 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 -O2 -fPIC -fvisibility=hidden -I. -I. -I../../src/include -D_GNU_SOURCE -c -o uuid-ossp.o uuid-ossp.c uuid-ossp.c:40:2: error: #error "please use configure's --with-uuid switch to select a UUID library" 40 | #error "please use configure's --with-uuid switch to select a UUID library" | ^~~~~ uuid-ossp.c: In function 'uuid_generate_internal': uuid-ossp.c:275:33: error: unknown type name 'uuid_t'; did you mean 'uid_t'? 275 | uuid_t uu; | ^~~~~~ | uid_t uuid-ossp.c:276:58: error: 'uuid_s_ok' undeclared (first use in this function); did you mean 'uuid_ns_oid'? 276 | uint32_t status = uuid_s_ok; | ^~~~~~~~~ | uuid_ns_oid uuid-ossp.c:276:58: note: each undeclared identifier is reported only once for each function it appears in uuid-ossp.c:279:33: warning: implicit declaration of function 'uuid_create'; did you mean 'uuid_recv'? -Wimplicit-function-declaration 279 | uuid_create(&uu, &status); | ^~~~~~~~~~~ | uuid_recv uuid-ossp.c:283:41: warning: implicit declaration of function 'uuid_to_string'; did you mean 'text_to_cstring'? -Wimplicit-function-declaration 283 | uuid_to_string(&uu, &str, &status); | ^~~~~~~~~~~~~~ | text_to_cstring uuid-ossp.c:75:20: error: unknown type name 'uuid_t'; did you mean 'uid_t'? 75 | #define dce_uuid_t uuid_t | ^~~~~~ uuid-ossp.c:323:33: note: in expansion of macro 'dce_uuid_t' 323 | dce_uuid_t uu; | ^~~~~~~~~~ uuid-ossp.c:83:11: error: request for member 'time_low' in something not a structure or union 83 | uu.time_low = pg_hton32(uu.time_low); \ | ^ uuid-ossp.c:368:33: note: in expansion of macro 'UUID_TO_NETWORK' 368 | UUID_TO_NETWORK(uu); | ^~~~~~~~~~~~~~~ In file included from uuid-ossp.c:19: uuid-ossp.c:83:35: error: request for member 'time_low' in something not a structure or union 83 | uu.time_low = pg_hton32(uu.time_low); \ | ^ ../../src/include/port/pg_bswap.h:55:41: note: in definition of macro 'pg_bswap32' 55 | #define pg_bswap32(x) __builtin_bswap32(x) | ^ uuid-ossp.c:83:23: note: in expansion of macro 'pg_hton32' 83 | uu.time_low = pg_hton32(uu.time_low); \ | ^~~~~~~~~ uuid-ossp.c:368:33: note: in expansion of macro 'UUID_TO_NETWORK' 368 | UUID_TO_NETWORK(uu); | ^~~~~~~~~~~~~~~ uuid-ossp.c:84:11: error: request for member 'time_mid' in something not a structure or union 84 | uu.time_mid = pg_hton16(uu.time_mid); \ | ^ uuid-ossp.c:368:33: note: in expansion of macro 'UUID_TO_NETWORK' 368 | UUID_TO_NETWORK(uu); | ^~~~~~~~~~~~~~~ uuid-ossp.c:84:35: error: request for member 'time_mid' in something not a structure or union 84 | uu.time_mid = pg_hton16(uu.time_mid); \ | ^

成功标志如下

make

make install


第四步:验证并启用扩展

检查文件是否存在

bash 复制代码
ls /www/server/pgsql/share/extension/uuid-ossp.control
ls /www/server/pgsql/lib/uuid-ossp.so

进入数据库:

bash 复制代码
psql -U postgres -d ai_rag
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

❓为什么 hstore 能编译,而 uuid-ossp 不能?

  • hstore 是纯 C 实现,无外部依赖

  • uuid-ossp 需要调用系统 UUID 生成函数,必须链接 libuuid ,因此必须在 configure 时声明。

相关推荐
程序员小八77712 小时前
MySQL 事务:一文把 ACID、隔离级别、MVCC、锁全串起来
数据库·mysql
lzhdim12 小时前
提高 SQL 语句执行速度的方法
java·开发语言·数据库·sql·oracle
ltl13 小时前
ClickHouse Distributed 引擎与分布式查询路由
数据库
Wang's Blog13 小时前
PostgreSQL笔记60: 权限与角色管理——从层级体系到最佳实践
数据库·笔记·postgresql
whcyhhh14 小时前
头歌实践教学平台:大数据存储2023(六)
大数据·数据库·python
Elastic 中国社区官方博客15 小时前
让大模型思考,让小模型执行:在 Elastic Workflows 中拆分 LLM 成本
大数据·运维·数据库·人工智能·elasticsearch·ai
Faith_xzc15 小时前
一条 SQL 顶一条 Flink 链路?Doris Streaming Job 持续导入全景解析
大数据·数据库·sql·flink
这个DBA有点耶18 小时前
多模数据库深度解读:从“多库拼装”到“一库多能”的架构演进
数据库·mysql·dba
程序员夏洛18 小时前
MySQL 默认的事务隔离级别是什么?为什么选择这个级别?
数据库·mysql
Wang's Blog19 小时前
PostgreSQL笔记28: PostgreSQL ACID 特性与实现机制深度解析
大数据·笔记·postgresql