To anonymize a database, work on a copy, find every column that holds personal or sensitive data, replace each value with a realistic substitute that nobody can retrieve or trace back to a person, and then prove that the application still runs and that no real value is left. The hard parts are the columns nobody listed (free-text notes, logs, old staging tables), keeping keys consistent across tables, and knowing whether your result counts as anonymous or only pseudonymous under privacy law. This guide is for engineering managers, QA leads, DBAs and compliance owners who need to protect sensitive data while keeping production-like data in development and testing. A copy of production data with real names in a test environment is a data breach waiting to happen, because test environments rarely get production-grade access controls.
What It Means to Anonymize a Database
A database is anonymized when nobody who gets the copy can identify a real person from it, alone or combined with other data they could reasonably obtain. GDPR draws the line in Recital 26: data protection rules do not apply to anonymous information, but "personal data which have undergone pseudonymisation" still count as information about an identifiable person.
For a database copy used in non production environments, database testing or data sharing with a vendor, the primary goal is narrower and practical: keep the schema, data types, formats, row counts and relationships so tests behave like production, and remove the people. A masked customer table should still have names that look like names, emails that pass validation and card numbers in a valid format. None of them should belong to anyone.
Anonymization, Masking, Obfuscation and Pseudonymization
Vendors use these words loosely. If someone asks you to obfuscate a database, check which of these they mean:
| Term | What happens to the value | Reversible? | Typical use |
|---|---|---|---|
| Data masking | Replaced with a realistic substitute in the same format | No, if done as a one-way rewrite | Test, development, vendor access |
| Data obfuscation | Umbrella term: masking, scrambling, nulling, encryption | Depends on the method | General term in tool lists |
| Pseudonymization | Replaced by a consistent pseudonym, linkable with a key or seed | Yes, for whoever holds the key | Analysis that must join records |
| Encryption | Scrambled, readable again with a key | Yes | Data at rest and in transit |
| Anonymization | Transformed so no person can be identified | No | Sharing, research, test copies |
Test teams anonymize databases with data masking because masked data stays usable. Whether masked data reaches the legal bar of anonymous depends on how you mask: consistent, key-based masking that keeps records linkable is closer to pseudonymization. Treat a masked copy as sensitive until your privacy or security team agrees otherwise.
Database Anonymization Techniques
You pick a technique per column, not per database:
- Substitution. Swap names, addresses and company names for values from a dictionary of realistic ones.
- Format-preserving replacement. Re-encode numbers (SSNs, card numbers, phone numbers) so they keep a valid format and pass application checks.
- Partial masking. Keep a prefix or suffix and hide the rest, for example the last four digits of a card. This suits screens and reports, but it leaves part of the original value in place.
- Deterministic pseudonyms. The same input always gives the same output, so a customer masked in one table matches the same customer in another.
- Generalization. Replace an exact value with a range: an age band instead of a birth date, a ZIP prefix instead of a full ZIP code.
- Random values. Replace a number or a date with a random value from a range, when tests need a plausible value and nothing more.
- Noise. Shift numbers and dates by a random amount within a ratio or interval, which keeps distributions close to the original.
- Nulling or deletion. Remove a column the tests do not need. It is the safest option for any column no test reads.
How to Anonymize a Database Step by Step
The masking commands follow the PostgreSQL Anonymizer and Microsoft SQL Server documentation. The discovery and validation queries are plain SQL for you to adapt to your schema. The same order of steps applies to Oracle and MySQL.
- Restore a copy into an isolated environment. Never run a masking job against production. Restore a backup into a network segment that test users can reach and production users cannot, and limit access to the restored copy until masking finishes.
- Find the sensitive data. Protecting sensitive information starts with data discovery: check column names first and then scan content, because sensitive information hides in columns with neutral names.
SELECT table_schema, table_name, column_name, data_type FROM information_schema.columns WHERE lower(column_name) LIKE '%name%' OR lower(column_name) LIKE '%mail%' OR lower(column_name) LIKE '%phone%' OR lower(column_name) LIKE '%ssn%' OR lower(column_name) LIKE '%birth%' OR lower(column_name) LIKE '%addr%' ORDER BY table_schema, table_name;A name scan misses comments, notes and ticket bodies. In PostgreSQL, a regex scan shows how many rows carry SSN-like or email-like strings:
SELECT count(*) FROM support_ticket WHERE body ~ '\d{3}-\d{2}-\d{4}' OR body ~* '[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}'; - Choose a method for each column and write it down. A masking plan lists table, column, technique and owner. Use the same rule for the same kind of value everywhere, so
customer.emailandinvoice.emailmask to the same address. - Run the data masking on the copy. With the PostgreSQL Anonymizer extension, you declare rules as security labels and then rewrite the data in place:
CREATE EXTENSION IF NOT EXISTS anon CASCADE; SELECT anon.init(); SECURITY LABEL FOR anon ON COLUMN customer.full_name IS 'MASKED WITH FUNCTION anon.dummy_name()'; SECURITY LABEL FOR anon ON COLUMN customer.zipcode IS 'MASKED WITH FUNCTION anon.random_zip()'; SECURITY LABEL FOR anon ON COLUMN customer.email IS 'MASKED WITH FUNCTION anon.dummy_safe_email()'; SELECT anon.anonymize_database(); ANALYZE;The project's documentation warns that these methods "will destroy the original data", which is the point on a copy and a disaster on production.
dummy_*functions are random fakes, not deterministic ones, so the same customer can get different addresses in different tables. For a value that must match in several tables, such ascustomer.emailandinvoice.emailfrom step 3, the documentation offersseeded_*functions that return the same fake value for the same seed, for exampleanon.seeded_email(users.login). - Validate the result. Check that relationships survived and that no real values are left. Orphaned rows after masking mean a key was masked differently in two places:
SELECT count(*) AS orphan_orders FROM orders o LEFT JOIN customer c ON c.id = o.customer_id WHERE c.id IS NULL;Then run the discovery scan from step 2 again and compare counts, run the application's smoke tests against the copy, and keep the output as evidence for the audit.
- Automate the refresh. Teams refresh test environments from production on a schedule. Put the masking job in the refresh pipeline, so nobody can hand out an unmasked copy, and rerun discovery on each refresh to catch new tables.
Pitfalls That Leave Sensitive Data Behind
- Free-text columns. Support notes, comments and XML or JSON payloads carry names, phone numbers and card numbers that column-name rules never see.
- Indirect identifiers. A ZIP code, a birth date and a gender together can single out a person, even after the name is gone, so re-identification risk stays.
- Keys and secrets stored with the copy. If the salt or key that produced your pseudonyms travels with the database, anyone with the copy can re-identify records. PostgreSQL Anonymizer's documentation asks you to protect the salt at the same level as the source data.
- Inconsistent rules across systems. If the CRM and the billing database mask the same customer differently, integration tests fail and testers start asking for real data.
- Unique constraints. Deterministic functions can produce collisions: two different originals masked to the same value break a unique index. PostgreSQL Anonymizer's docs recommend a fake dataset much larger than the table to avoid this.
- Copies made before masking. Backups, Data Pump or pg_dump export files, and staging tables created during the refresh hold the original data. Delete or encrypt them on the same schedule as the copy.
- Triggers and audit tables. A trigger that fires on update can copy the old value into a history table, so check triggers before you mask in place.
- Slow jobs on large datasets. If the masking job does not fit into the refresh window, someone will skip it. Measure throughput on a realistic volume before you commit to a tool.
- Dynamic masking mistaken for anonymization. SQL Server's dynamic data masking leaves stored data unchanged, and admins with CONTROL see everything, as do authorized users with UNMASK.
A dynamic mask in SQL Server is one statement:
ALTER TABLE Data.Membership
ALTER COLUMN Email
ADD MASKED WITH (FUNCTION = 'email()');
That rule shows aXXX@XXXX.com to users without the UNMASK permission. Microsoft's documentation also shows how a user with ad hoc query rights can infer a masked salary with range queries. An export made by a user without UNMASK does contain masked values, but the masks come from a few built-in functions (xxxx for strings, aXXX@XXXX.com for email, a random number in a range, a partial string), not from rules you write, and every column without a mask stays as it was. The real data remains visible to anyone who holds UNMASK or CONTROL. Dynamic masking helps in production, but it is not a substitute for a masked copy built with your own rules.
Database Anonymization Tools Compared
Database obfuscation tools fall into three groups: features built into one database engine, extensions, and data masking software that masks sensitive data in several databases with one set of rules. Because many tools cover only part of the job, the table compares four options by where the masking runs. Facts come from vendor documentation read on 3 December 2026.
| Tool | Databases | Static or dynamic | Where masking runs |
|---|---|---|---|
| PostgreSQL Anonymizer | PostgreSQL | Static and dynamic, plus anonymous dumps | Inside PostgreSQL, as an extension |
| SQL Server dynamic data masking | SQL Server 2016 and later, Azure SQL | Dynamic only; stored data unchanged | In query results |
| Oracle Data Masking and Subsetting | Oracle; other databases through Oracle Database Gateways | Static only | In-Database mode, or In-Export during a Data Pump export |
| Datasan by PFLB | Oracle, PostgreSQL, SQL Server, MySQL | Static and dynamic | Inside the database, as a SQL package |
Another tool can be the better choice than Datasan:
- Your estate is PostgreSQL only and the developers who know the data model will write and review masking rules in SQL: PostgreSQL Anonymizer keeps those rules in the schema, and its source code is public on GitLab.
- You only need to hide columns from some users of a production SQL Server and do not need a test copy: dynamic data masking is built into the engine.
- You run Oracle with Enterprise Manager and already license the Data Masking and Subsetting pack: Oracle data masking also subsets data. Our K2view vs Oracle comparison covers that case.
- You want masking inside a wider data platform that also handles integration and pipelines: look at K2view or Informatica. See our K2view alternatives and Informatica Cloud Data Masking alternatives.
For a longer shortlist, read our review of data masking tools. If you would rather have engineers build the masking plan and wire it into your environment refresh, our test data management team does that work.
Talk to Our Test Data Engineers
How Datasan Does It
Datasan is the data masking tool PFLB builds for organizations with Oracle, PostgreSQL, SQL Server and MySQL. It follows the same steps as above, with the manual parts automated:
- Profile. Dictionaries, regex rules and an AI model find personally identifiable information, even in free text such as comments and notes. Identification works on content, not only on column names.
- Review. Each PII column gets a masking method, and you approve the plan in the UI.
- Mask in place. The Datasan core runs inside the database as a SQL package, so data is not exported to an ETL server. Names are swapped for new ones from dictionaries, numbers are re-encoded in a valid format, and the same original value is masked the same way in every table, so keys and joins still match.
- Report. Tables are processed in parallel threads at 1,000,000+ table rows per minute. Each run ends with a report of tables, rows processed, errors and values left unmasked, and a stopped run resumes where it stopped.
Datasan also does dynamic data masking: it masks values on the fly, in transit, so each consumer sees only what its role allows while production data stays untouched. When a new table with PII appears, Datasan adds it to the profile and masks it like the rest.
A top-20 bank used Datasan to mask a 40 TB Oracle database in 38 hours; the bank case study describes the setup. PFLB has worked with 300+ companies since 2008 and is SOC 2 Type II certified.
Database Anonymization FAQ
What is the difference between anonymization and data masking?
Anonymization is the goal: data that no longer identifies a person. Data masking is a technique to get there, by replacing real values with realistic substitutes. Masking that keeps records linkable through a key or seed is closer to pseudonymization, so check the method before you call a masked copy anonymous.
Is masked data still personal data under data privacy regulations like GDPR?
It depends on whether anyone can re-identify people from it with means reasonably likely to be used. GDPR Recital 26 says pseudonymised data is still personal data, while anonymous data is out of scope. Masking supports compliance with GDPR, HIPAA, CCPA and PCI DSS, but compliance depends on your full set of controls.
Can I anonymize a production database in place?
Not with static masking: it rewrites the stored values for good. Run static masking on a restored copy. In production, use dynamic data masking to limit what each role sees, and keep the original data intact.
Does SQL Server dynamic data masking anonymize the database?
No. Microsoft's documentation states that the data in the database is not changed, administrators can see unmasked values, and users who can run ad hoc queries can infer masked values. An export by a user without UNMASK carries masks from a few built-in functions, not from your own rules, and columns without a mask stay readable. For a test copy that you control, use static masking with your own rules on a restored copy.
How do I keep foreign keys working after masking?
Mask the same original value the same way in every table and every database, either with deterministic functions such as the seeded functions of PostgreSQL Anonymizer or with a tool that applies one rule set across systems. Then run orphan-row queries on each foreign key before you release the copy.
What should I look for in a data masking tool?
Check five things: which databases it supports, whether it does static and dynamic masking, whether the same value masks the same way in every table, whether discovery covers free text and not only column names, and whether it runs inside the database or exports data to another server. Ask for a run report you can keep as audit evidence, and test throughput on large datasets before you buy.
What are database obfuscation tools?
Database obfuscation tools hide or replace sensitive values in a database. The group includes built-in features such as SQL Server dynamic data masking, extensions such as PostgreSQL Anonymizer, and products such as Datasan, Oracle Data Masking and Subsetting, K2view and Informatica.
Which databases does Datasan support?
Oracle, PostgreSQL, Microsoft SQL Server and MySQL. The same masking rules apply across all four, so a customer masked in one system is masked the same way in another.






