pg_jieba

Chinese full-text search parser based on cppjieba

Overview

PackageVersionCategoryLicenseLanguage
pg_jieba1.1.0FTSBSD-3-ClauseC++
IDExtensionBinLibLoadCreateTrustRelocSchema
2240pg_jiebaNoYesNoYesNoYes-
Relatedpg_cjk_parser pgroonga pg_tokenizer zhparser pg_bigm pg_pinyin pg_tiktoken pg_tiktoken_c unaccent dict_xsyn

Package 2.0.1 ships extension version 1.1.0, vendors cppjieba commit 45809955, and fixes the LexDescr terminator allocation.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.01817161514pg_jieba-
RPMPIGSTY2.0.11817161514pg_jieba_$v-
DEBPIGSTY2.0.11817161514postgresql-$v-pg-jieba-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d13.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
d13.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u22.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u22.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u24.x86_64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u24.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
u26.x86_64
u26.aarch64
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1
PIGSTY 2.0.1

Build

You can build the RPM / DEB packages for pg_jieba using pig build:

pig build pkg pg_jieba         # build RPM / DEB packages

Install

You can install pg_jieba directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_jieba;          # Install for current active PG version
pig ext install -y pg_jieba -v 18  # PG 18
pig ext install -y pg_jieba -v 17  # PG 17
pig ext install -y pg_jieba -v 16  # PG 16
pig ext install -y pg_jieba -v 15  # PG 15
pig ext install -y pg_jieba -v 14  # PG 14
dnf install -y pg_jieba_18       # PG 18
dnf install -y pg_jieba_17       # PG 17
dnf install -y pg_jieba_16       # PG 16
dnf install -y pg_jieba_15       # PG 15
dnf install -y pg_jieba_14       # PG 14
apt install -y postgresql-18-pg-jieba   # PG 18
apt install -y postgresql-17-pg-jieba   # PG 17
apt install -y postgresql-16-pg-jieba   # PG 16
apt install -y postgresql-15-pg-jieba   # PG 15
apt install -y postgresql-14-pg-jieba   # PG 14

Create Extension:

CREATE EXTENSION pg_jieba;

Usage

Sources:

pg_jieba adds Jieba-based Chinese word segmentation to PostgreSQL full-text search. The upstream v2.0.1 source release installs SQL extension version 1.1.0, as recorded by its control file. It provides separate document and query parsers plus ready-to-use text-search configurations.

Core Workflow

CREATE EXTENSION pg_jieba;

SELECT to_tsvector(
    'jiebacfg',
    '小明硕士毕业于中国科学院计算所,后在日本京都大学深造'
);

SELECT plainto_tsquery('jiebaqry', '云计算专家');

Use jiebacfg to build searchable document vectors and jiebaqry to segment user queries:

ALTER TABLE articles
ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (to_tsvector('jiebacfg', body)) STORED;

CREATE INDEX articles_search_idx
ON articles USING GIN (search_vector);

SELECT title
FROM articles
WHERE search_vector @@ plainto_tsquery('jiebaqry', '中文全文检索');

Object Index

  • jieba: document text-search parser.
  • jiebaqry: query-oriented text-search parser.
  • jiebacfg: document text-search configuration using jieba and jieba_stem.
  • jiebaqry: text-search configuration of the same name using the query parser.
  • jieba_stem: simple dictionary with Jieba stop words used for the parser’s token categories.

Custom Dictionary and Caveats

Upstream reads a custom dictionary named jieba.user.dict.utf8 from PostgreSQL’s tsearch_data directory. Entries may contain a word and optional part-of-speech tag:

云计算
韩玉鉴赏
蓝翔 nz
  • The v2.x source requires a C++11-capable compiler because of its bundled cppjieba dependency.
  • Upstream’s published compatibility testing is old and limited. Build and regression-test the package against the exact PostgreSQL major version used in production.
  • Changing dictionaries changes tokenization. Recompute stored tsvector values and rebuild dependent indexes when dictionary output changes.

Last Modified: 2026-07-30: extension update 2026-07-30 (7219c44)