PostgreSQL

PostgreSQL Extensions Guide: pg_stat_statements, pg_trgm, pg_cron, and More

Survey essential PostgreSQL extensions: pg_stat_statements for query analysis, pg_trgm for fuzzy search, pg_cron for scheduled jobs, pg_buffercache for cache inspection.

JusDB Team
Published November 6, 2025
5 min read

PostgreSQL's extension system is one of its greatest strengths. The right extensions can add full-text search, time-series, vector search, statistics, and more — without leaving PostgreSQL.

Essential Extensions

sql
-- Performance analysis
CREATE EXTENSION pg_stat_statements;  -- query statistics
CREATE EXTENSION pgstattuple;         -- table/index bloat analysis
CREATE EXTENSION pg_buffercache;      -- inspect buffer pool contents

-- Data types and functions
CREATE EXTENSION hstore;             -- key-value store in a column
CREATE EXTENSION citext;             -- case-insensitive text
CREATE EXTENSION uuid-ossp;          -- UUID generation functions
CREATE EXTENSION pg_trgm;            -- trigram similarity, fuzzy search

-- Advanced features
CREATE EXTENSION vector;             -- pgvector: AI embeddings
CREATE EXTENSION timescaledb;        -- time-series hypertables
CREATE EXTENSION pg_partman;         -- automated partition management
CREATE EXTENSION pg_cron;            -- cron-based job scheduling
sql
CREATE EXTENSION pg_trgm;

-- GIN index for fast fuzzy search
CREATE INDEX idx_products_name_trgm ON products
USING GIN (name gin_trgm_ops);

-- Find similar product names
SELECT name, similarity(name, 'postgresl') AS sim
FROM products
WHERE name % 'postgresl'     -- similarity > 0.3 threshold
ORDER BY sim DESC
LIMIT 10;

pg_cron: Scheduled Jobs

sql
CREATE EXTENSION pg_cron;

-- Vacuum a table every night at 2am
SELECT cron.schedule('nightly-vacuum', '0 2 * * *',
  $$VACUUM ANALYZE orders$$);

-- Purge old data weekly
SELECT cron.schedule('weekly-purge', '0 3 * * 0',
  $$DELETE FROM events WHERE created_at < now() - INTERVAL '90 days'$$);

-- List scheduled jobs
SELECT * FROM cron.job;

pg_buffercache: What Is in Shared Buffers?

sql
CREATE EXTENSION pg_buffercache;

-- Top tables by buffer cache usage
SELECT c.relname,
       count(*) AS buffers,
       pg_size_pretty(count(*) * 8192) AS cached_size
FROM pg_buffercache b
JOIN pg_class c ON c.relfilenode = b.relfilenode
WHERE b.reldatabase = (SELECT oid FROM pg_database WHERE datname = current_database())
GROUP BY c.relname
ORDER BY buffers DESC
LIMIT 10;

Key Takeaways

  • Install pg_stat_statements on every PostgreSQL instance — it is free and invaluable
  • pg_trgm enables fuzzy string matching with GIN indexes — replaces many Elasticsearch use cases
  • pg_cron runs maintenance jobs inside PostgreSQL without external schedulers
  • Check pg_available_extensions to see what is available in your PostgreSQL version

JusDB Can Help

The right PostgreSQL extensions can solve problems that would otherwise require additional services. JusDB can audit your use cases and recommend the right extensions.

Share this article

JusDB Team

Official JusDB content team

Keep reading

PostgreSQL 19 Beta: Every New Feature That Matters to DBAs

PostgreSQL 19 Beta 1 (June 4, 2026) brings parallel autovacuum, the native REPACK command for online table rebuilds, 2x faster inserts under foreign-key load, online logical replication without a restart, WAIT FOR LSN for read-your-writes consistency, and default changes (JIT off, lz4 TOAST, RADIUS removed). A DBA-focused walkthrough of what changed and what to test before GA.

PostgreSQL14 minJun 15, 2026
Read

PostgreSQL Performance Tuning Playbook: A Top-Down Method for Faster Queries

A repeatable, top-down method for tuning PostgreSQL: measure with pg_stat_statements, read plans with EXPLAIN (ANALYZE, BUFFERS), fix queries and indexes before parameters, then tune memory, I/O, WAL, connection pooling, and autovacuum — with a ready-to-adapt postgresql.conf baseline.

PostgreSQL22 minMay 31, 2026
Read

PostgreSQL Architecture Deep Dive: Process Model, MVCC, WAL & Replication Explained

Walk through PostgreSQL's multi-process architecture, shared/local memory layout, page-organized storage, MVCC tuple versioning, the WAL write path, the query execution pipeline, and physical + logical replication — all with ASCII flow diagrams that show how data and control actually move through the system.

PostgreSQL18 minMay 31, 2026
Read