Skip to content

anon

PostgreSQL Anonymizer (anon) extension

pg_anon · PostgreSQL Anonymizer (anon) extension

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7070anonpg_anon3.4.0SECPostgreSQLRust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Save masking rules before dropping and recreating the extension.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY3.4.019 18 17 16 15pg_anon-
RPMPIGSTY3.4.019 18 17 16 15pg_anon_$v-
DEBPIGSTY3.4.019 18 17 16 15postgresql-$v-pg-anon-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
el8.aarch64N/APIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
el9.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
el9.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
el10.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
el10.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
d12.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
d12.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
d13.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
d13.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u22.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u22.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u24.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u24.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u26.x86_64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
u26.aarch64PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0PIGSTY 3.4.0
PackageVersionOSORGSIZEFile URL
pg_anon_183.4.0el8.x86_64pigsty3.4 MiBpg_anon_18-3.4.0-1PGSTY.el8.x86_64.rpm
pg_anon_183.4.0el8.aarch64pigsty3.0 MiBpg_anon_18-3.4.0-1PGSTY.el8.aarch64.rpm
pg_anon_183.4.0el9.x86_64pigsty3.1 MiBpg_anon_18-3.4.0-1PGSTY.el9.x86_64.rpm
pg_anon_183.4.0el9.aarch64pigsty3.0 MiBpg_anon_18-3.4.0-1PGSTY.el9.aarch64.rpm
pg_anon_183.4.0el10.x86_64pigsty3.1 MiBpg_anon_18-3.4.0-1PGSTY.el10.x86_64.rpm
pg_anon_183.4.0el10.aarch64pigsty3.0 MiBpg_anon_18-3.4.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-anon3.4.0d12.x86_64pigsty2.8 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-anon3.4.0d12.aarch64pigsty2.5 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-anon3.4.0d13.x86_64pigsty2.8 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-anon3.4.0d13.aarch64pigsty2.5 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-anon3.4.0u22.x86_64pigsty3.1 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-anon3.4.0u22.aarch64pigsty2.9 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-anon3.4.0u24.x86_64pigsty3.0 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-anon3.4.0u24.aarch64pigsty2.9 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-anon3.4.0u26.x86_64pigsty3.0 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-anon3.4.0u26.aarch64pigsty2.8 MiBpostgresql-18-pg-anon_3.4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_anon_173.4.0el8.x86_64pigsty3.4 MiBpg_anon_17-3.4.0-1PGSTY.el8.x86_64.rpm
pg_anon_173.4.0el8.aarch64pigsty3.0 MiBpg_anon_17-3.4.0-1PGSTY.el8.aarch64.rpm
pg_anon_173.4.0el9.x86_64pigsty3.1 MiBpg_anon_17-3.4.0-1PGSTY.el9.x86_64.rpm
pg_anon_173.4.0el9.aarch64pigsty3.0 MiBpg_anon_17-3.4.0-1PGSTY.el9.aarch64.rpm
pg_anon_173.4.0el10.x86_64pigsty3.1 MiBpg_anon_17-3.4.0-1PGSTY.el10.x86_64.rpm
pg_anon_173.4.0el10.aarch64pigsty3.0 MiBpg_anon_17-3.4.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-anon3.4.0d12.x86_64pigsty2.8 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-anon3.4.0d12.aarch64pigsty2.5 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-anon3.4.0d13.x86_64pigsty2.8 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-anon3.4.0d13.aarch64pigsty2.5 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-anon3.4.0u22.x86_64pigsty3.1 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-anon3.4.0u22.aarch64pigsty2.9 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-anon3.4.0u24.x86_64pigsty3.0 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-anon3.4.0u24.aarch64pigsty2.9 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-anon3.4.0u26.x86_64pigsty3.0 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-anon3.4.0u26.aarch64pigsty2.8 MiBpostgresql-17-pg-anon_3.4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_anon_163.4.0el8.x86_64pigsty3.4 MiBpg_anon_16-3.4.0-1PGSTY.el8.x86_64.rpm
pg_anon_163.4.0el8.aarch64pigsty3.0 MiBpg_anon_16-3.4.0-1PGSTY.el8.aarch64.rpm
pg_anon_163.4.0el9.x86_64pigsty3.1 MiBpg_anon_16-3.4.0-1PGSTY.el9.x86_64.rpm
pg_anon_163.4.0el9.aarch64pigsty3.0 MiBpg_anon_16-3.4.0-1PGSTY.el9.aarch64.rpm
pg_anon_163.4.0el10.x86_64pigsty3.1 MiBpg_anon_16-3.4.0-1PGSTY.el10.x86_64.rpm
pg_anon_163.4.0el10.aarch64pigsty3.0 MiBpg_anon_16-3.4.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-anon3.4.0d12.x86_64pigsty2.8 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-anon3.4.0d12.aarch64pigsty2.5 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-anon3.4.0d13.x86_64pigsty2.8 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-anon3.4.0d13.aarch64pigsty2.5 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-anon3.4.0u22.x86_64pigsty3.1 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-anon3.4.0u22.aarch64pigsty2.9 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-anon3.4.0u24.x86_64pigsty3.0 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-anon3.4.0u24.aarch64pigsty2.8 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-anon3.4.0u26.x86_64pigsty3.0 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-anon3.4.0u26.aarch64pigsty2.8 MiBpostgresql-16-pg-anon_3.4.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_anon_153.4.0el8.x86_64pigsty3.4 MiBpg_anon_15-3.4.0-1PGSTY.el8.x86_64.rpm
pg_anon_153.4.0el8.aarch64pigsty3.0 MiBpg_anon_15-3.4.0-1PGSTY.el8.aarch64.rpm
pg_anon_153.4.0el9.x86_64pigsty3.1 MiBpg_anon_15-3.4.0-1PGSTY.el9.x86_64.rpm
pg_anon_153.4.0el9.aarch64pigsty3.0 MiBpg_anon_15-3.4.0-1PGSTY.el9.aarch64.rpm
pg_anon_153.4.0el10.x86_64pigsty3.1 MiBpg_anon_15-3.4.0-1PGSTY.el10.x86_64.rpm
pg_anon_153.4.0el10.aarch64pigsty3.0 MiBpg_anon_15-3.4.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-anon3.4.0d12.x86_64pigsty2.8 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-anon3.4.0d12.aarch64pigsty2.5 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-anon3.4.0d13.x86_64pigsty2.8 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-anon3.4.0d13.aarch64pigsty2.5 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-anon3.4.0u22.x86_64pigsty3.1 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-anon3.4.0u22.aarch64pigsty2.9 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-anon3.4.0u24.x86_64pigsty3.0 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-anon3.4.0u24.aarch64pigsty2.9 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-anon3.4.0u26.x86_64pigsty3.0 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-anon3.4.0u26.aarch64pigsty2.8 MiBpostgresql-15-pg-anon_3.4.0-1PGSTY~resolute_arm64.deb

Source

gitlab.com/dalibo/postgresql_anonymizer/

pig build pkg pg_anon;		# 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 pg_anon;		# install by package name
pig install anon;		# install by extension name

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

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'anon';

Create this extension with:

CREATE EXTENSION anon;

Usage

Sources:

anon is PostgreSQL Anonymizer. It applies declarative masking rules for protected query access, produces anonymized data sets, and provides pseudonymization and randomized-response helpers. Use it when realistic data must remain useful without exposing the original sensitive values; treat masking policy, role grants, and access to the unmasked database as part of the security boundary.

Core Workflow

Load anon for sessions in the target database, install the extension, and enable transparent dynamic masking. New connections pick up database-level settings.

ALTER DATABASE app SET session_preload_libraries = 'anon';

\connect app
CREATE EXTENSION anon;
ALTER DATABASE app SET anon.transparent_dynamic_masking = true;

Mark a login as masked and attach masking rules to sensitive columns:

CREATE ROLE reporting LOGIN;
SECURITY LABEL FOR anon ON ROLE reporting IS 'MASKED';
GRANT USAGE ON SCHEMA public TO reporting;
GRANT SELECT ON TABLE public.customer TO reporting;

SECURITY LABEL FOR anon ON COLUMN customer.last_name
  IS 'MASKED WITH FUNCTION anon.dummy_last_name()';
SECURITY LABEL FOR anon ON COLUMN customer.phone
  IS 'MASKED WITH FUNCTION anon.partial(phone, 2, $$******$$, 2)';

Queries made as reporting see the transformed values. Privileged users still see the originals, so do not grant masked roles a path around the policy.

Masking Strategies

  • Dynamic masking transforms results for roles labeled MASKED without rewriting the table.
  • Static masking permanently rewrites selected data and is appropriate for disposable development or test copies.
  • Anonymous dumps and replicas produce sanitized exports or downstream copies.
  • Masking views and data wrappers expose a deliberately reduced or transformed projection.
  • Pseudonymization uses deterministic transforms when joins or repeated values must remain consistent.

Important Objects

  • anon.dummy_*, anon.random_*, and anon.partial(...) generate or partially conceal values.
  • anon.hash(text) and anon.digest(text, text, text) provide deterministic transformations. In 3.1.2 they were marked RESTRICTED to limit brute-force exposure.
  • anon.ldp_grrm(value, epsilon, max_v) and anon.ldp_grrm_pttt(value, truth_probability, max_v) implement generalized randomized response for local differential privacy.
  • anon.ldp_truth_probability(...) and anon.ldp_lie_probability(...) help inspect randomized-response probabilities.
  • Security labels on roles and columns define who is masked and how each value is transformed.

Operational Notes

anon is superuser-installed and non-relocatable. Test every policy with the same grants and connection path used by the intended consumer. Randomization is not automatically deterministic; use a confirmed pseudonymization function when stable equality is required. Static anonymization is destructive, so run it on a copy and verify constraints and application behavior afterward.

Upgrading to 3.4.0

Save masking rules on roles, columns and tables, together with their grants. After installing the 3.4.0 library, follow the upstream guide to drop and recreate anon in each affected database. Restore the rules and grants, then test them as the masked role. Upstream provides no ALTER EXTENSION ... UPDATE path.

Transparent dynamic masking also covers the results of CREATE TABLE AS and SELECT INTO. Masked roles cannot create or refresh materialized views. Grant whole-table read access only on the required tables and restrict schema CREATE privileges.

Seed arguments to anon.seeded_* and anon.pseudo_* must be TEXT or BIGINT. For example, explicitly cast a UUID seed in a masking rule.

SECURITY LABEL FOR anon ON COLUMN customer.email
  IS 'MASKED WITH FUNCTION anon.seeded_email(user_uuid::TEXT)';

For dates and timestamps, choose a representation independent of session settings, such as to_char(birth_date, 'YYYY-MM-DD') for a date or extract(epoch FROM created_at)::BIGINT for an instant. Upstream plans to remove the older pseudonymization functions in 4.0.

Version 3.3.2

Version 3.3.2 is the follow-up release to the 3.3 security series and restores the missing ARM build. The 3.3 series forbids subqueries in masking rules, disables inlining for transparent dynamic masking, rejects SQL-standard-body functions for masked roles, and changes anon.salt. There is no in-place update path: preserve and migrate masking rules, then drop and recreate the extension in each database as directed by upstream.

Version 3.2.0 introduces localized deterministic anon.seeded_* functions; the older anon.pseudo_* family is deprecated. It fixes three upstream-reported security vulnerabilities and defaults to refusing masking operations executed by superusers. Use a dedicated non-superuser masking role. Setting anon.nosuperuser to false removes that barrier and is not the recommended upgrade path. The masking-rule JSON format changed; re-export rules after upgrading.

Version 3.2.3 is a security update for CVE-2026-97469: dynamic masking now checks for RESTRICTED functions inside subqueries. Upgrade the installed library, then follow the upstream drop-and-recreate procedure in each database; ALTER EXTENSION ... UPDATE is unsupported. Preserve and migrate masking rules before recreating the extension; review masked-role queries that previously reached restricted functions through subqueries.

Table reader