Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Managed Service for PostgreSQL
  • Getting started
    • All guides
      • Managing extensions
      • pg_cron
      • pg_repack
      • pgaudit
      • pgcrypto
      • postgresql_anonymizer
      • Hunspell dictionaries for full-text search
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Installing postresql_anonymizer in a PostgreSQL cluster
  • Usage example
  1. Step-by-step guides
  2. PostgreSQL extensions and dictionaries
  3. postgresql_anonymizer

Using postgresql_anonymizer in Managed Service for PostgreSQL

Written by
Yandex Cloud
Updated at December 25, 2025
  • Installing postresql_anonymizer in a PostgreSQL cluster
  • Usage example

The postgresql_anonymizer extension allows you to mask or replace personal and commercially sensitive data in a PostgreSQL database.

The extension uses a declarative approach to anonymization, allowing you to declare masking rules with DDL and set the anonymization strategy within the table definition.

Data anonymization methods:

  • Static masking: Replaces sensitive information with other data according to the masking rules. This method makes it impossible to restore the original data.
  • Generalization: Replaces a value, e.g., number or date, with a range that contains it.

Installing postresql_anonymizer in a PostgreSQL clusterInstalling postresql_anonymizer in a PostgreSQL cluster

To install postgresql_anonymizer in a PostgreSQL cluster:

  1. Load the shared library anon into your cluster.

  2. Enable the anon extension in your database.

  3. Assign the mdb_admin role to the database owner, if not assigned yet.

    You can get the owner's name from the cluster’s database list.

To learn more about the postgresql_anonymizer extension, see its official documentation.

Usage exampleUsage example

In the following example, we will use static masking to substitute data according to the masking rules.

  1. Connect to the database via psql.

  2. Create a table named employees and populate it with data:

    CREATE TABLE employees (
      id SERIAL,
      name TEXT,
      company TEXT,
      code TEXT
    );
    
    INSERT INTO employees
    VALUES
    (111,'Maria Belova','Bank of Saratov','405-657'),
    (222,'Pavel Petrov','Head and Hands','601-245')
    ;
    
  3. Check the result:

    SELECT * FROM employees;
    
    id  |       name       |    company      |   code
    ----+------------------+-----------------+-----------
    111 | Maria Belova     | Bank of Saratov |  405-657
    222 | Pavel Petrov     | Head and Hands  |  601-245
    
  4. Define the masking rules:

    SECURITY LABEL FOR anon ON COLUMN employees.company
    IS 'MASKED WITH FUNCTION anon.fake_company()';
    
    SECURITY LABEL FOR anon ON COLUMN employees.code
    IS 'MASKED WITH FUNCTION anon.random_zip()';
    
  5. Replace the data in masked columns:

    SELECT anon.anonymize_database();
    
  6. Verify that the data in the company and code columns has changed:

    id  |       name       |           company                |   code
    ----+------------------+----------------------------------+---------
    111 | Maria Belova     | Schneider, Phillips and Martinez |  82175
    222 | Pavel Petrov     | White, Hines and Ramos           |  49306
    

Was the article helpful?

Previous
pgcrypto
Next
Hunspell dictionaries for full-text search
© 2026 Direct Cursus Technology L.L.C.