Open-Source Wikis

/

PostgreSQL

/

Extensions

/

Contrib modules

postgres/postgres

Contrib modules

contrib/ is the project's collection of optional first-party extensions. They are built and packaged with the server but not loaded automatically; users opt in with CREATE EXTENSION <name>. This page is a guided tour, grouped by what each module is for.

How a contrib module is built

Each contrib directory contains a small Makefile (and meson.build), one or more C files, a <name>.control file declaring the extension, and one or more <name>--<version>.sql scripts. make install puts the .so in the standard library directory and the SQL/control files in share/extension/. Then CREATE EXTENSION <name> runs the SQL.

Some contribs are pure SQL and have no C component (e.g., intagg, tcn). Others are tightly bound to backend internals.

Performance and observability

Module Purpose
pg_stat_statements Cumulative statistics about SQL queries: total time, rows, calls, plan/exec time, I/O. Probably the most-used contrib in production. Must be loaded via shared_preload_libraries.
auto_explain Automatically logs EXPLAIN ANALYZE for queries slower than a threshold.
pg_buffercache View into shared-buffer contents.
pg_freespacemap View into the FSM.
pg_visibility View into the VM (visibility map).
pg_walinspect Read WAL records as rows; replaces pg_xlogdump for in-server analysis.
pg_logicalinspect Inspect the contents of logical-replication snapshots.
pageinspect Decode raw pages of heap and indexes. Used by the project's own tests.
pgrowlocks Show row-level lock state of a relation's tuples.
pgstattuple Dead/live tuple statistics for a relation; used by autovacuum tuning analyses.
pg_overexplain Extra EXPLAIN format with extension hooks.
pg_plan_advice, pg_stash_advice Newer planner advisory tools (in master).
Module Purpose
btree_gin GIN operator classes for the btree-indexable types. Lets you mix btree-style equality with other GIN predicates in a single index.
btree_gist Same but for GiST. Useful for exclusion constraints across heterogenous types.
bloom Bloom-filter index access method. Multi-column equality at low storage cost.
pg_trgm Trigram similarity for text. Used for approximate match (%, <%, <<%, <<<%) and LIKE/ILIKE acceleration via GIN/GiST.
fuzzystrmatch Soundex, Metaphone, Levenshtein, dmetaphone — phonetic and approximate string matching functions.
unaccent Diacritic-folding text-search dictionary.
dict_int, dict_xsyn Specialized text-search dictionaries.

Datatypes

Module Purpose
citext Case-insensitive text type.
cube Multi-dimensional numeric cube type plus GiST operator class. Often paired with earthdistance for geographic queries.
earthdistance "Earth distance" calculations on cube or point.
hstore Key-value store as a single column. Now usually superseded by jsonb but still widely deployed.
intarray Operators and indexing for int[].
isn International standard numbers (ISBN, ISSN, EAN13, etc.).
ltree Hierarchical label trees (path-style data). Indexable.
seg Confidence intervals (numeric ranges with uncertainty).
uuid-ossp UUID generation functions (v1, v3, v4, v5). Modern PostgreSQL has gen_random_uuid() built in, but uuid-ossp adds the others.

Bridging to other languages

Trans-type bindings between contrib datatypes and procedural languages:

Module
bool_plperl
hstore_plperl, hstore_plpython
jsonb_plperl, jsonb_plpython
ltree_plpython

These let PL/Perl and PL/Python functions accept and return the relevant datatype as a native Perl/Python value rather than a string.

Federation and FDWs

Module Purpose
postgres_fdw Foreign-data wrapper for federating to other PostgreSQL servers. Pushes down quals, joins, aggregates, sorts, and DML when safe. The reference FDW implementation.
file_fdw Foreign-data wrapper for CSV / text files. Read-only. Built on COPY.
dblink Older alternative to FDWs: function-call-based remote queries. Predates the FDW API by a decade but still in use.

Backup, recovery, and admin

Module Purpose
amcheck Verify the structural correctness of indexes (and, in newer versions, heaps). The driver pg_amcheck (in src/bin/) wraps it.
auth_delay Adds a configurable delay after failed login attempts (anti-brute-force).
basebackup_to_shell A pg_basebackup target module that pipes the backup to a shell command.
basic_archive A reference implementation of the archive_library interface (replaces archive_command for some workloads).
oid2name CLI tool to map OIDs to names. Useful when a pg_class.relfilenode-named file is all you have.
passwordcheck Hooks into role creation and password change to enforce complexity rules. Loaded via shared_preload_libraries.
pg_archivecleanup (frontend tool, also documented under Apps.)
pg_prewarm Pre-loads relations into the shared-buffer cache after a restart.
pg_surgery "Surgery" functions for emergency repair of corrupted heaps. Use with extreme care.
pgcrypto Cryptographic primitives: hashes, ciphers, public-key, password hashing. Unmaintained-style legacy module that nonetheless remains the easiest way to call SHA-256 from SQL.
sslinfo SQL-callable views into the active SSL session.
tcn Triggered Change Notification: fires NOTIFY messages on row changes.
vacuumlo Bulk-deletes orphaned large objects.

Logical replication and CDC

Module Purpose
test_decoding The reference logical-decoding output plugin. Outputs a human-readable representation of every change. The basis of every CDC tool's first integration test.

Sampling and testing

Module Purpose
tablefunc crosstab(), connectby(), normal-distribution random variates. Crosstab in particular is a common ask.
tsm_system_rows TABLESAMPLE method that takes N rows.
tsm_system_time TABLESAMPLE method that runs for M milliseconds.

Security

Module Purpose
sepgsql SELinux integration: applies MAC labels to PostgreSQL objects via the object_access_hook and policy decisions made by SELinux userspace. Linux-only and rarely deployed but actively maintained.

Stored procedures and SPI

Module Purpose
spi A historical "module" that is really a holding area for example SPI-using extensions: autoinc, insert_username, moddatetime, refint. Mostly preserved for backwards compatibility.
xml2 Older XML support, predating the in-core xml type.
intagg Pure-SQL aggregates over integer arrays.
lo Helper for tracking large-object references.

What's not here

A lot of widely-used PostgreSQL extensions are not in contrib/:

  • PostGIS — separate project. Far too large and specialized.
  • pgvector — embedding-vector index AM. Out of tree.
  • TimescaleDB, Citus, pg_partman — out of tree.
  • pglogical — older logical replication; mostly superseded by core's logical replication.

The criteria for a feature ending up in contrib/ rather than out-of-tree are informal: small, useful, broadly applicable, and not wedded to a particular vendor's vision. The community is, on net, conservative about adding new contribs — most new functionality lives outside the tree.

Entry points for modification

  • Adding a feature to an existing contrib: each subdirectory is self-contained.
  • Adding a new contrib: write the C, a control file, an SQL script, a Makefile, and a meson.build. Add a TAP or SQL test directory. Submit a patch with the same workflow as a backend feature.

For the broader extension story (PLs, hooks, etc.), see Extensions.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Contrib modules – PostgreSQL wiki | Factory