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
November 6, 2025
Updated May 23, 2026
5 min read
177 views

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