pg_bigm
pg_bigm
pg_bigm : create 2-gram (bigram) index for faster full text search.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2120 | pg_bigm | pg_bigm | 1.2 | FTS | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_search pgroonga zhparser pg_trgm pgroonga_database pg_tokenizer fuzzystrmatch rum |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 1.2 | 18 17 16 15 14 | pg_bigm | - |
| RPM | PGDG | 1.2 | 18 17 16 15 14 | pg_bigm_$v | - |
| DEB | PIGSTY | 1.2 | 18 17 16 15 14 | postgresql-$v-pg-bigm | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
el8.aarch64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
el9.x86_64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
el9.aarch64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
el10.x86_64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
el10.aarch64 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 | PGDG 1.2 |
d12.x86_64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
d12.aarch64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
d13.x86_64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
d13.aarch64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
u22.x86_64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
u22.aarch64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
u24.x86_64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
u24.aarch64 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 | PIGSTY 1.2 |
Source
pig build pkg pg_bigm; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_bigm; # install via package name, for the active PG version
pig install pg_bigm -v 18; # install for PG 18
pig install pg_bigm -v 17; # install for PG 17
pig install pg_bigm -v 16; # install for PG 16
pig install pg_bigm -v 15; # install for PG 15
pig install pg_bigm -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_bigm';Create this extension with:
CREATE EXTENSION pg_bigm;Usage
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
LIKEqueries 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
| Function | Return Type | Description |
|---|---|---|
likequery(text) | text | Generates 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) | record | Returns the number of pages and tuples in the pending list of a GIN index |
Operators
| Operator | Description |
|---|---|
text =% text | Returns true if the similarity between the left and right operands is greater than or equal to pg_bigm.similarity_limit |
GUC Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
pg_bigm.last_update | text | - | Shows the last update date of the module (read-only) |
pg_bigm.enable_recheck | bool | on | Controls whether recheck is performed during index scan |
pg_bigm.gin_key_limit | int | 0 | Limits the maximum number of bigrams used for full text search. 0 means no limit |
pg_bigm.similarity_limit | real | 0.3 | Sets the minimum similarity threshold for the =% operator |
Examples
Basic Full Text Search
-- 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');Similarity Search
-- 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:
| Feature | pg_bigm | pg_trgm |
|---|---|---|
| N-gram type | 2-gram (bigram) | 3-gram (trigram) |
| Minimum search string | 1 character | 3 characters |
| Non-alphabetic languages | Full support | Limited support |
| LIKE search types | Prefix, suffix, and substring | Prefix, suffix, and substring |
For detailed documentation including advanced usage and performance tuning, see the official pg_bigm documentation.
Last updated on