Data masking for databases: native options and the proxy approach

Data masking returns a modified value (a***@example.com, ****4242) instead of the real one to whoever should not see it. In PostgreSQL, MySQL and MariaDB you can do it with views and column privileges, an extension or a proxy; the right choice depends on who reads the data and whether you can change the application.

What data masking is

Data masking replaces a sensitive value with a realistic but harmless one. The column keeps its name and the query keeps working; only the value changes.

  • Static masking rewrites the stored data, usually in a copy (a staging database, a dump for developers). The original values are gone from that copy.
  • Dynamic masking leaves the data as it is and masks the value when a given role or client reads it. Others still see the real value.
TechniqueWhat it protectsWho still sees the value
MaskingValues in query resultsThe roles or clients that are not masked
EncryptionData at rest or in transitAnyone who queries with a role that can read the column
Row-level securityWhich rows a role seesThe full row, every column, for the rows it does see
Column privilegesWhether a role can read a column at allRoles with the privilege see the real value; others get an error

When you need it

  • Personal and payment data (PII): emails, phone numbers, card numbers, national IDs.
  • Compliance work: frameworks such as GDPR or PCI DSS ask you to limit who sees personal or card data. Masking is one control among several; it does not make a system compliant on its own.
  • Analysts and support who need the rows but not the full values.
  • Developers who work on a copy of production.
  • AI agents. SELECT email, card_number FROM customers is harmless to the database and still puts personal and payment data into an LLM's context. An agent that writes its own SQL reads whatever its role allows.

Native options per engine

EngineNative optionsGuide
PostgreSQLViews with column privileges; the postgresql_anonymizer extension (dynamic and static masking, anonymized dumps); row-level security filters rows, not columnsPostgreSQL data masking
MySQLMySQL Enterprise Data Masking functions (Enterprise Edition only); views with column privileges; generated columnsMySQL data masking
MariaDBThe MaxScale masking filter (a separate product with its own licence); views with column privileges; generated columnsMariaDB data masking

Every guide has SQL that was run in a container, with its real output, and says which statements come only from the docs.

Native options vs. masking at a proxy

Views and column privilegesMasking extension or filterVericto proxy
Application changesQueries must use the viewNone for the masked role or servicePoint the connection at the proxy; the SQL does not change
Per-agent policiesOne database role per agentPer role or per accountPer database registered in Vericto: a dedicated proxy for the agent path
AuditDatabase logsDatabase or proxy logsEach masked, blocked or flagged read is an audit trail event, with the column that triggered it
PerformanceThe view's expressions run in the databaseDepends on the productOne extra hop, and the masking expressions run in the database; measured latency and method
LicensingPart of the databaseDepends on the product (see each guide)Proxy and engine are AGPL-3.0-only

They combine well: column privileges and views in the database, and the proxy on the path an agent or an untrusted client uses.

Mask columns with Vericto

Vericto masks at the proxy, for agents and applications, without changing the database or the application. You tag the column once; the proxy rewrites each query that reads it.

  • Tag columns per database in the Vericto dashboard, each with a policy: block (the query is blocked), flag (it runs and is recorded, with an alert) or mask (the projection is rewritten), and for mask a style: full, last4, email or hash.
  • Every read of a tagged column is reported as VERICTO-085. When a query reads several tagged columns, the strictest policy wins: block > mask > flag.
  • Vericto decides on the AST of the query, by column name. It never reads the results and does not look at the values.

This is the real rewrite the engine produced for a PostgreSQL query, with email tagged mask/email and card_number tagged mask/last4:

-- The query the agent or the app sends (PostgreSQL):
SELECT id, name, email, card_number FROM customers WHERE id = 42
-- FLAGGED VERICTO-085: SensitiveColumn > customers.card_number, customers.email (mask)
-- The query the proxy forwards instead (rewritten_query):
SELECT id, name, regexp_replace(email::text, '^(.)[^@]*(@.*)?$', E'\\1***\\2') AS email, CASE WHEN char_length(card_number::text) <= 8 THEN '[redacted]'::text ELSE '****' || "right"(card_number::text, 4) END AS card_number FROM customers WHERE id = 42

Real output: vericto-engine 5.0.0, evaluate() on PostgreSQL with customers.email (mask, email), customers.card_number (mask, last4) and customers.ssn (block), 2026-11-14.

And the rows that rewrite returns on PostgreSQL:

-- The rows the masked rewrite returns:
 id | name |      email       | card_number
----+------+------------------+-------------
 42 | Ana  | a***@example.com | ****4242
(1 row)

Tested on PostgreSQL 17.11 and 18.6 (Docker images postgres:17 and postgres:18), 2026-11-16.

Sensitive columns are configured in a Vericto workspace; the masking page lists where the feature is available. vericto-proxy mcp applies masks only when it is linked to a workspace: its local mode, with no account, has none. The details per engine are in the PostgreSQL, MySQL and MariaDB guides.

Frequently asked questions

Sources

The official documentation this guide cites, checked on 2026-11-14: