Config
Some extensions require preloading dynamic libraries or configuring parameters before use. This section describes how to configure extensions.
Preload Extensions
Most extensions can be enabled directly with CREATE EXTENSION after installation, but some extensions using PostgreSQL’s Hook mechanism require preloading.
Preloading is specified via the shared_preload_libraries parameter and requires a database restart to take effect.
Extensions Requiring Preload
Common extensions that require preloading:
| Extension | Description |
|---|---|
timescaledb | Time-series database extension, must be placed first |
citus | Distributed database extension, must be placed first |
pg_stat_statements | SQL statement statistics, enabled by default in Pigsty |
auto_explain | Automatically log slow query execution plans, enabled by default in Pigsty |
pg_cron | Scheduled task scheduling |
pg_net | Asynchronous HTTP requests |
pg_tle | Trusted language extensions |
pgaudit | Audit logging |
pg_stat_kcache | Kernel statistics |
pg_squeeze | Online table space reclamation |
pgml | PostgresML machine learning |
For the complete list, see the Extension Catalog (marked with LOAD).
Preload Order
The loading order of extensions in shared_preload_libraries is important:
timescaledbandcitusmust be placed first- If using both,
citusshould come beforetimescaledb - Statistics extensions should come after
pg_stat_statementsto use the same query_id
pg_libs: 'citus, timescaledb, pg_stat_statements, auto_explain'
Configure During Cluster Initialization
When creating a new cluster, use the pg_libs parameter to specify preloaded extensions:
pg-meta:
hosts: { 10.10.10.10: { pg_seq: 1, pg_role: primary } }
vars:
pg_cluster: pg-meta
pg_libs: 'timescaledb, pg_stat_statements, auto_explain'
pg_extensions: [ timescaledb, postgis, pgvector ]
The value of pg_libs will be written to shared_preload_libraries during cluster initialization.
Default Value
The default value of pg_libs is pg_stat_statements, auto_explain. These two Contrib extensions provide basic observability:
pg_stat_statements: Track execution statistics of all SQL statementsauto_explain: Automatically log execution plans for slow queries
Modify Configuration on Existing Cluster
For initialized clusters, use patronictl to modify shared_preload_libraries:
# Add timescaledb to preload libraries
pg edit-config pg-meta --force -p shared_preload_libraries='timescaledb, pg_stat_statements, auto_explain'
# Restart cluster to apply configuration
pg restart pg-meta
You can also directly modify postgresql.conf or use ALTER SYSTEM:
ALTER SYSTEM SET shared_preload_libraries = 'timescaledb, pg_stat_statements, auto_explain';
A PostgreSQL service restart is required after modification.
Extension Parameter Configuration
Many extensions have configurable parameters that can be set in the following locations:
During Cluster Initialization
Use the pg_parameters parameter to specify:
pg-meta:
vars:
pg_cluster: pg-meta
pg_libs: 'pg_cron, pg_stat_statements, auto_explain'
pg_parameters:
cron.database_name: postgres # Database used by pg_cron
pg_stat_statements.track: all # Track all statements
auto_explain.log_min_duration: 1000 # Log queries exceeding 1 second
Runtime Modification
Use ALTER SYSTEM or patronictl:
-- Modify parameter
ALTER SYSTEM SET pg_stat_statements.track = 'all';
-- Reload configuration
SELECT pg_reload_conf();
# Modify using patronictl
pg edit-config pg-meta --force -p 'pg_stat_statements.track=all'
Important Notes
Preload errors prevent startup: If an extension in
shared_preload_librariesdoesn’t exist or fails to load, PostgreSQL will not start. Ensure extensions are properly installed before adding to preload.Modification requires restart: Changes to
shared_preload_librariesrequire restarting the PostgreSQL service to take effect.Partial functionality available: Some extensions can be partially used without preloading, but full functionality requires preloading.
View current configuration: Use the following command to view current preload libraries:
SHOW shared_preload_libraries;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.