docker 方式,postgreSQL18 安装 jieba 分词器扩展

首先用 docker 启动 pgsql 最新版,目前最新版是 18:

shell 复制代码
docker run --name test-postgres \
  --network test-dev-net \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=hcy991002 \
  -p 15432:5432 \
  -v /usr/local/test/dev/postgresql:/var/lib/postgresql \
  --restart always \
  -d postgres:latest

然后按照如下命令来就行了

shell 复制代码
cd /usr/local/pp/dev/jieba_pg_extension

git clone https://github.com/jaiminpan/pg_jieba

# 现在容器内的 /tmp/pg_jieba 就有完整源码. test-postgres 是容器名
docker cp pg_jieba test-postgres:/tmp/

# 进入容器
docker exec -it test-postgres bash

# 更新包列表
apt update

# 安装编译工具和 PostgreSQL 开发头文件
apt install -y build-essential cmake git libpq-dev

# 看 pg_config 是否可用,应该会打印出 pg 版本
pg_config --version

# 安装对应版本的头文件,我的 pgsql 是 18,所以是 poxxxx-dev-18
apt install -y postgresql-server-dev-18

# 进入源码根目录
cd /tmp/pg_jieba

# 初始化子模块
git submodule update --init --recursive

mkdir build && cd build

# 编译,需指定 pg 位置
cmake .. \
  -DPostgreSQL_TYPE_INCLUDE_DIR=$(pg_config --includedir-server) \
  -DPostgreSQL_LIBRARY_DIR=$(pg_config --libdir) \
  -DPostgreSQL_INCLUDE_DIR=$(pg_config --includedir)

make

make install

# 完成 --------

# 测试
psql -U postgres

CREATE EXTENSION pg_jieba;

# 成功使用了扩展
SELECT to_tsvector('jiebacfg', '我在北京中关村上班');
         to_tsvector
------------------------------
 '上班':5 '中关村':4 '北京':3
(1 row)
相关推荐
Mr.朱鹏19 小时前
【Python 进阶 | 第四篇】Psycopg3 + Flask 实现 PostgreSQL CRUD 全流程:从连接池到RESTful接口
python·postgresql·flask·virtualenv·fastapi·pip·tornado
^—app56686619 小时前
游戏运存小启动不起来临时解决方法
运维·服务器
Ujimatsu20 小时前
虚拟机安装Debian 13.x及其常用软件(2026.4)
linux·运维·ubuntu
志栋智能20 小时前
超自动化安全:构建智能安全运营的核心引擎
大数据·运维·服务器·数据库·安全·自动化·产品运营
Edward111111111 天前
4月28日防火墙问题
linux·运维·服务器
小猿姐1 天前
Redis Kubernetes Operator 实测:三个方案的真实差距
redis·容器·kubernetes
米高梅狮子1 天前
08.CronJob和Service
云原生·容器·架构·kubernetes·自动化
想学后端的前端工程师1 天前
【补充内外网突然不通的情况】
运维·服务器
面汤放盐1 天前
何时使用以及何时不应使用微服务:没有银弹
java·运维·云计算
子琦啊1 天前
【算法复习】字符串 | 两个底层直觉,吃透高频题
linux·运维·算法