List Installed Extensions in PostgreSQL
How to List Installed Extensions in PostgreSQL
PostgreSQL extensions package additional functionality — data types, functions, operators, and index methods — that can be installed into a database with CREATE EXTENSION. Common examples include pg_stat_statements for query performance tracking, uuid-ossp for UUID generation, postgis for geographic data, and pg_trgm for fuzzy text search.
Before modifying a database or diagnosing unexpected behavior, it is useful to know exactly which extensions are installed, which versions are running, and which schema their objects live in.
Sample Code
List all installed extensions in the current database:
1SELECT
2 e.extname AS extension_name,
3 e.extversion AS installed_version,
4 n.nspname AS schema,
5 e.extrelocatable AS relocatable,
6 c.description AS description
7FROM
8 pg_catalog.pg_extension e
9 JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace
10 LEFT JOIN pg_catalog.pg_description c
11 ON c.objoid = e.oid
12 AND c.classoid = 'pg_catalog.pg_extension'::regclass
13ORDER BY
14 e.extname;
Check what extensions are available (installed or not):
1SELECT
2 name,
3 default_version,
4 installed_version,
5 comment
6FROM
7 pg_catalog.pg_available_extensions
8ORDER BY
9 name;
Find extensions with an available upgrade:
1SELECT
2 name,
3 installed_version,
4 default_version
5FROM
6 pg_catalog.pg_available_extensions
7WHERE
8 installed_version IS NOT NULL
9 AND installed_version <> default_version
10ORDER BY
11 name;
Notes: pg_extension works on PostgreSQL 9.1 and later (extensions were introduced in 9.1). pg_available_extensions requires the extension files to be present on the server's file system — it reflects what the server can install, not just what is installed.
Code Breakdown
pg_catalog.pg_extension— System catalog that stores one row for each extension installed in the current database. Extensions are per-database, not per-cluster.extname— The extension name as used inCREATE EXTENSION extname.extversion— The version string of the currently installed extension.extnamespace— OID of the schema where most of the extension's objects are created.extrelocatable— Boolean. If true, the extension can be moved to a different schema withALTER EXTENSION ... SET SCHEMA.pg_catalog.pg_namespace— Joined to convertextnamespaceOID to a readable schema name.pg_catalog.pg_description— Provides the human-readable description of the extension, filtered byclassoidto thepg_extensioncatalog.pg_catalog.pg_available_extensions— A view (not a table) that reads from the server's extension files on disk. Showsinstalled_versionas null for extensions that are available but not yet installed.
Key Points
- Extensions are installed per database. Running
CREATE EXTENSION pg_stat_statementsinmydbdoes not install it inotherdb. - The
pg_catalogschema itself is never listed as an extension — its objects are built into PostgreSQL. - Most extensions install their objects into a dedicated schema (e.g.,
extensions) orpublic. Using a dedicated schema keepspublicclean. pg_stat_statementsmust also be added toshared_preload_librariesinpostgresql.confto function — installing it withCREATE EXTENSIONalone is not enough.
Insights and Explanations
Checking if a specific extension is installed:
1SELECT extname, extversion
2FROM pg_catalog.pg_extension
3WHERE extname = 'pg_stat_statements';
Returns one row if installed, zero rows if not.
Installing an extension:
1CREATE EXTENSION IF NOT EXISTS pg_trgm
2 SCHEMA extensions;
Upgrading an extension to the latest available version:
1ALTER EXTENSION pg_trgm UPDATE;
Removing an extension:
1DROP EXTENSION pg_trgm;
This removes the extension and all objects it created. Use CASCADE to also drop dependent objects.
Common useful extensions:
| Extension | Purpose |
|---|---|
pg_stat_statements | Track execution statistics for all SQL statements |
pg_trgm | Trigram matching for fuzzy text search and LIKE index support |
uuid-ossp | Generate UUIDs (version 1, 3, 4, 5) |
pgcrypto | Cryptographic functions (hashing, encryption) |
hstore | Key-value store data type |
postgis | Geospatial data types, functions, and indexes |
tablefunc | Functions for cross-tab (pivot) queries |
unaccent | Text search dictionary that removes accents |
Additional Considerations
- Permissions: Any user can query
pg_extension.CREATE EXTENSIONrequires superuser or thepg_extension_ownerrole (PostgreSQL 15+). - Trusted extensions: PostgreSQL 13 introduced trusted extensions, which can be installed by non-superusers who hold the
CREATEprivilege on the database. Thepg_available_extensionsview marks these withtrusted = true. - Extension scripts: Extension files live in
$sharedir/extension/on the server. If an extension is missing frompg_available_extensions, its.controlfile is not present on disk.
References
Posts in this series
- How Many Connections Can Your PostgreSQL Database Handle?
- PostgreSQL Backend Connections via pg_stat_database
- Identifying Blocking PostgreSQL Queries using pg_stat_activity
- List PostgreSQL Databases by Size with Access Check
- Assess PostgreSQL Database Sizes Quickly and Easily
- Unveiling Your PostgreSQL Server - A Diagnostic Powerhouse
- Keep Your PostgreSQL Database Clean, Identify Idle Connections
- Query the PostgreSQL Configuration
- PostgreSQL Recovery Monitoring: Essential SQL Insights
- Restart All PostgreSQL Sequences with ALTER SEQUENCE
- Monitor Running Queries in PostgreSQL using pg_stat_activity
- Monitor PostgreSQL Active Sessions with pg_stat_activity
- PostgreSQL Error Handling Settings via pg_settings
- PostgreSQL File Location Settings Query via pg_settings
- PostgreSQL Lock Management Settings via pg_settings
- PostgreSQL Logging Configuration Query via pg_settings
- Monitor PostgreSQL Memory Settings with pg_settings
- PostgreSQL Table Row Count Estimates with SQL
- List PostgreSQL Tables by Size with SQL
- PostgreSQL WAL Settings Query Guide
- PostgreSQL SSL Settings Query Guide
- PostgreSQL Statistics Settings Query Guide
- PostgreSQL Resource Settings Query Guide
- PostgreSQL Replication Settings Query Guide
- PostgreSQL Query Planning Settings Query Guide
- PostgreSQL Preset Options Settings Query Guide
- PostgreSQL Miscellaneous Settings Query Guide
- Count PostgreSQL Sessions by State with SQL
- Kill Idle PostgreSQL Sessions with SQL
- Grant SELECT on All Tables in PostgreSQL
- Identify Insert-Only Tables in PostgreSQL
- Detect Soft Delete Patterns in PostgreSQL
- List PostgreSQL Object Comments with SQL
- List Foreign Key Constraints in PostgreSQL
- List PostgreSQL Enum Types and Their Values with SQL
- List All Views in a PostgreSQL Database with SQL
- Find PostgreSQL Tables Without a Primary Key
- List PostgreSQL Partitioned Tables with SQL
- List All Schemas in Your PostgreSQL Database
- PostgreSQL Database Statistics with pg_stat_database
- List PostgreSQL Roles and Their Privileges
- Scrubbing Email PII in PostgreSQL for GDPR Compliance
- List Installed Extensions in PostgreSQL
- List Collations in Your PostgreSQL Database
- PostgreSQL Replica Identity for Logical Replication