PostgreSQL Data Masking: Options for Protecting Test and Development Copies
PostgreSQL has no built-in dynamic masking. How the PostgreSQL Anonymizer extension works, why managed services may block extensions, and how to protect test copies with consistent static masking.
The short answer. PostgreSQL has no built-in dynamic data masking. The most established option inside the database is PostgreSQL Anonymizer, an open-source extension that supports both static masking, which rewrites data in a copy, and dynamic masking, which shows masked values to designated roles. Managed PostgreSQL services may not allow installing extensions, so teams on hosted platforms often mask outside the database. For test and development copies, the goal is the same as on any database: the copy should hold no real sensitive values, and masking should stay consistent with every connected system.
PostgreSQL is everywhere: behind internal applications, analytics platforms, SaaS products and integration layers. Wherever it holds customer, employee or financial data, copies of that data end up in development and test environments. Here is how masking works on PostgreSQL and what teams should consider.
What PostgreSQL provides natively
Unlike some commercial databases, PostgreSQL does not include a built-in dynamic data masking feature. Its access controls, such as roles, privileges, views and row-level security, can restrict who sees which data, but they do not replace sensitive values with realistic substitutes. For that, teams turn either to an extension or to masking outside the database.
PostgreSQL Anonymizer
PostgreSQL Anonymizer is an open-source extension, maintained by Dalibo, that is widely cited as the most established in-database option. It lets teams declare masking rules on columns and supports both approaches:
| Dynamic masking | Static masking | |
|---|---|---|
| What it does | Designated roles see masked values when they query | Rewrites the stored values, irreversibly |
| Stored data | Unchanged | Replaced in that copy |
| Typical use | Limiting what certain users see | Development and test copies |
The managed-service constraint
Installing an extension needs privileges that many hosted PostgreSQL services do not grant.
Installing PostgreSQL extensions requires elevated privileges, and many managed PostgreSQL services restrict which extensions can be installed. Teams running on hosted platforms should check their provider's supported extensions before planning around an in-database tool. Where the extension is not available, masking is typically done outside the database, applied to the data as it is copied into the non-production environment.
Static masking for test copies
For development and test environments, static masking is usually the right approach: the real values should not exist in the copy at all, so that losing the copy, or giving many people access to it, does not expose anyone. The typical pattern is to restore or copy production data into the non-production environment and replace the sensitive values there, never in production itself.
What to mask
- Direct identifiers. Names, email addresses, phone numbers, addresses.
- Financial data. Bank account and payment details.
- Employee data. Salaries, personal records, identifiers.
- Free text. Notes and comment fields that often contain personal details typed in freely.
- JSON columns. PostgreSQL applications often store personal data inside JSON documents, which are easy to overlook.
Keep it consistent
A PostgreSQL database rarely holds data in isolation. If the same customer exists in an ERP system and a PostgreSQL-backed application, both must be masked to the same value for end-to-end testing to work. Masking each database with its own tool and its own random values breaks those links.
Build masking into refreshes
Development databases are refreshed from production frequently, sometimes automatically. Each refresh restores real data unless masking runs as part of the same process. Making masking a step in the refresh pipeline, rather than something done once by hand, is what keeps non-production PostgreSQL environments protected over time.
Discover before you mask
Masking rules only cover the columns you list. Profiling the database first, including text and JSON columns, shows where personal and financial data actually sits, and avoids the common situation where the obvious columns are masked and a notes field still holds real customer details.
Verify the result
After masking, check that no real values remain in the columns that should be protected, and that the applications and tests that use the copy still work. A masking run that leaves data unusable will be bypassed by the next team in a hurry.
Choosing an approach
For a single PostgreSQL database where extensions are allowed, an in-database extension can be a practical choice. For landscapes where PostgreSQL sits alongside other databases and SAP, or where the hosting platform restricts extensions, masking outside the database is usually simpler to run consistently. The deciding questions are where the database is hosted, how many other systems share its entities, and who will run masking on every refresh.
Set a clear default
A written rule that real production data does not enter development or test PostgreSQL environments, with an owner for each environment and an exception process, makes masking the default. It is especially important where developers create databases freely, because ad hoc copies are where unmasked data most often escapes.
Involve the right people
Developers know where data is used, privacy teams know what must be protected, and platform teams know what the hosting environment allows. Agreeing the approach together avoids masking that one group cannot live with.
JSON deserves special attention
PostgreSQL applications frequently store flexible data in JSON columns, and personal details often end up inside them: a customer profile, a delivery address, a contact list. Column-level masking rules that ignore JSON content leave those details exposed. Any masking approach for PostgreSQL should be checked specifically for how it handles values nested inside JSON documents.
In short
PostgreSQL gives teams the access controls to restrict who sees data, and an established extension where in-database masking is possible. For test and development copies, especially on managed platforms or in mixed landscapes, the reliable answer is static masking applied to every copy, consistently across connected systems, and verified each time.
The practical test applies here as on any database: if a development copy were lost or shared too widely tomorrow, would it expose real people or real financial details? If the answer is yes, that copy needs static masking, applied as part of the process that creates it, before developers and testers start working with it.
Making that the standard keeps protection in place however many copies are made.
How deKorvai helps
deKorvai provides static masking outside the database through its scrambling engine, so it does not depend on installing extensions in a managed service. It connects to PostgreSQL and other relational databases through JDBC, as well as to SAP and files, and scrambles sensitive fields at field level with predefined profiles and functions including scramble, shuffle, constant mapping, character set and bank scrambling. Consistent scrambling logic across multiple databases preserves referential and functional integrity, and a test mode validates results before committing.
Key takeaways
- PostgreSQL has no built-in dynamic masking. PostgreSQL Anonymizer is the established extension.
- Managed services may block extensions, so check before planning.
- Test copies need static masking, never applied to production.
- Mask consistently across systems so links survive.
PostgreSQL data masking, answered
Does PostgreSQL have built-in data masking?
PostgreSQL does not include a built-in dynamic data masking feature. Roles, privileges, views and row-level security restrict access but do not replace sensitive values with realistic substitutes.
What is PostgreSQL Anonymizer?
An open-source PostgreSQL extension, maintained by Dalibo, that lets teams declare masking rules on columns and supports both dynamic masking for designated roles and static masking that rewrites stored values.
Can I use PostgreSQL Anonymizer on a managed PostgreSQL service?
Possibly not. Installing extensions needs elevated privileges that many managed services restrict, so check your provider's supported extensions. Where it is unavailable, masking is typically done outside the database.
How should PostgreSQL test and development data be masked?
With static masking applied to the copy, never to production, so the copy holds no real sensitive values. Include free-text and JSON columns, and keep masking consistent with connected systems.
Ready to transform your data migration?
See how deKorvai can simplify your S/4HANA transformation program.
Book a Demo