pg_tre
pg_tre : Native PostgreSQL index access method for approximate regular-expression matching
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2330 | pg_tre | pg_tre | 4.5.1 |
FTS | MIT AND BSD-2-Clause | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | pg_trgm pg_textsearch pg_fts vector pg_infer pg_mentat |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 4.5.1 |
18 17 16 15 14 | pg_tre |
- |
| RPM | PIGSTY | 4.5.1 |
18 17 16 15 14 | pg_tre_$v |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| el8.aarch64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| el9.x86_64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| el9.aarch64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| el10.x86_64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| el10.aarch64 | PIGSTY 4.5.1 | PIGSTY 4.5.1 | N/A | N/A | N/A |
| d12.x86_64 | N/A | N/A | N/A | N/A | N/A |
| d12.aarch64 | N/A | N/A | N/A | N/A | N/A |
| d13.x86_64 | N/A | N/A | N/A | N/A | N/A |
| d13.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u22.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u22.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u24.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u24.aarch64 | N/A | N/A | N/A | N/A | N/A |
| u26.x86_64 | N/A | N/A | N/A | N/A | N/A |
| u26.aarch64 | N/A | N/A | N/A | N/A | N/A |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_tre_18 |
4.5.1 |
el8.x86_64 | pigsty | 590.3 KiB | pg_tre_18-4.5.1-1PGSTY.el8.x86_64.rpm |
pg_tre_18 |
4.5.1 |
el8.aarch64 | pigsty | 574.0 KiB | pg_tre_18-4.5.1-1PGSTY.el8.aarch64.rpm |
pg_tre_18 |
4.5.1 |
el9.x86_64 | pigsty | 560.7 KiB | pg_tre_18-4.5.1-1PGSTY.el9.x86_64.rpm |
pg_tre_18 |
4.5.1 |
el9.aarch64 | pigsty | 551.8 KiB | pg_tre_18-4.5.1-1PGSTY.el9.aarch64.rpm |
pg_tre_18 |
4.5.1 |
el10.x86_64 | pigsty | 567.7 KiB | pg_tre_18-4.5.1-1PGSTY.el10.x86_64.rpm |
pg_tre_18 |
4.5.1 |
el10.aarch64 | pigsty | 556.2 KiB | pg_tre_18-4.5.1-1PGSTY.el10.aarch64.rpm |
| Package | Version | OS | ORG | SIZE | File URL |
|---|---|---|---|---|---|
pg_tre_17 |
4.5.1 |
el8.x86_64 | pigsty | 590.9 KiB | pg_tre_17-4.5.1-1PGSTY.el8.x86_64.rpm |
pg_tre_17 |
4.5.1 |
el8.aarch64 | pigsty | 574.9 KiB | pg_tre_17-4.5.1-1PGSTY.el8.aarch64.rpm |
pg_tre_17 |
4.5.1 |
el9.x86_64 | pigsty | 561.5 KiB | pg_tre_17-4.5.1-1PGSTY.el9.x86_64.rpm |
pg_tre_17 |
4.5.1 |
el9.aarch64 | pigsty | 552.4 KiB | pg_tre_17-4.5.1-1PGSTY.el9.aarch64.rpm |
pg_tre_17 |
4.5.1 |
el10.x86_64 | pigsty | 568.4 KiB | pg_tre_17-4.5.1-1PGSTY.el10.x86_64.rpm |
pg_tre_17 |
4.5.1 |
el10.aarch64 | pigsty | 557.0 KiB | pg_tre_17-4.5.1-1PGSTY.el10.aarch64.rpm |
Source
codeberg.org/gregburd/pg_tre
pg_tre-4.5.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
- README.md
- pg_tre.control
- sql/pg_tre–4.5.1.sql
- CHANGELOG.md
- LIMITATIONS.md
- META.json
- .github/workflows/ci.yml
- Library initialization
pg_tre 4.5.1 provides the tre native index access method for approximate regular-expression matching over text on PostgreSQL 17–19. It narrows candidates with codepoint trigrams and postings, then checks matches against the heap. Use it for typo-tolerant identifiers, log messages and lexical patterns with explicit edit costs.
Enable and Search
The index write path uses PostgreSQL’s generic WAL facility. Since 4.0.0, CREATE EXTENSION is sufficient: shared_preload_libraries and a restart are not required to enable a new installation. Extension creation requires a superuser, and the control file is untrusted and non-relocatable.
PostgreSQL 19 uses the core regular-expression character classifier; ICU character-class edge cases on PostgreSQL 17–18 may differ from native PostgreSQL regex semantics, as described upstream.
Patterns and Objects
tre_pattern(text)usespg_tre.default_max_cost;tre_pattern(text, int4)supplies a maximum cost; the five-argument form also sets insertion, deletion and substitution costs. Patterns use POSIX extended regular expressions and TRE approximate budgets.text %~~ tre_patternis the indexable approximate-match predicate;text <@> tre_patternreturns the edit cost or NULL when no match fits the budget.tre_distance,tre_similarity,tre_amatch,tre_amatch_costandtre_amatch_detailexpose matching and compatibility functions.- The index operator family also supports LIKE, ILIKE, regular-expression and equality predicates with heap rechecks. The separately named trigram functions coexist with
pg_trgm;pg_tredoes not install the colliding bare trigram operators removed in 3.0.
Indexes accept one text column with tre_text_ops. Expression and partial indexes are available, but index-only scans are not. Short patterns, high edit budgets and non-literal regexes can produce broad candidate sets; inspect real plans and keep cancellation and query-time limits enabled.
Maintenance and Limits
fastupdate must be true; setting it false is now rejected because the direct path could not preserve the index format. Existing off settings can still be opened, but inserts use the pending list. pending_list_limit is in KiB and defaults to 0, meaning unlimited. A positive value triggers a synchronous merge when the threshold is crossed; that inserting backend pays the work, and if another merge is active the limit can temporarily be exceeded.
pg_tre.min_trigram_freq must remain 1. Values above 1 formerly omitted rare postings and could lose results; they are now rejected. Keep regex state and compilation/matching limits bounded for untrusted patterns. Index construction uses tuplesort and temporary disk, with memory governed by maintenance_work_mem; estimate large builds before scheduling them.
pg_tre_index_check compares index answers with sequential scans. Each sample performs multiple sequential scans, so bound the sample count on large tables. Version 4.5.1 fixes its search-path handling, pins trusted lookup paths and qualifies calls; use the fixed version before running this helper as a privileged user.
Upgrade Boundaries
Install matching files, ensure sessions use the new library, and update each database:
Crossing from 3.x to 4.x changes WAL record types even though the index page format is unchanged. Shut down cleanly before replacing the library; a physical standby cannot run a different major extension version from its primary and must be rebuilt from a fresh base backup after the primary upgrade. There is no rolling upgrade across this boundary. Remove any old wal_consistency_checking = 'pg_tre' setting; it prevents startup in 4.x. Upstream recommends wal_consistency_checking = 'all' when consistency checking is needed.
Version 4.4 writes format 11 and reads formats 6–10. Upgrading from those formats does not require a routine rebuild; optional REINDEX obtains the newer dense-posting representation. Downgrading to 4.3 after a 4.4+ write requires rebuilding the affected indexes for the older format. Older upgrades may cross additional boundaries described in the changelog.
REINDEX every index built with min_trigram_freq greater than 1: installing the fix cannot restore omitted postings. Version 4.5 also disables stale SuRF acceleration on indexes from earlier affected versions, restoring correctness immediately; a rebuild is optional to regain that acceleration. Upgrading 4.5.0 to 4.5.1 changes neither format nor ordinary query behavior and requires no additional REINDEX. Old definitions using the removed tuple bloom options must still be corrected before rebuilding.