Security and privacy · Edition No. 58 · 22 Oct 2026

michelp/pgsodium

A PostgreSQL extension that brings libsodium's encryption functions into SQL, with a root key the database cannot read back.

← Security and privacyRead the whole edition →
12

michelp/pgsodium

💎 hidden gem

614 stars · PostgreSQL Licence · v3.1.11 (2026-06-10) · Track this in Scout

A PostgreSQL extension that brings libsodium's encryption functions into SQL, with a root key the database cannot read back.

▶Repo detailsthe review · specs · pros & cons · install

What it does

It makes the functions of libsodium, a well-regarded encryption library, callable from SQL, which is the language used to query a database. That covers hashing, public-key encryption, digital signatures, deriving keys from other keys, and password hashing. Its key management is the part worth the attention: a root key is loaded into the server at startup and is not readable from SQL, and every other key is derived from it by number, so the database stores key numbers rather than keys. On top of that sits a feature called transparent column encryption, which uses database triggers and views so a column is encrypted on the way in and decrypted on the way out without the application knowing. There is also a section for encrypting network addresses in a way that keeps their structure. Version 3.0.0 needs PostgreSQL 14 or newer, earlier database versions need the 2.0 line, and some of the column-encryption features rely on a PostgreSQL 15 feature. Code was pushed on 10 June 2026. Now the limits, and this project is remarkably honest about them. The managed keys are optional, and without them you have to handle keys yourself. The project says storing secrets in a database is generally a bad idea even though it can be done carefully. It states that a sufficiently capable attacker with full database powers might still reach the root key through other programs, memory dumps or swap files, and that this is outside what the extension can prevent. One of its encryption modes reveals when two stored values are identical. One of its hash functions produces only 64 bits and is not safe against deliberate collisions. And values passed through the standard database client's variables can end up in the database logs.

Why it matters

Who it suits. Anyone who has to encrypt specific fields inside PostgreSQL — a token, a document reference, a national identifier — and wants the key kept out of the database that holds the data. It suits a situation where an auditor is asking where the keys live, because the answer here is concrete. It also suits anyone who cannot change the application, since transparent column encryption works through views and triggers rather than through code changes. Skip it if what you need is encryption of the whole disk or the whole database, which is a different and simpler problem, and skip it if there is nobody on hand who can reason about key rotation.

Verdict. A genuine find at 612 stars, and the reason to read it is the documentation as much as the code: a security project that spends paragraphs on what it cannot protect against has earned the claims it does make. The superuser point is the one to act on, exactly as with the audit extension covered in Edition 57: if one account can reach the running server's memory, no extension inside that server can stop it, so that access is the thing to restrict. Two practical notes. Code was pushed on 10 June 2026, four months before this edition, and the repository publishes no releases, so the version numbers come from the documentation rather than from a tag. And test it on a copy first, because an encryption mistake is discovered later than other mistakes and costs more. For storing a handful of secrets rather than encrypting columns, supabase/vault is the smaller answer; for a layer in front of the database rather than inside it, cossacklabs/acra was covered in Edition 55.

Stars614
LicencePostgreSQL Licence
Latestv3.1.11 (2026-06-10)
Good
  • The root key is loaded at startup and cannot be read back through SQL, so the database stores key numbers rather than keys.
  • Transparent column encryption works through views and triggers, so the application does not have to change.
  • It documents its own weaknesses in detail, including the ones that are awkward to admit.
Watch for
  • It publishes no releases, so versions have to be read from the documentation rather than a tag.
  • Several modes carry sharp edges: one reveals duplicate values, and one hash is only 64 bits.
  • Building it needs libsodium 1.0.18 or newer and the PostgreSQL development headers, which is a real install.
Similar repositories
  • supabase/vault

    A PostgreSQL extension for storing encrypted secrets and reading them back through a view; a much smaller job than encrypting columns, and its About sidebar links a licence file without naming the licence.

    Track this in Scout
  • cossacklabs/acra

    Apache-2.0, a suite that sits in front of the database instead of inside it: it encrypts fields, blocks risky queries and watches for intrusion. Edition 55 covered it.

    Track this in Scout
Install
# build it, with libsodium 1.0.18+ and the PostgreSQL headers present
git clone https://github.com/michelp/pgsodium.git
cd pgsodium
sudo make install
# or from the PostgreSQL extension network
pgxn install pgsodium
Screenshots
michelp/pgsodium: GitHub preview card

On Stack Radar: Infrastructure & Security › Databases & Storage › SQL Databases.

Get the next edition in your inbox

A dozen repositories, opened and checked. The licence read, the last release dated, and the ones that did not make it named with the reason. It is the half most lists leave out.

No tracking pixels. One click to leave. The archive stays free either way.

We use your address to send the edition and nothing else. Confirm by email, leave in one click. How we handle it.