Package: pganonymize
A commandline tool to anonymize PostgreSQL databases for DSGVO/GDPR purposes.It uses a YAML file to define which tables and fields should be anonymized and provides various methods of
anonymization. The tool requires a direct PostgreSQL connection to perform the anonymization.ContentsFeaturesInstallationUsageDatabase dumpDockerFeaturesIntentionally compatible with Python 2.7 (for old, productive platforms)Anonymize PostgreSQL tables on data level entry with various providers (some examples in the table below)Exclude data for anonymization depending on regular expressions or SQLWHEREclausesTruncate entire tables for unwanted dataFieldValueProviderOutputfirst_nameJohnchoice(Bob|Larry|Lisa)titleDr.clearstreetIrving Stfaker.street_nameMiller Stationpassworddsf82hFxcMmaskXXXXXXXXXXcredit_card1234-567-890partial_mask1??????????0emailjane.doe@example.commd50cba00ca3da1b283a57287bcceb17e35emailjane.doe@example.comfaker.unique.emailalex7@sample.comphone_num65923473md5as_number: True3948293448ip157.50.1.20set127.0.0.1uuid_col00010203-0405-……uuid4f7c1bd87-4d….Note:faker.unique.[provider]only supported on Python 3.6+ (Faker library min. supported python version)Note:uuid4- only for (nativeuuid4) columnsSee thedocumentationfor a more detailed description of the provided anonymization methods.InstallationThe default installation method is to usepip:$ pip install pganonymizeUsageusage: pganonymize [-h] [-v] [-l] [--schema SCHEMA] [--dbname DBNAME]
               [--user USER] [--password PASSWORD] [--host HOST]
               [--port PORT] [--dry-run] [--dump-file DUMP_FILE]

Anonymize data of a PostgreSQL database

optional arguments:
-h, --help            show this help message and exit
-v, --verbose         Increase verbosity
-l, --list-providers  Show a list of all available providers
--schema SCHEMA       A YAML schema file that contains the anonymization
                        rules
--dbname DBNAME       Name of the database
--user USER           Name of the database user
--password PASSWORD   Password for the database user
--host HOST           Database hostname
--port PORT           Port of the database
--dry-run             Don't commit changes made on the database
--dump-file DUMP_FILE
                        Create a database dump file with the given name
--init-sql INIT_SQL   SQL to run before starting anonymizationDespite the database connection values, you will have to define a YAML schema file, that includes
all anonymization rules for that database. Take a look at theschema documentationor theYAML sample schema.Example calls:$ pganonymize --schema=myschema.yml \
    --dbname=test_database \
    --user=username \
    --password=mysecret \
    --host=db.host.example.com \
    -v

$ pganonymize --schema=myschema.yml \
    --dbname=test_database \
    --user=username \
    --password=mysecret \
    --host=db.host.example.com \
    --init-sql "set search_path to non_public_search_path; set work_mem to '1GB';" \
    -vDatabase dumpWith the--dump-fileargument it is possible to create a dump file after anonymizing the database. Please note,
that thepg_dumpcommand from thepostgresql-client-commonlibrary is necessary to create the dump file for the
database, e.g. under Linux:$ sudo apt-get install postgresql-client-commonExample call:$ pganonymize --schema=myschema.yml \
    --dbname=test_database \
    --user=username \
    --password=mysecret \
    --host=db.host.example.com \
    --dump-file=/tmp/dump.gz \
    -vDockerIf you want to run the anonymizer within a Docker container you first have to build the image:$ docker build -t pganonymize .After that you can pass a schema file to the container, using Docker volumes, and call the anonymizer:$ docker run \
    -v <path to your schema>:/schema.yml \
    -it pganonymize \
    /usr/local/bin/pganonymize \
    --schema=/schema.yml \
    --dbname=<database> \
    --user=<user> \
    --password=<password> \
    --host=<host> \
    -v