Registry / database / pg-anonymizer

pg-anonymizer

JSON →
library0.8.1jsnpmunverified

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-anonymizer
INSTALL
IMPORT
SIG · PG-ANONYMIZER
P
pg-anonymizer
databasejavascriptv0.8.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import pgAnonymizer from 'pg-anonymizer'
const pgAnonymizer = require('pg-anonymizer')
ESM and CJS both supported (dual package). The default export is the CLI runner.
anonymize
import { anonymize } from 'pg-anonymizer'
const { anonymize } = require('pg-anonymizer')
Named export for programmatic usage; available since v0.6.
types
import type { Config } from 'pg-anonymizer'
TypeScript types are bundled; use import type for type-only imports.

Anonymize a PostgreSQL database export by specifying columns to anonymize, using npx without installation.

npx pg-anonymizer postgres://user:pass@localhost:5432/mydb --columns=email,firstName,lastName --output dump.sql
pg-anonymizer --version
Debug
Known issues
gotchapg_dump must be installed separately; it is not bundled with npm package.
fix
Install PostgreSQL client tools (e.g., apt-get install postgresql-client) or ensure pg_dump is in PATH.
affects: >=0.0.0
breakingv0.6.0 changed default faker from faker.random.word to auto-detection based on column name; custom --columns without faker function now auto-detects.
fix
If you relied on faker.random.word default, specify columns explicitly with ':faker.random.word'.
affects: >=0.6.0 <0.7.0
deprecatedThe --columns option with dot-notation for tables (e.g., public.user.email) may be deprecated in future; prefer using --skip for tables.
fix
Use --skip to exclude tables from anonymization instead of prefixing column names.
affects: >=0.5.0
gotchaUnexpected anonymization of non-sensitive columns: if no --columns specified, a default list of columns (email, name, etc.) is anonymized, potentially including non-sensitive data.
fix
Always specify --columns to avoid accidentally anonymizing unintended columns.
affects: >=0.0.0
gotchaOutput file path is relative to current working directory, not the script location.
fix
Use absolute paths for --output to avoid confusion.
affects: >=0.0.0
deprecatedNode.js >=12 required; Node 10 support dropped in v0.6.0.
fix
Upgrade Node.js to >=12.
affects: >=0.6.0
Errors
Common errors & fixes
pg_dump: command not found
pg_dump is not installed on the system.
fix
Install PostgreSQL client tools (e.g., on Ubuntu: sudo apt-get install postgresql-client).
Error: Cannot find module 'pg-anonymizer'
When using require in an older CJS project without transpilation, but package is ESM-only in some versions.
fix
Use dynamic import() or switch to ESM: 'import pgAnonymizer from "pg-anonymizer"'.
Error: Column 'nonexistent' does not exist in any table
Specified a column name that does not exist in any database table.
fix
Check the column name spelling and ensure it exists in the database.
Upgrade
Version history
0.8.1latest on npm
Audit
Dependencies
pg_dumprequiredRequired system tool for dumping the database; the CLI calls pg_dump internally.
Agent activity
6 hits · last 30 days
node
6
Resources
pg-anonymizer — npm install pg-anonymizer · libregistry