Recently, we had a long discussion in our internal chat about the concept of Trusted Extensions in PostgreSQL. It became clear that while the feature is very useful, it’s often misunderstood — especially by beginners. Let's fix that!
Table of Contents
This post explains what trusted extensions are, why they exist, how they work, and provides some important hints and warnings for everyday use.
An extension is a package of SQL scripts, types, functions, and sometimes even compiled C code that extends PostgreSQL's capabilities.
Extensions are installed on the server and then enabled inside a database using:
1 |
CREATE EXTENSION my_extension; |
Normally, installing or enabling an extension requires superuser privileges, because extensions can modify how the database server behaves.
Trusted extensions allow non-superusers (regular database users) to enable certain extensions themselves using CREATE EXTENSION
, without needing superuser rights.
In simple words:
CREATE
privilege on a database can activate it.Important:
"Trusted" does not mean:
It simply means:
"We believe that enabling this extension should not allow users to bypass security or harm the database server."
Each extension has a control file (.control
) where its properties are described.
Inside that file, the line:
1 |
trusted = true |
tells PostgreSQL that the extension can be enabled by non-superusers.
If the line is missing, the extension is considered untrusted by default.
Example of a simple control file:
1 2 3 4 5 |
comment = 'Extension for text search' default_version = '1.0' relocatable = false superuser = false trusted = true |
The same extension can be trusted on one server but untrusted on another, depending on what the local superuser decides!
Trusted extensions are especially important for PostgreSQL cloud providers. In managed database services), users typically don't have superuser access for safety reasons. Without trusted extensions, they would be severely limited in extending the functionality of their databases.
Thanks to trusted extensions:
hstore
, citext
, pg_trgm
, and more.As you can see, trusted extensions make PostgreSQL much more cloud-friendly!
Let's use a simple analogy:
Imagine a kindergarten (your PostgreSQL server) full of kids (database users) who love to play with toys (extensions). You, as the principal/teacher (superuser), are responsible for making sure everyone is safe.
You decide which toys go into which room:
The important thing is it’s not about who made the toy (extension author), or even how famous it is.
It’s about whether it’s safe to allow general users to play with it without direct supervision.
And yes — if a principal (admin) wants, they could technically move any toy to the open room — but it's on them if something goes wrong!
Some extensions that ship bundled with PostgreSQL (from the "contrib" modules) are marked trusted.
These usually provide safe functionality like new data types, functions, or indexes without dangerous side effects.
However, external extensions (e.g., developed by companies like CYBERTEC) are not usually automatically trusted — it's up to authors and administrators to make those decisions.
- Trusted does not mean bug-free.
Even trusted extensions could have bugs. Trust is a promise by the author — not a full audit!
- C Extensions deserve extra caution.
If an extension loads C code (.so files), it can still crash the database or introduce risks. Labeling them trusted requires careful review. Same applies for pgrx extension written in Rust, for example.
- Superusers have the final say.
Admins can override trust by editing control files or managing access rights manually.
- "Install" vs "Create" confusion.
- You don't have to trust blindly.
Even if an extension says "trusted", it's perfectly okay to review it yourself before allowing users to enable it.
Trusted extensions are an elegant PostgreSQL feature that helps balance security and flexibility.
Used wisely, trusted extensions empower PostgreSQL to stay open, safe, and powerful for everyone.
Leave a Reply