Skip to content

pg_fts

Full-text search with BM25 and BM25F ranking

pg_fts : Full-text search with BM25 and BM25F ranking

Overview

ID Extension Package Version Category License Language
2230 pg_fts pg_fts 1.14.1 FTS PostgreSQL C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-dtr No Yes No Yes yes yes
PG17-18; trusted and relocatable.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 1.14.1 18 17 16 15 14 pg_fts -
RPM PIGSTY 1.14.1 18 17 16 15 14 pg_fts_$v -
DEB PIGSTY 1.14.1 18 17 16 15 14 postgresql-$v-pg-fts -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
el8.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
el9.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
el9.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
el10.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
el10.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
d12.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
d12.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
d13.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
d13.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u22.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u22.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u24.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u24.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u26.x86_64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
u26.aarch64 PIGSTY 1.14.1 PIGSTY 1.14.1 N/A N/A N/A
Package Version OS ORG SIZE File URL
pg_fts_18 1.14.1 el8.x86_64 pigsty 574.9 KiB pg_fts_18-1.14.1-1PGSTY.el8.x86_64.rpm
pg_fts_18 1.14.1 el8.aarch64 pigsty 562.8 KiB pg_fts_18-1.14.1-1PGSTY.el8.aarch64.rpm
pg_fts_18 1.14.1 el9.x86_64 pigsty 548.0 KiB pg_fts_18-1.14.1-1PGSTY.el9.x86_64.rpm
pg_fts_18 1.14.1 el9.aarch64 pigsty 543.1 KiB pg_fts_18-1.14.1-1PGSTY.el9.aarch64.rpm
pg_fts_18 1.14.1 el10.x86_64 pigsty 555.3 KiB pg_fts_18-1.14.1-1PGSTY.el10.x86_64.rpm
pg_fts_18 1.14.1 el10.aarch64 pigsty 547.1 KiB pg_fts_18-1.14.1-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-fts 1.14.1 d12.x86_64 pigsty 558.4 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-fts 1.14.1 d12.aarch64 pigsty 544.8 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-fts 1.14.1 d13.x86_64 pigsty 561.0 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~trixie_amd64.deb
postgresql-18-pg-fts 1.14.1 d13.aarch64 pigsty 548.0 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~trixie_arm64.deb
postgresql-18-pg-fts 1.14.1 u22.x86_64 pigsty 578.9 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~jammy_amd64.deb
postgresql-18-pg-fts 1.14.1 u22.aarch64 pigsty 572.3 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~jammy_arm64.deb
postgresql-18-pg-fts 1.14.1 u24.x86_64 pigsty 557.2 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~noble_amd64.deb
postgresql-18-pg-fts 1.14.1 u24.aarch64 pigsty 552.1 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~noble_arm64.deb
postgresql-18-pg-fts 1.14.1 u26.x86_64 pigsty 553.6 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~resolute_amd64.deb
postgresql-18-pg-fts 1.14.1 u26.aarch64 pigsty 546.3 KiB postgresql-18-pg-fts_1.14.1-1PGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_fts_17 1.14.1 el8.x86_64 pigsty 575.0 KiB pg_fts_17-1.14.1-1PGSTY.el8.x86_64.rpm
pg_fts_17 1.14.1 el8.aarch64 pigsty 562.8 KiB pg_fts_17-1.14.1-1PGSTY.el8.aarch64.rpm
pg_fts_17 1.14.1 el9.x86_64 pigsty 548.1 KiB pg_fts_17-1.14.1-1PGSTY.el9.x86_64.rpm
pg_fts_17 1.14.1 el9.aarch64 pigsty 542.9 KiB pg_fts_17-1.14.1-1PGSTY.el9.aarch64.rpm
pg_fts_17 1.14.1 el10.x86_64 pigsty 555.1 KiB pg_fts_17-1.14.1-1PGSTY.el10.x86_64.rpm
pg_fts_17 1.14.1 el10.aarch64 pigsty 547.1 KiB pg_fts_17-1.14.1-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-fts 1.14.1 d12.x86_64 pigsty 558.6 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-fts 1.14.1 d12.aarch64 pigsty 544.5 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-fts 1.14.1 d13.x86_64 pigsty 560.9 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~trixie_amd64.deb
postgresql-17-pg-fts 1.14.1 d13.aarch64 pigsty 547.9 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~trixie_arm64.deb
postgresql-17-pg-fts 1.14.1 u22.x86_64 pigsty 609.1 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~jammy_amd64.deb
postgresql-17-pg-fts 1.14.1 u22.aarch64 pigsty 600.2 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~jammy_arm64.deb
postgresql-17-pg-fts 1.14.1 u24.x86_64 pigsty 557.1 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~noble_amd64.deb
postgresql-17-pg-fts 1.14.1 u24.aarch64 pigsty 551.9 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~noble_arm64.deb
postgresql-17-pg-fts 1.14.1 u26.x86_64 pigsty 553.7 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~resolute_amd64.deb
postgresql-17-pg-fts 1.14.1 u26.aarch64 pigsty 546.2 KiB postgresql-17-pg-fts_1.14.1-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_fts;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_fts;		# install via package name, for the active PG version

pig install pg_fts -v 18;   # install for PG 18
pig install pg_fts -v 17;   # install for PG 17

Create this extension with:

CREATE EXTENSION pg_fts;

Usage

Sources:

pg_fts 1.14.1 provides full-text search with BM25/BM25F ranking and the dedicated fts inverted index. PostgreSQL 17 and 18 are supported; PostgreSQL 19/master CI is best-effort. The control is trusted and relocatable, and core use needs no shared preload.

Search and Rank

CREATE EXTENSION pg_fts;
CREATE TABLE docs (id bigint, body text);
CREATE INDEX docs_fts ON docs USING fts (to_ftsdoc('english', body));
SELECT id FROM docs
 WHERE to_ftsdoc('english', body) @@@ to_ftsquery('english', 'quick fox')
 ORDER BY to_ftsdoc('english', body) <=> to_ftsquery('english', 'quick fox')
 LIMIT 10;
SELECT fts_merge('docs_fts');
SELECT fts_vacuum('docs_fts');

Objects and Queries

ftsdoc and ftsquery represent analyzed documents and queries. to_ftsdoc() and to_ftsquery() construct them; @@@ matches documents and <=> orders relevance distance. The match predicate is required for an indexed KNN ordering scan. Queries support boolean terms, phrases, prefix, fuzzy and regular-expression matching. Multi-column documents support BM25F field weighting. fts_count() and ordinary count queries can use exact index counting; fts_search() exposes direct ranked results. Regex/long-fuzzy acceleration is opt-in through trigrams = on.

Maintenance and Privileges

Pending inserts are immediately searchable; merging is not a visibility prerequisite. fts_merge() compacts segments and fts_vacuum() reclaims physical space. Both write WAL, require index ownership and must run on a primary. Large pending documents can temporarily consume substantial space, so merge and reclaim periodically during bulk ingestion. fts_search() and fts_anomalous_docs() expose indexed content and are revoked from PUBLIC by default; widen access only deliberately. Regular table-query visibility and direct helper access are different permission surfaces.

Upgrade to 1.10.0

After installing matching files, run ALTER EXTENSION pg_fts UPDATE TO '1.10.0'. Version 1.10.0 shares each segment’s document-length array across backends by default and adds fts_shared_doclen_stats() to inspect the shared cache. A superuser can change pg_fts.shared_doclen; unavailable shared memory falls back to a private copy. There is no on-disk format change and no REINDEX requirement. Earlier delete-ranking and posting-block fixes remain included; distinguish shared-cache memory from fallback per-backend copies when planning capacity.

Version 1.11.0

Version 1.11.0 fixes wrong-result cases and concurrent insert/VACUUM/merge failures. Ranked traversal uses best-first block ordering; pg_fts.bestfirst defaults on. The index format is unchanged and the SQL upgrade adds no objects. REINDEX is not required merely to upgrade, but it repairs index entries already left or lost by the earlier bugs.

Version 1.12.0

Version 1.12.0 caches the segment dictionary index in each backend, charging it against pg_fts.doclen_cache_mb; a segment that does not fit falls back to the page-chain lookup. Changes to that budget now take effect without waiting for a segment-directory change. There is no index-format change, no new SQL object and no REINDEX requirement. A cancellation or error during cache reconstruction can leave memory allocated until that backend exits; this known limitation does not change query results.

Compound Proximity and 1.13.0 Fixes

Queries now support unordered w/N, ordered p/N, exact-gap <N>, adjacency <->, and same-position <0>. Either operand can be a term, phrase, OR group or another proximity group; direct AND/NOT operands are rejected. Quoted phrases preserve removed-stopword gaps. Ranked prefix, fuzzy and regex searches now include all matching rows, and pending documents participate in ranking; expansion-only matches can still score zero because scores use literal query terms.

This release fixes malformed binary-query crashes, non-ASCII fuzzy matching and a positional-scan double free during concurrent merges. Install matching files and run ALTER EXTENSION pg_fts UPDATE TO '1.13.0'; no index-format change or routine REINDEX is required.

1.14.0 Vacuum and Write-Load Fixes

Version 1.14.0 bounds posting-list vacuum batches by maintenance_work_mem and skips tail truncation during parallel VACUUM. Deferred free space remains reusable and can be reclaimed by a later non-parallel VACUUM or fts_vacuum(). The new fts_matchsel estimator improves ranked-search plan selection. pg_fts.pending_flush_threshold defaults to 20000 pending documents; 0 disables insert-triggered flushing. The insert path attempts the maintenance lock without waiting.

Install matching files and run ALTER EXTENSION pg_fts UPDATE TO '1.14.0' to rewire the match operators. Index format is unchanged; routine REINDEX is unnecessary.

Counting and Maintenance Fixes in 1.14.1

1.14.1 prevents the exact-count fast path from using partial, invalid or snapshot-ineligible new indexes, and corrects selectivity estimates inflated by pending documents. VACUUM no longer evacuates tail pages when it cannot acquire the truncation lock, avoiding index growth under concurrent readers; bounded memory batches also cover configurations without the document-length sidecar. Install matching files and run ALTER EXTENSION pg_fts UPDATE TO '1.14.1'. The upgrade from 1.14.0 changes neither SQL objects nor index format and needs no routine REINDEX.