Skip to content

column_encrypt

Transparent column-level encryption with encrypted_text and encrypted_bytea types

column_encrypt · Transparent column-level encryption with encrypted_text and encrypted_bytea types

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7030column_encryptcolumn_encrypt4.0SECPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
fixed encrypt schema; create schema encrypt before CREATE EXTENSION; preload column_encrypt;

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY4.019 18 17 16 15column_encryptpgcrypto
RPMPIGSTY4.019 18 17 16 15column_encrypt_$v-
DEBPIGSTY4.019 18 17 16 15postgresql-$v-column-encrypt-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
el8.aarch64N/APIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
el9.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
el9.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
el10.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
el10.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
d12.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
d12.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
d13.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
d13.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u22.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u22.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u24.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u24.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u26.x86_64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
u26.aarch64PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0PIGSTY 4.0
PackageVersionOSORGSIZEFile URL
column_encrypt_194.0el9.x86_64pigsty71.2 KiBcolumn_encrypt_19-4.0-1PGSTY.el9.x86_64.rpm
column_encrypt_194.0el9.aarch64pigsty71.0 KiBcolumn_encrypt_19-4.0-1PGSTY.el9.aarch64.rpm
column_encrypt_194.0el10.x86_64pigsty71.2 KiBcolumn_encrypt_19-4.0-1PGSTY.el10.x86_64.rpm
column_encrypt_194.0el10.aarch64pigsty70.4 KiBcolumn_encrypt_19-4.0-1PGSTY.el10.aarch64.rpm
postgresql-19-column-encrypt4.0d12.x86_64pigsty62.5 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~bookworm_amd64.deb
postgresql-19-column-encrypt4.0d12.aarch64pigsty61.7 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~bookworm_arm64.deb
postgresql-19-column-encrypt4.0d13.x86_64pigsty62.6 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~trixie_amd64.deb
postgresql-19-column-encrypt4.0d13.aarch64pigsty61.8 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~trixie_arm64.deb
postgresql-19-column-encrypt4.0u22.x86_64pigsty63.8 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~jammy_amd64.deb
postgresql-19-column-encrypt4.0u22.aarch64pigsty63.2 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~jammy_arm64.deb
postgresql-19-column-encrypt4.0u24.x86_64pigsty62.9 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~noble_amd64.deb
postgresql-19-column-encrypt4.0u24.aarch64pigsty61.9 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~noble_arm64.deb
postgresql-19-column-encrypt4.0u26.x86_64pigsty62.8 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~resolute_amd64.deb
postgresql-19-column-encrypt4.0u26.aarch64pigsty62.2 KiBpostgresql-19-column-encrypt_4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
column_encrypt_184.0el8.x86_64pigsty73.3 KiBcolumn_encrypt_18-4.0-1PGSTY.el8.x86_64.rpm
column_encrypt_184.0el8.aarch64pigsty73.3 KiBcolumn_encrypt_18-4.0-1PGSTY.el8.aarch64.rpm
column_encrypt_184.0el9.x86_64pigsty71.2 KiBcolumn_encrypt_18-4.0-1PGSTY.el9.x86_64.rpm
column_encrypt_184.0el9.aarch64pigsty71.0 KiBcolumn_encrypt_18-4.0-1PGSTY.el9.aarch64.rpm
column_encrypt_184.0el10.x86_64pigsty71.2 KiBcolumn_encrypt_18-4.0-1PGSTY.el10.x86_64.rpm
column_encrypt_184.0el10.aarch64pigsty70.4 KiBcolumn_encrypt_18-4.0-1PGSTY.el10.aarch64.rpm
postgresql-18-column-encrypt4.0d12.x86_64pigsty62.6 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~bookworm_amd64.deb
postgresql-18-column-encrypt4.0d12.aarch64pigsty61.8 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~bookworm_arm64.deb
postgresql-18-column-encrypt4.0d13.x86_64pigsty62.5 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~trixie_amd64.deb
postgresql-18-column-encrypt4.0d13.aarch64pigsty61.8 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~trixie_arm64.deb
postgresql-18-column-encrypt4.0u22.x86_64pigsty63.8 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~jammy_amd64.deb
postgresql-18-column-encrypt4.0u22.aarch64pigsty63.2 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~jammy_arm64.deb
postgresql-18-column-encrypt4.0u24.x86_64pigsty62.9 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~noble_amd64.deb
postgresql-18-column-encrypt4.0u24.aarch64pigsty61.8 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~noble_arm64.deb
postgresql-18-column-encrypt4.0u26.x86_64pigsty62.8 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~resolute_amd64.deb
postgresql-18-column-encrypt4.0u26.aarch64pigsty62.1 KiBpostgresql-18-column-encrypt_4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
column_encrypt_174.0el8.x86_64pigsty73.3 KiBcolumn_encrypt_17-4.0-1PGSTY.el8.x86_64.rpm
column_encrypt_174.0el8.aarch64pigsty73.3 KiBcolumn_encrypt_17-4.0-1PGSTY.el8.aarch64.rpm
column_encrypt_174.0el9.x86_64pigsty71.3 KiBcolumn_encrypt_17-4.0-1PGSTY.el9.x86_64.rpm
column_encrypt_174.0el9.aarch64pigsty71.0 KiBcolumn_encrypt_17-4.0-1PGSTY.el9.aarch64.rpm
column_encrypt_174.0el10.x86_64pigsty71.2 KiBcolumn_encrypt_17-4.0-1PGSTY.el10.x86_64.rpm
column_encrypt_174.0el10.aarch64pigsty70.4 KiBcolumn_encrypt_17-4.0-1PGSTY.el10.aarch64.rpm
postgresql-17-column-encrypt4.0d12.x86_64pigsty62.5 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~bookworm_amd64.deb
postgresql-17-column-encrypt4.0d12.aarch64pigsty61.7 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~bookworm_arm64.deb
postgresql-17-column-encrypt4.0d13.x86_64pigsty62.5 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~trixie_amd64.deb
postgresql-17-column-encrypt4.0d13.aarch64pigsty61.8 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~trixie_arm64.deb
postgresql-17-column-encrypt4.0u22.x86_64pigsty65.2 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~jammy_amd64.deb
postgresql-17-column-encrypt4.0u22.aarch64pigsty64.6 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~jammy_arm64.deb
postgresql-17-column-encrypt4.0u24.x86_64pigsty62.9 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~noble_amd64.deb
postgresql-17-column-encrypt4.0u24.aarch64pigsty62.0 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~noble_arm64.deb
postgresql-17-column-encrypt4.0u26.x86_64pigsty62.8 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~resolute_amd64.deb
postgresql-17-column-encrypt4.0u26.aarch64pigsty62.1 KiBpostgresql-17-column-encrypt_4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
column_encrypt_164.0el8.x86_64pigsty73.3 KiBcolumn_encrypt_16-4.0-1PGSTY.el8.x86_64.rpm
column_encrypt_164.0el8.aarch64pigsty73.3 KiBcolumn_encrypt_16-4.0-1PGSTY.el8.aarch64.rpm
column_encrypt_164.0el9.x86_64pigsty71.3 KiBcolumn_encrypt_16-4.0-1PGSTY.el9.x86_64.rpm
column_encrypt_164.0el9.aarch64pigsty71.0 KiBcolumn_encrypt_16-4.0-1PGSTY.el9.aarch64.rpm
column_encrypt_164.0el10.x86_64pigsty71.2 KiBcolumn_encrypt_16-4.0-1PGSTY.el10.x86_64.rpm
column_encrypt_164.0el10.aarch64pigsty70.4 KiBcolumn_encrypt_16-4.0-1PGSTY.el10.aarch64.rpm
postgresql-16-column-encrypt4.0d12.x86_64pigsty62.5 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~bookworm_amd64.deb
postgresql-16-column-encrypt4.0d12.aarch64pigsty61.7 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~bookworm_arm64.deb
postgresql-16-column-encrypt4.0d13.x86_64pigsty62.5 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~trixie_amd64.deb
postgresql-16-column-encrypt4.0d13.aarch64pigsty61.8 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~trixie_arm64.deb
postgresql-16-column-encrypt4.0u22.x86_64pigsty65.2 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~jammy_amd64.deb
postgresql-16-column-encrypt4.0u22.aarch64pigsty64.6 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~jammy_arm64.deb
postgresql-16-column-encrypt4.0u24.x86_64pigsty62.9 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~noble_amd64.deb
postgresql-16-column-encrypt4.0u24.aarch64pigsty61.9 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~noble_arm64.deb
postgresql-16-column-encrypt4.0u26.x86_64pigsty62.8 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~resolute_amd64.deb
postgresql-16-column-encrypt4.0u26.aarch64pigsty62.1 KiBpostgresql-16-column-encrypt_4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
column_encrypt_154.0el8.x86_64pigsty73.5 KiBcolumn_encrypt_15-4.0-1PGSTY.el8.x86_64.rpm
column_encrypt_154.0el8.aarch64pigsty73.3 KiBcolumn_encrypt_15-4.0-1PGSTY.el8.aarch64.rpm
column_encrypt_154.0el9.x86_64pigsty71.4 KiBcolumn_encrypt_15-4.0-1PGSTY.el9.x86_64.rpm
column_encrypt_154.0el9.aarch64pigsty71.0 KiBcolumn_encrypt_15-4.0-1PGSTY.el9.aarch64.rpm
column_encrypt_154.0el10.x86_64pigsty71.6 KiBcolumn_encrypt_15-4.0-1PGSTY.el10.x86_64.rpm
column_encrypt_154.0el10.aarch64pigsty70.8 KiBcolumn_encrypt_15-4.0-1PGSTY.el10.aarch64.rpm
postgresql-15-column-encrypt4.0d12.x86_64pigsty62.5 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~bookworm_amd64.deb
postgresql-15-column-encrypt4.0d12.aarch64pigsty62.1 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~bookworm_arm64.deb
postgresql-15-column-encrypt4.0d13.x86_64pigsty62.6 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~trixie_amd64.deb
postgresql-15-column-encrypt4.0d13.aarch64pigsty62.2 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~trixie_arm64.deb
postgresql-15-column-encrypt4.0u22.x86_64pigsty65.5 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~jammy_amd64.deb
postgresql-15-column-encrypt4.0u22.aarch64pigsty64.9 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~jammy_arm64.deb
postgresql-15-column-encrypt4.0u24.x86_64pigsty62.9 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~noble_amd64.deb
postgresql-15-column-encrypt4.0u24.aarch64pigsty62.5 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~noble_arm64.deb
postgresql-15-column-encrypt4.0u26.x86_64pigsty63.0 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~resolute_amd64.deb
postgresql-15-column-encrypt4.0u26.aarch64pigsty62.5 KiBpostgresql-15-column-encrypt_4.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg column_encrypt;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install column_encrypt;		# install by package name

pig install column_encrypt -v 19;   # install for PG 19
pig install column_encrypt -v 18;   # install for PG 18
pig install column_encrypt -v 17;   # install for PG 17
pig install column_encrypt -v 16;   # install for PG 16
pig install column_encrypt -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'column_encrypt';

Create this extension with:

CREATE EXTENSION column_encrypt CASCADE; -- requires pgcrypto

Usage

Sources: README, v4.0 release, SQL objects

column_encrypt provides transparent column-level encryption for PostgreSQL. It defines encrypted_text and encrypted_bytea types, encrypts values through type input functions, decrypts through output functions, and manages data-encryption keys through the encrypt schema.

Enable

Load the shared library at server start, restart PostgreSQL, then create the schema and extension:

shared_preload_libraries = 'column_encrypt'
CREATE EXTENSION pgcrypto;
CREATE SCHEMA IF NOT EXISTS encrypt;
CREATE EXTENSION column_encrypt;

Add encrypt to search_path or schema-qualify the encrypted types and functions.

Register And Load Keys

SELECT encrypt.register_key('my-secret-data-key', 'my-master-passphrase');
SELECT encrypt.load_key('my-master-passphrase');

SELECT * FROM encrypt.keys();
SELECT * FROM encrypt.status();

The extension uses a two-tier key model with key-encryption keys and data-encryption keys. Ciphertext carries a key-version header so older values can still be decrypted after rotation.

Encrypt Columns

CREATE TABLE secure_data (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  ssn encrypt.encrypted_text,
  payload encrypt.encrypted_bytea
);

INSERT INTO secure_data (ssn, payload)
VALUES ('888-999-2045', decode('aabbcc', 'hex'));

SELECT id, ssn FROM secure_data;

Without a loaded key, decrypting encrypted values raises an error.

Key Operations

Common functions include encrypt.activate_key, encrypt.revoke_key, encrypt.rotate, encrypt.verify, encrypt.unload_key, encrypt.loaded_cipher_key_versions, and encrypt.blind_index.

Use blind indexes for lookup patterns that cannot expose plaintext values directly:

SELECT encrypt.blind_index('888-999-2045', 'lookup-hmac-key');

Notes

The extension intentionally rejects binary send/receive for encrypted values. Equality and hash semantics are based on decrypted plaintext; range ordering is not supported. After upgrading from older ciphertext-hash behavior, rebuild hash indexes on encrypted columns.

Table reader