What are PostgreSQL extensions? Give examples.
IntermediateConceptPostgreSQL
Answer
Short answer
Extensions package extra features — data types, functions, indexes — that you add to a database with CREATE EXTENSION. They're one of PostgreSQL's biggest strengths.
Popular extensions
| Extension | What it adds |
|---|---|
pg_stat_statements |
Query performance statistics |
pgvector |
Vector type + similarity search for AI/RAG embeddings |
PostGIS |
Geographic data and queries |
pgcrypto |
Hashing and encryption functions |
uuid-ossp |
UUID generation (PG 13+ has gen_random_uuid() built in) |
pg_trgm |
Fuzzy text search / LIKE acceleration |
TimescaleDB |
Time-series tables |
postgres_fdw |
Query tables in another Postgres server |
Example
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE docs (id serial PRIMARY KEY, content text, embedding vector(1536));
CREATE INDEX ON docs USING hnsw (embedding vector_cosine_ops);
SELECT content FROM docs ORDER BY embedding <=> '[0.01, 0.02, ...]' LIMIT 5;
\dx -- installed extensions
SELECT * FROM pg_available_extensions; -- available to install
Managed services
RDS and Azure support a list of extensions; some must be allowed in a parameter (azure.extensions) or added to shared_preload_libraries (needs a restart).
What to say in the interview
"Extensions add capabilities via CREATE EXTENSION — pg_stat_statements for performance, pgvector for embeddings in RAG apps, PostGIS for geo. On managed services I check the supported list and whether it needs shared_preload_libraries."
More on PostgreSQL
How do you set up PostgreSQL and log in with psql?BeginnerHow do you create a database, tables, users and query data in PostgreSQL?BeginnerHow do you back up and restore a PostgreSQL database?BeginnerWhat is PostgreSQL and why is it so popular?BeginnerHow is PostgreSQL organised: cluster, database, schema and table?BeginnerHow do you connect to PostgreSQL from the command line?Beginner