OpenTenBase 是 企业级分布式数据库 TDSQL 的社区发行版,包含 OpenTenBase 和 TXSQL 双内核,具备高扩展性、商业数据库语法兼容、分布式引擎、多级容灾和多维度资源隔离等能力,成功应用在金融、医疗、航天等行业的核心业务系统。
近日,OpenTenBase 5.0 新版本发布,详情:OpenTenBase 5.0 与 TXSQL 8.0.30 重磅升级:双引擎齐进化,迈向新一代企业级数据库
依托 PostgreSQL 生态在 AI 领域的天然优势,OpenTenBase 5.0 强势布局多模态分析,打造“结构化 + 半结构化 + 非结构化”全数据类型处理能力:
OpenTenBase 5.0 的 opentenbase_ai 插件为 PostgreSQL 数据库提供了集成人工智能大语言模型能力的接口,让您能够直接在 SQL 中使用 AI 功能。该插件支持多种 AI 模型提供商(包括 OpenAI、DeepSeek、腾讯混元、阿里通义千问等),提供文本生成、翻译、情感分析、问答提取、文本摘要、嵌入向量生成以及图像分析等功能。
★阅读下面的内容需要一点 Linux 和 PostgreSQL 基础。坐等官方 RPM 包上线 OpenCloudOS 的仓库。
之前的文章 手把手教你在 OpenCloudOS 上部署 OpenTenBase 数据库 介绍过源码编译 OpenTenBase v2.6。本文将介绍如何在 OpenCloudOS 操作系统上编译 OpenTenBase v5.0。
本文实验环境为 OpenCloudOS 8.10 操作系统,查看系统信息如下。
[shawnyan@oc8 ~]$ hostnamectl
Static hostname: oc8.shawnyan.cn
Operating System: OpenCloudOS 8.10
Kernel: Linux 5.4.241-30.0017.19
Architecture: x86-64
[shawnyan@oc8 ~]$除了 OpenTenBase 2.6 所需的依赖包,OpenTenBase 5.0 还需安装以下依赖。
编译安装 zstd 和 lz4,参阅:https://github.com/OpenTenBase/OpenTenBase/issues/166
[root@oc8 ~]# git clone https://github.com/facebook/zstd.git --depth=1
Cloning into 'zstd'...
remote: Enumerating objects: 64644, done.
remote: Counting objects: 100% (143/143), done.
remote: Compressing objects: 100% (77/77), done.
remote: Total 64644 (delta 91), reused 72 (delta 66), pack-reused 64501 (from 4)
Receiving objects: 100% (64644/64644), 39.45 MiB | 2.84 MiB/s, done.
Resolving deltas: 100% (48338/48338), done.
[root@oc8 ~]# cd zstd
[root@oc8 zstd]# make -j$(nproc)
make[1]: Entering directory '/root/zstd/lib'
make[1]: Entering directory '/root/zstd/programs'
creating pkgconfig
...
zstd build completed
compiling multi-threaded dynamic library 1.5.8
creating versioned links
release build completed
make[1]: Leaving directory '/root/zstd/lib'
[root@oc8 zstd]# make install
make[1]: Entering directory '/root/zstd/lib'
creating pkgconfig
Installing static library
Installing shared library
Installing includes
zstd static and shared library installed
make[1]: Leaving directory '/root/zstd/lib'
make[1]: Entering directory '/root/zstd/programs'
Installing binaries
Installing man pages
zstd installation completed
make[1]: Leaving directory '/root/zstd/programs'
[root@oc8 zstd]#
[root@oc8 ~]# git clone https://github.com/lz4/lz4.git
Cloning into 'lz4'...
remote: Enumerating objects: 17541, done.
remote: Counting objects: 100% (878/878), done.
remote: Compressing objects: 100% (377/377), done.
remote: Total 17541 (delta 626), reused 513 (delta 501), pack-reused 16663 (from 2)
Receiving objects: 100% (17541/17541), 7.00 MiB | 2.29 MiB/s, done.
Resolving deltas: 100% (12067/12067), done.
[root@oc8 ~]# cd lz4
[root@oc8 lz4]# make -j$(nproc)
creating pkgconfig
...
liblz4.so.1.10.0 created
LD cachedObjs/d899e3357a27def6ef4a116bc839409e/lz4
==> built with multithreading support
lz4 build completed
[root@oc8 lz4]# make install
Installing libraries in /usr/local/lib
Installing headers in /usr/local/include
lz4 libraries installed
Installing binaries in /usr/local/bin
Installing man pages in /usr/local/share/man/man1
lz4 installation completed
[root@oc8 lz4]# 如未安装会遇到报错。
checking for ZSTD_compress in -lzstd... no
configure: error: zstd library not found.
checking for LZ4_compress_default in -llz4... no
configure: error: lz4 library not found.使用 dnf 命令安装 xml2。
dnf install libxml2-devel libcurl-devel 如未安装会遇到报错。
checking for xmlSaveToBuffer in -lxml2... no
configure: error: library 'xml2' (version >= 2.6.23) is required for XML support使用 dnf 命令安装依赖。
dnf install cmake libxslt-devel openldap-devel perl-IPC-Run perl-Test-Simple python36-devel tcl-devel
dnf install -y epel-release
dnf install -y libssh2-devellibpqxx 是开源关系数据库 PostgreSQL 的官方 C++ 客户端 API。
dnf install postgresql-devel
wget https://github.com/jtv/libpqxx/archive/refs/tags/6.4.8.zip
unzip 6.4.8.zip && cd 6.4.8
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
make install如未安装会遇到报错。
src/node/node.h:4:10: fatal error: pqxx/pqxx: No such file or directory也不能在 OC 8 上安装 libpqxx 7,因为 gcc 版本不够高。
[root@oc8 libpqxx-master]# gcc -dM -E - < /dev/null | grep __STDC_VERSION__ | awk '{ print $2 " --> " $3 }'
__STDC_VERSION__ --> 201710L上面命令返回 __STDC_VERSION__ --> 201710L 意味着当前使用 2017 C standard(c17)。
准备工作做好那我们的进度就完成了 80%,接下来的编译安装就和 PostgreSQL 一样简单了。
export SOURCECODE_PATH=/data/opentenbase/OpenTenBase
export INSTALL_PATH=/data/opentenbase/install/
cd ${SOURCECODE_PATH}
./configure --prefix=${INSTALL_PATH}/opentenbase_bin_v5.0 --enable-user-switch --with-libxml --disable-license --with-openssl --with-ossp-uuid CFLAGS="-g"
make
make install继续编译扩展。
cd contrib
make
make install到此,编译步骤完成。
vi ~/.bashrc
export OPENTENBASE_HOME=/data/opentenbase/install/opentenbase_bin_v5.0
export PGDATA=/data/opentenbase/data
export PATH=$OPENTENBASE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$OPENTENBASE_HOME/lib:${LD_LIBRARY_PATH}
export LC_ALL=C
source ~/.bashrcpostgres -V
initdb -V输出结果一致。
[opentenbase@oc8 ~]$ pg_ctl -V
pg_ctl (PostgreSQL) 10.0 @ OpenTenBase_v5.0 OpenTenBase V5.21 2025-09-25 19:49:18
[opentenbase@oc8 ~]$ 这里我们安装单实例对数据库进行初始化。
initdb --nodename=dn1 --nodetype=datanode启动之前修改服务器参数。
# 集中式开关
is_centralized_mode = on
# DN 可写
allow_dml_on_datanode = onpg_ctl -Z datanode start到此,OpenTenBase 已启动成功。
接下来,我们可以开始体验 OpenTenBase 5.0 新增的 AI 功能。
postgres=# create node dn1 with(TYPE='datanode',HOST='127.0.0.1',PORT=5432,PRIMARY='TRUE',PREFERRED='TRUE');
CREATE NODE
postgres=# create default node group default_group with (dn1);
CREATE NODE GROUP
postgres=#安装 opentenbase_ai 扩展前,需要先安装 plpgsql 和 http 两个扩展。
postgres=# CREATE EXTENSION plpgsql;
CREATE EXTENSION
postgres=# CREATE EXTENSION opentenbase_ai CASCADE;
NOTICE: (00000) installing required extension "http"
CREATE EXTENSION
postgres=#
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
----------------+---------+------------+----------------------------------------------------------------------------
http | 1.7 | public | HTTP client for PostgreSQL, allows web page retrieval inside the database.
opentenbase_ai | 1.0 | public |
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(3 rows)
postgres=#添加混元大模型的模型定义到模型元数据表中。
SELECT ai.add_completion_model(
model_name => 'hunyuan_chat',
uri => 'https://api.hunyuan.cloud.tencent.com/v1/chat/completions',
default_args => '{"model": "hunyuan-lite"}'::jsonb,
token => 'your_hunyuan_api_key',
model_provider => 'tencent'
);配置混元大模型为默认模型。
SET ai.completion_model = 'hunyuan_chat';关于 opentenbase_ai 特性的更多用法,请参照文档:
https://docs.opentenbase.org/guide/23-opentenbase_ai/
OpenTenBase 5.0 在 OpenCloudOS 上的完整编译与部署流程可概括为“依赖补齐 → 源码构建 → 集群初始化 → 集群启动”四步。只要提前装好诸多新增依赖,即可像常规 PostgreSQL 一样快速完成安装,OpenTenBase 还提供了 opentenbase_ctl 便于集群管理。新版本增加的 opentenbase_ai 插件,能在 SQL 里直接调用腾讯混元等主流大模型,实现智能检索与分析,强烈推荐大家来试用。

Have a nice day ~ ☕
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。