pg-anonymizer is a CLI tool (built with oclif) that exports a PostgreSQL database and anonymizes sensitive columns using faker.js. It wraps pg_dump and replaces data on the fly. Current stable version 0.8.1, released Feb 2024, with ~5 releases per year. Key differentiators: no database installation, works as a pipe, supports custom faker functions, extension files, and config files. Alternative to pg_dump with custom scripts or postgresql_anonymizer, but simpler and portable.
npm install pg-anonymizerVerified import paths — ran on the pinned version, not inferred.
Anonymize a PostgreSQL database export by specifying columns to anonymize, using npx without installation.
Install PostgreSQL client tools (e.g., apt-get install postgresql-client) or ensure pg_dump is in PATH.
If you relied on faker.random.word default, specify columns explicitly with ':faker.random.word'.
Use --skip to exclude tables from anonymization instead of prefixing column names.
Always specify --columns to avoid accidentally anonymizing unintended columns.
Use absolute paths for --output to avoid confusion.
Upgrade Node.js to >=12.
Install PostgreSQL client tools (e.g., on Ubuntu: sudo apt-get install postgresql-client).
Use dynamic import() or switch to ESM: 'import pgAnonymizer from "pg-anonymizer"'.
Check the column name spelling and ensure it exists in the database.