Load Extension

Extensions using the hook mechanism must be preloaded and require a restart to take effect.

While most PostgreSQL extensions written in SQL can be directly enabled with CREATE EXTENSION, extensions that provide dynamic libraries (.so, .dylib, .dll) have different loading requirements.

Most library-based extensions don’t need explicit loading. However, extensions using PostgreSQL’s Hook mechanism require an additional step — modifying the shared_preload_libraries parameter and restarting the database server.

Attempting to execute CREATE EXTENSION without proper preloading will result in an error. And wrongly configured loading may lead to a failure on database restart/start.


Quick Start

For example, in the conf/app/supa config template, we load multiple extensions by setting the pg_libs parameter:

all:
  children:
    pg-meta:
      hosts: { 10.10.10.10: { pg_seq: 1, pg_role: primary } }
      vars:
        pg_cluster: pg-meta
        pg_databases:
          - name: postgres
            pg_libs: 'timescaledb, plpgsql, plpgsql_check, pg_cron, pg_net, pg_stat_statements, auto_explain, pg_tle, plan_filter'

Not all extensions require dynamic loading via pg_libs (e.g., pgcrypto, pgjwt, vector). For extensions requiring dynamic loading, please refer to the Extensions that Need Loading list below.


Configure

There are several ways to modify PostgreSQL cluster configuration in Pigsty:

For new clusters, configure the pg_libs parameter to specify the initial value of shared_preload_libraries.

Note that pg_libs only takes effect during cluster creation. After creation, it becomes the initial value for the PostgreSQL parameter shared_preload_libraries.

To modify loaded extensions in an existing cluster, use the Patroni command line to config cluster, change shared_preload_libraries, and restart to apply changes.

Alternatively, you can modify shared_preload_libraries by editing postgresql.conf, using the ALTER SYSTEM command, or overriding it through pg_parameters. Ensure configuration remains consistent across the cluster.


Default

Pigsty preloads these two Contrib extensions by default:

  • auto_explain: Provides automatic logging of slow query execution plans
  • pg_stat_statements: Tracks planning and execution statistics for grouped SQL statements

These extensions are critical for query performance monitoring, which is why the default value of pg_libs is pg_stat_statements, auto_explain.

We strongly recommend retaining these extensions when configuring additional loaded modules.


Caveats

In shared_preload_libraries, separate multiple extensions with commas:

shared_preload_libraries = 'timescaledb, pg_stat_statements, auto_explain'

Loading sequence can be significant. For example, citus and timescaledb must be placed at the beginning of shared_preload_libraries. If using both extensions simultaneously (uncommon), place citus before timescaledb.

The full-text search plugin pg_search requires explicit loading in current versions, but in PostgreSQL 17, this requirement is removed.

For the MongoDB emulation plugin documentdb, note that the dynamic library names differ from the extension names — use pg_documentdb and pg_documentdb_core instead.


Extensions that Need Loading

In the Extension List, extensions marked with LOAD require dynamic loading and a server restart. These include:

Extension Name ext Package Name pkg Category Description
timescaledb timescaledb TIME Enables scalable inserts and complex queries for time-series data
pg_cron pg_cron TIME Job scheduler for PostgreSQL
pg_task pg_task TIME Execute SQL commands at specific times in the background
vchord vchord RAG Vector database plugin for Postgres, written in Rust
pgml pgml RAG PostgresML: Run AI/ML workloads with SQL interface
pg_bestmatch pg_bestmatch FTS Generate BM25 sparse vector inside PostgreSQL
vchord_bm25 vchord_bm25 FTS PostgreSQL extension for BM25 ranking algorithm
citus citus OLAP Distributed PostgreSQL as an extension
pg_duckdb pg_duckdb OLAP DuckDB embedded in PostgreSQL
pg_parquet pg_parquet OLAP Copy data between PostgreSQL and Parquet files
plan_filter pg_plan_filter FEAT Filter statements by their execution plans
omni omnigres FEAT Advanced adapter for PostgreSQL extensions
pg_tle pg_tle LANG Trusted Language Extensions for PostgreSQL
plpgsql_check plpgsql_check LANG Extended checker for PL/pgSQL functions
pgpdf pgpdf TYPE PDF type with metadata and full-text search
pglite_fusion pglite_fusion TYPE Embed an SQLite database in your PostgreSQL table
pg_net pg_net UTIL Asynchronous HTTP requests
pg_squeeze pg_squeeze ADMIN Tool to remove unused space from a relation
pgautofailover pgautofailover ADMIN Automated failover manager for PostgreSQL
pg_crash pg_crash ADMIN Send random signals to random processes
pg_prewarm pg_prewarm ADMIN Prewarm relation data
pg_tracing pg_tracing STAT Distributed tracing for PostgreSQL
pg_stat_kcache pg_stat_kcache STAT Kernel statistics gathering
pg_stat_monitor pg_stat_monitor STAT PostgreSQL query performance monitoring tool with aggregated statistics, client information, plan details, and histogram information
pg_qualstats pg_qualstats STAT Extension collecting statistics about predicate expressions
pg_store_plans pg_store_plans STAT Track execution plan statistics of SQL statements
pg_wait_sampling pg_wait_sampling STAT Sampling-based statistics of wait events
bgw_replstatus bgw_replstatus STAT Background worker reporting replication primary/standby status
pg_relusage pg_relusage STAT Log queries that reference a particular column
auto_explain auto_explain STAT Automatically log execution plans of slow statements
pg_stat_statements pg_stat_statements STAT Track planning and execution statistics of SQL statements
passwordcheck_cracklib passwordcheck SEC Strengthen PostgreSQL password checks with cracklib
supautils supautils SEC Extension to secure clusters in cloud environments
pgsodium pgsodium SEC PostgreSQL extension for libsodium cryptographic functions
anon pg_anon SEC PostgreSQL Anonymizer extension
pg_tde pg_tde SEC Transparent data encryption method
pgaudit pgaudit SEC Provides detailed session and object audit logging
pg_snakeoil pg_snakeoil SEC PostgreSQL antivirus extension
pgextwlist pgextwlist SEC PostgreSQL extension whitelisting
noset pg_noset SEC Module blocking SET commands for non-superusers
sepgsql sepgsql SEC Label-based mandatory access control based on SELinux security policy
auth_delay auth_delay SEC Brief pause before reporting authentication failures
passwordcheck passwordcheck SEC Checks and rejects weak passwords
documentdb documentdb SIM API surface for DocumentDB for PostgreSQL
documentdb_core documentdb SIM Core API for DocumentDB for PostgreSQL
documentdb_distributed documentdb SIM Multi-node API for DocumentDB
pg_statement_rollback pg_statement_rollback SIM Statement-level rollback similar to Oracle or DB2
babelfishpg_tsql babelfishpg_tsql SIM SQL Server T-SQL compatibility
pglogical_ticker pglogical_ticker ETL Accurate monitoring of pglogical replication delay
pg_failover_slots pg_failover_slots ETL Failover slot management for logical replication




Last modified 2025-03-07: extension update (3df74ea)