Extensions Basics
PostgreSQL extensions add types, functions, and background workers without forking the server. Install them deliberately, track versions, and know which ones require a restart via shared_preload_libraries.
Search across all documentation pages
PostgreSQL extensions add types, functions, and background workers without forking the server. Install them deliberately, track versions, and know which ones require a restart via shared_preload_libraries.
-- List available extensions in the cluster
SELECT name, default_version, installed_version, comment
FROM pg_available_extensions
ORDER BY name;
-- Install into a schema (common pattern for PostGIS, pgvector)
CREATE SCHEMA IF NOT EXISTS extensions;
CREATE EXTENSION IF NOT EXISTS vector
WITH SCHEMA extensions
VERSION '0.8.0';
-- Extensions that need preload (example: pg_stat_statements)
-- postgresql.conf:
-- shared_preload_libraries = 'pg_stat_statements'
-- Then restart, then:
CREATE EXTENSION pg_stat_statements;When to reach for this: You need capabilities beyond core SQL (vectors, geospatial, stats, audit) and want them versioned like application dependencies.
-- Bootstrap a new database with pinned extensions
BEGIN;
CREATE SCHEMA IF NOT EXISTS extensions;
GRANT USAGE ON SCHEMA extensions TO app_role;
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA extensions;
CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA extensions VERSION '0.8.0';
-- Verify what is installed
SELECT e.extname,
e.extversion,
n.nspname AS schema
FROM pg_extension e
JOIN pg_namespace n ON n.oid = e.extnamespace
WHERE e.extname IN ('pgcrypto', 'vector');
COMMIT;What this demonstrates:
extensions schema keeps public cleanVERSION pins the extension at install timepg_extension is the inventory source of truthpg_available_extensions.CREATE EXTENSION runs the install script and records metadata in pg_extension.ALTER EXTENSION ... UPDATE applies migration scripts between versions.DROP EXTENSION removes objects the extension owns; use CASCADE only after review.| Extension | Preload required? | Notes |
|---|---|---|
pg_stat_statements | Yes | Tracks normalized query stats |
pg_cron | Yes | Background job scheduler |
vector (pgvector) | No | Loads on CREATE EXTENSION |
postgis | No | Heavy SQL install, no preload |
Preload extensions need a full server restart. Plan maintenance windows before enabling them in production.
-- See installed vs available
SELECT extname,
extversion AS installed,
(SELECT default_version
FROM pg_available_extensions a
WHERE a.name = e.extname) AS available_default
FROM pg_extension e;On managed Postgres (RDS, Cloud SQL, Neon), only pre-approved extensions appear in pg_available_extensions. Self-hosted clusters install packages via OS (postgresql-18-pgvector, postgis) before CREATE EXTENSION succeeds.
USAGE on the extension schema; avoid granting CREATE on public to app roles.IF NOT EXISTS in idempotent migration scripts.CREATE EXTENSION vector fails with "could not open extension control file." Fix: Install the extension package for your Postgres major version first.public by default and clutter search paths. Fix: CREATE EXTENSION postgis WITH SCHEMA extensions; on greenfield databases.shared_preload_libraries and running CREATE EXTENSION immediately fails. Fix: Restart Postgres, then create the extension.USAGE only.ALTER EXTENSION UPDATE.pg_depend audit before drop; prefer ALTER EXTENSION updates over reinstall.| Alternative | Use When | Don't Use When |
|---|---|---|
| Core Postgres only | Simple CRUD, no special types | You need vectors, GIS, or advanced stats |
| Application-layer libraries | Extension not available on managed host | You need index-backed search in SQL |
| Foreign data wrappers | Data lives in another system | Latency and join complexity are unacceptable |
| Separate search/OLAP service | Massive scale, dedicated team | Operational cost of another datastore is too high |
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PostGIS 3.5+, pgbouncer 1.x, and Patroni 3.x.
Reviewed by Chris St. John·Last updated Jul 18, 2026