63 / 65 · 15 SQL & Database Testing · Data Masking and Anonymization← prev⊞ allnext →☰ Read as one page
8.7Masking Tools
| Tool | Type | Best For |
|---|---|---|
| pg_anonymize | PostgreSQL extension | Simple rules-based masking |
| Delphix | Enterprise platform | Large-scale, automated masking |
| DataMasker | Commercial tool | SQL Server and Oracle |
| Faker (Python/JS) | Library | Generating fake data for test environments |
| Custom scripts | DIY | Full control over masking logic |
Simple Masking with Faker
from faker import Faker
fake = Faker()
def mask_users_table(source_conn, target_conn):
source = source_conn.cursor()
target = target_conn.cursor()
source.execute("SELECT id, name, email, phone FROM users")
for row in source.fetchall():
target.execute(
"INSERT INTO users (id, name, email, phone) VALUES (%s, %s, %s, %s)",
(row[0], fake.name(), fake.email(), fake.phone_number())
)
target_conn.commit()