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)
相关推荐
小p10 小时前
docker学习: 2. 构建镜像Dockerfile
docker
小p1 天前
docker学习: 1. docker基本使用
docker
蝎子莱莱爱打怪1 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀1 天前
Docker部署Nacos
docker·容器
缓解AI焦虑1 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
1candobetter2 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka
DianSan_ERP2 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
シ風箏2 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
呉師傅2 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒2 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器