Quick revision
The short answer
An extension is a package of SQL objects, such as types, functions, operators and index methods, often backed by compiled C code, that we install into a database with CREATE EXTENSION name and can see in pg_extension and pg_available_extensions. Four widely used ones are pg_stat_statements for per-query statistics, PostGIS for geospatial data, pg_trgm for similarity and LIKE '%x%' search, and pgvector for vector similarity search; pgcrypto and postgres_fdw are common too.
What to remember
In this answer, we saw that an extension packages SQL objects and often C code, installed per database with CREATE EXTENSION and listed in pg_extension and pg_available_extensions. pg_stat_statements finds slow and frequent queries and needs shared_preload_libraries; pgcrypto provides hashing and encryption, while gen_random_uuid() is built in since PostgreSQL 13 and uuidv7() arrives in 18; PostGIS adds geospatial data; pg_trgm makes similarity and LIKE '%x%' searches fast; pgvector adds vector similarity search; and postgres_fdw queries other PostgreSQL servers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
An extension is a package of SQL objects, such as types, functions, operators and index methods, often backed by compiled C code, that we install into a database with CREATE EXTENSION name and can see in pg_extension and pg_available_extensions. Four widely used ones are pg_stat_statements for per-query statistics, PostGIS for geospatial data, pg_trgm for similarity and LIKE '%x%' search, and pgvector for vector similarity search; pgcrypto and postgres_fdw are common too.
Why this question is asked
Much of PostgreSQL's reputation comes from what can be added to it. Extensions turn the same database into a geospatial engine, a vector store or a tool for finding slow queries, without a new system to run. Interviewers ask this concept question to check that we know how extensions work and can name ones that solve real problems. In this answer, we will see what an extension is and how to install one, then look at the most widely used extensions and the problem each solves, and finish with what to check before relying on one.
1What an Extension Is
An extension bundles database objects under one name and version. A control file describes it, SQL scripts create its objects, and many extensions also ship a shared library of C code that PostgreSQL loads to run their functions, index types or hooks. Because PostgreSQL exposes extension points for data types, operators, index access methods, table access methods, planner hooks and more, extensions can add features that feel built in.
Installing is a two-part process. The extension's files must be present on the server, which is a package installation for self-hosted PostgreSQL and a provider choice on managed services. Then, in each database that should use it, we run CREATE EXTENSION. The extension's objects then belong to it, so DROP EXTENSION removes them together and pg_dump records only the CREATE EXTENSION line.
Version numbers here are examples; check your server.
2Pg_stat_statements: Finding Slow and Frequent Queries
pg_stat_statements records statistics for every distinct query shape. It normalises queries by replacing constants with placeholders, so WHERE id = 7 and WHERE id = 8 count as one entry, and keeps totals of calls, execution time, rows, and buffer hits and reads. This is the first tool for answering 'what is the database spending its time on?', because a query that takes 2 ms but runs 50 million times a day can matter more than one that takes 10 seconds once.
It needs its library loaded at server start, so it is added to shared_preload_libraries and the server is restarted once, then created as an extension.
3Pgcrypto and UUIDs
pgcrypto adds hashing and encryption functions: digest() for SHA-256 and other hashes, hmac(), crypt() with gen_salt() for password hashing, and pgp_sym_encrypt() for symmetric encryption of values. It used to be installed mainly for gen_random_uuid(), but that function is built into core PostgreSQL since version 13, so no extension is needed for random UUIDs. PostgreSQL 18 also adds a built-in uuidv7() for time-ordered UUIDs, which index better; check your version.
4PostGIS and pg_trgm
PostGIS adds geospatial types such as geometry and geography, hundreds of functions for distance, containment and intersection, and spatial indexing through GiST. It answers questions like 'which stores are within 5 km of this customer?' with an index instead of computing distances to every store. It is one of the most complete geospatial systems available, in any database.
pg_trgm splits text into trigrams, groups of three consecutive characters, and compares strings by how many trigrams they share. That gives similarity search for typos ('postgras' finds 'postgres'), and, with a GIN or GiST trigram index, makes LIKE '%term%' and ILIKE fast. A normal B-tree index cannot help a pattern that starts with a wildcard, so without pg_trgm such searches scan the whole table.
5Pgvector, postgres_fdw and a Summary
pgvector adds a vector type and distance operators for cosine, Euclidean (L2) and inner product distance, plus approximate nearest neighbour indexes (HNSW and IVFFlat). It lets an application store embeddings from a machine learning model next to its data and search for the most similar items in SQL. postgres_fdw is a foreign data wrapper: it lets one PostgreSQL server query tables on another as if they were local, which helps with migrations and occasional cross-database queries.
| Extension | Problem it solves | Note |
|---|---|---|
| pg_stat_statements | which queries cost the most time | needs shared_preload_libraries |
| pgcrypto | hashing and encryption in SQL | random UUIDs are built in since 13 |
| PostGIS | geospatial types, functions, indexes | GiST spatial indexes |
| pg_trgm | typo search and LIKE '%x%' | GIN or GiST trigram indexes |
| pgvector | vector similarity search | HNSW and IVFFlat indexes |
| postgres_fdw | query another PostgreSQL server | foreign tables |
6Follow-up questions
Which extensions does your managed provider allow?
Each provider publishes a list of supported extensions and versions per PostgreSQL major version, and we query pg_available_extensions on the instance to confirm. Common ones such as pg_stat_statements, pgcrypto, pg_trgm, PostGIS and pgvector are widely available, while extensions with custom C code that the provider has not vetted cannot be installed. Some need a parameter group change, such as adding to shared_preload_libraries. We check this before designing around an extension, and check its version, because a newer feature may need a newer extension release.
What risks come with installing extensions?
C extensions run inside the server process, so a bug can crash the backend or the whole server, and they must be compatible with every major version we upgrade to. We keep an approved list, pin versions, test upgrades, and prefer well-maintained extensions with wide use.
Is an extension per database or per server?
The files are installed per server, but CREATE EXTENSION is run per database, so each database decides which extensions it uses. Libraries in shared_preload_libraries are loaded for the whole server.
7Conclusion
In this answer, we saw that an extension packages SQL objects and often C code, installed per database with CREATE EXTENSION and listed in pg_extension and pg_available_extensions. pg_stat_statements finds slow and frequent queries and needs shared_preload_libraries; pgcrypto provides hashing and encryption, while gen_random_uuid() is built in since PostgreSQL 13 and uuidv7() arrives in 18; PostGIS adds geospatial data; pg_trgm makes similarity and LIKE '%x%' searches fast; pgvector adds vector similarity search; and postgres_fdw queries other PostgreSQL servers.
Open with
An extension is a package that adds objects to PostgreSQL, such as data types, functions, operators and index methods, usually with some compiled C code behind them. The files are installed on the server, and then in each database we run CREATE EXTENSION with its name.
Then, if they want more
We can see what is installed in pg_extension and what could be installed in pg_available_extensions.
Four that I use or see most are these. pg_stat_statements aggregates statistics per normalised query, calls, total and mean time, buffer reads, so it is the first place I look for slow or very frequent queries; it needs to be in shared_preload_libraries, which means one restart.
PostGIS adds geospatial types, functions and GiST indexes, so queries like stores within 5 kilometres use an index. pg_trgm breaks text into trigrams, which gives typo-tolerant similarity search and makes LIKE with a leading wildcard fast with a GIN trigram index.
And pgvector adds a vector type with cosine, L2 and inner product distance and HNSW or IVFFlat indexes for semantic search. I would also mention pgcrypto for hashing and encryption, noting that gen_random_uuid is built in since PostgreSQL 13 and uuidv7 since 18, and postgres_fdw to query another PostgreSQL server. On a managed service I would always check which extensions are allowed first.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- PostgreSQL 13, PostgreSQL 18
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is a PostgreSQL extension? Name four widely used extensions and what problem each...": https://scrivio-interview-library.netlify.app/databases/postgresql/d59bc10507/