pg_bigm

create 2-gram (bigram) index for faster full text search.

Overview

PackageVersionCategoryLicenseLanguage
pg_bigm1.2FTSPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
2120pg_bigmNoYesNoYesNoYes-
Relatedpg_search pgroonga zhparser pg_trgm pgroonga_database pg_tokenizer fuzzystrmatch rum

Version

TypeRepoVersionPG VerPackageDeps
EXTMIXED1.21817161514pg_bigm-
RPMPGDG1.21817161514pg_bigm_$v-
DEBPIGSTY1.21817161514postgresql-$v-pg-bigm-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Build

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

pig build pkg pg_bigm         # build RPM / DEB packages

Install

You can install pg_bigm 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_bigm;          # Install for current active PG version
pig ext install -y pg_bigm -v 18  # PG 18
pig ext install -y pg_bigm -v 17  # PG 17
pig ext install -y pg_bigm -v 16  # PG 16
pig ext install -y pg_bigm -v 15  # PG 15
pig ext install -y pg_bigm -v 14  # PG 14
dnf install -y pg_bigm_18       # PG 18
dnf install -y pg_bigm_17       # PG 17
dnf install -y pg_bigm_16       # PG 16
dnf install -y pg_bigm_15       # PG 15
dnf install -y pg_bigm_14       # PG 14
apt install -y postgresql-18-pg-bigm   # PG 18
apt install -y postgresql-17-pg-bigm   # PG 17
apt install -y postgresql-16-pg-bigm   # PG 16
apt install -y postgresql-15-pg-bigm   # PG 15
apt install -y postgresql-14-pg-bigm   # PG 14

Create Extension:

CREATE EXTENSION pg_bigm;

Usage

pg_bigm Documentation | GitHub: pgbigm/pg_bigm

The pg_bigm module provides full text search capability in PostgreSQL. This module allows a user to create 2-gram (bigram) index for faster full text search.

pg_bigm is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.

Features

  • Bigram indexing: Creates 2-gram (bigram) GIN indexes for text columns
  • Faster LIKE searches: Accelerates LIKE queries including prefix, suffix, and substring searches
  • All language support: Works with any language including CJK (Chinese, Japanese, Korean) without additional configuration
  • Simple API: Provides similarity search functions and operators

Functions and Operators

Functions

FunctionReturn TypeDescription
likequery(text)textGenerates a search query for full text search from a keyword
show_bigm(text)text[]Shows all 2-grams in the given string
pg_gin_pending_stats(regclass)recordReturns the number of pages and tuples in the pending list of a GIN index

Operators

OperatorDescription
text =% textReturns true if the similarity between the left and right operands is greater than or equal to pg_bigm.similarity_limit

GUC Parameters

ParameterTypeDefaultDescription
pg_bigm.last_updatetext-Shows the last update date of the module (read-only)
pg_bigm.enable_recheckboolonControls whether recheck is performed during index scan
pg_bigm.gin_key_limitint0Limits the maximum number of bigrams used for full text search. 0 means no limit
pg_bigm.similarity_limitreal0.3Sets the minimum similarity threshold for the =% operator

Examples

-- Create extension
CREATE EXTENSION pg_bigm;

-- Create a table with text data
CREATE TABLE documents (id serial PRIMARY KEY, content text);
INSERT INTO documents (content) VALUES
  ('PostgreSQL is a powerful database'),
  ('Full text search with bigram indexing'),
  ('Japanese text: 日本語テキスト検索');

-- Create a bigram index
CREATE INDEX docs_bigm_idx ON documents USING gin (content gin_bigm_ops);

-- Search using LIKE
SELECT * FROM documents WHERE content LIKE '%search%';

-- Search using likequery function
SELECT * FROM documents WHERE content LIKE likequery('database');
-- Show bigrams for a string
SELECT show_bigm('PostgreSQL');

-- Similarity search
SET pg_bigm.similarity_limit = 0.2;
SELECT * FROM documents WHERE content =% 'database search';

Comparison with pg_trgm

pg_bigm has the following advantages over the built-in pg_trgm:

Featurepg_bigmpg_trgm
N-gram type2-gram (bigram)3-gram (trigram)
Minimum search string1 character3 characters
Non-alphabetic languagesFull supportLimited support
LIKE search typesPrefix, suffix, and substringPrefix, suffix, and substring

For detailed documentation including advanced usage and performance tuning, see the official pg_bigm documentation.


Last Modified 2026-03-12: add pg extension catalog (95749bf)