Skip to main content
Version: Next

Configuration

The configuration is organized into six sections:

  • common — settings that can be used for both the dump and restore commands
  • log — settings for the logging subsystem
  • storage — settings for the storage locations where dumps are stored
  • dump — settings for the dump command. This section includes pg_dump options and transformation parameters.
  • restore — settings for the restore command. It contains pg_restore options and additional restoration scripts.
  • custom_transformers — definitions of the custom transformers that interact through stdin and stdout. Once a custom transformer is configured, it becomes accessible via the greenmask list-transformers command.

Environment Variables in Configuration​

Greenmask supports inline environment variable interpolation in YAML configuration file values using POSIX Parameter Expansion syntax. This lets you store config files in version control without hardcoding secrets or environment-specific values.

Syntax​

SyntaxDescription
${VAR} or $VARReplaced with the value of VAR; empty string if VAR is unset.
${VAR:-default}Replaced with the value of VAR, or "default" if VAR is unset or empty.
${VAR-default}Replaced with the value of VAR, or "default" if VAR is unset (but not if empty).
${VAR:-}Replaced with an empty string when VAR is unset or empty (explicit empty default).
${VAR?message}Replaced with the value of VAR; Greenmask exits with message if VAR is unset.
$$VAREscape sequence — produces the literal string $VAR without any env lookup.

Example​

config with environment variable interpolation
log:
level: ${LOG_LEVEL:-info}
format: ${LOG_FORMAT:-text}

storage:
type: "s3"
s3:
endpoint: "${S3_ENDPOINT:-http://localhost:9000}"
bucket: "${S3_BUCKET?S3 bucket name must be set}"
region: "${AWS_REGION:-us-east-1}"
access_key_id: "${AWS_ACCESS_KEY_ID?AWS access key ID must be set}"
secret_access_key: "${AWS_SECRET_ACCESS_KEY?AWS secret access key must be set}"

dump:
pg_dump_options:
dbname: "host=${DB_HOST:-localhost} user=${DB_USER:-postgres} dbname=${DB_NAME:-mydb}"

Notes​

  • Interpolation is applied to all string values in the config during unmarshaling.
  • Transformer params values are parsed separately (to preserve key casing) and are not subject to env var interpolation by default. To enable interpolation for a specific transformer, set resolve_env: true on it — see Parameters env vars interpolation for details and examples.
  • Variable values that contain YAML special characters (:, {, }, #, etc.) should be enclosed in quotes in the config file to avoid YAML parsing errors.
  • The existing behavior of overriding whole config keys via environment variables (e.g., setting LOG_LEVEL=debug to override log.level) is preserved and unaffected by this feature.
warning

To apply env vars interpolation to transformer parameters, set resolve_env: true on the specific transformer. By default it is false — parameter values containing $ are treated as plain strings, which prevents accidental expansion of literal dollar signs that may appear in stored data or config values. See Parameters env vars interpolation for details and examples.

tip

Use ${VAR?your error message} to mark a variable as required. Greenmask will exit with the provided message if the variable is not set, making misconfiguration errors explicit and easy to diagnose.

common section​

In the common section of the configuration, you can specify the following settings:

  • pg_bin_path — path to the PostgreSQL binaries. Note that the PostgreSQL server version must match the provided binaries.
  • tmp_dir — temporary directory for storing the table of contents files. Default value is /tmp
  • timezone — time zone in which dump and validate read timestamptz values from the data. It affects everything that depends on the local date and time of a value, for example truncate in NoiseDate and templates that use truncateDate or read fields such as the year or hour. The value written to the dump is the same instant in any zone. Use a case-sensitive IANA name, such as UTC or Europe/Berlin. Default value is UTC. Can be set with the COMMON_TIMEZONE environment variable. restore does not use it.
note

Greenmask exclusively manages data dumping and data restoration processes, delegating schema dumping to the pg_dump utility and schema restoration to the pg_restore utility. Both pg_dump and pg_restore rely on a toc.dat file located in a specific directory, which contains metadata and object definitions. Therefore, the tmp_dir parameter is essential for storing the toc.dat file during the dumping or restoration procedure. It is important to note that all artifacts in this directory will be automatically deleted once the Greenmask command is completed.

log section​

In the log section of the configuration, you can specify the following settings:

  • level — specifies the level of logging, which can be one of the following: debug, info, or warn. The default level is info.
  • format — defines the logging format, which can be either json or text. The default format is text.

storage section​

In the storage section, you can configure the storage driver for storing the dumped data. Currently, four storage type options are supported: directory, s3, azure and ssh.

The directory storage option refers to a filesystem directory where the dump data will be stored.

Parameters include path which specifies the path to the directory in the filesystem where the dumps will be stored.

directory storage config example
storage:
type: "directory"
directory:
path: "/home/user_name/storage_dir" # (1)

Client-side encryption​

With storage.encryption.key set, greenmask dump encrypts the objects of the new dump on the host, before they are sent to the storage, with age and one X25519 key. It works with every storage type and is off by default.

What is encrypted and what is not:

  • Encrypted: every object in the dump directory except the two below, including metadata.json, toc.dat and the table data files.
  • Not encrypted: encryption.json, which holds the public key the dump is encrypted to, and heartbeat, which holds only whether the dump is in progress or done, so that list-dumps and delete work without the key. The names, sizes and modification times of the objects, and their number, are not encrypted either.
ParameterDescription
keyThe age identity, AGE-SECRET-KEY-1.... When it is set, new dumps are encrypted to it and encrypted dumps are read with it; without it, encryption is off. Prefer the STORAGE_ENCRYPTION_KEY environment variable to a key in the config file

Generate a key with age-keygen and keep a copy in a safe place:

age-keygen -o key.txt
export STORAGE_ENCRYPTION_KEY="$(grep AGE-SECRET-KEY key.txt)"
client-side encryption config example
storage:
type: "s3"
encryption:
key: "${STORAGE_ENCRYPTION_KEY}"

The STORAGE_ENCRYPTION_KEY variable alone turns encryption on as well, with no encryption section in the config.

A lost key is a lost dump

Greenmask keeps no copy of the key. Without it, an encrypted dump cannot be read by anyone, Greenmask included.

How plain and encrypted dumps live together:

  • The key controls both writing and reading: with it, dump encrypts the new dump. To make plain dumps again and still restore the encrypted ones, run dump without the key and restore with it.
  • Plain and encrypted dumps can share one storage. A dump without encryption.json is plain, and every command reads it as before, with or without a key. Existing dumps are not encrypted in place when you set a key.
  • To change the key, set the new one: new dumps are encrypted to it, and older dumps are read by running Greenmask with the old one.

When a dump cannot be read:

  • With a key that is not the one the dump was encrypted to, restore, show-dump and validate --schema fail with dump is encrypted to another key: age1.... The error names the public key from encryption.json.
  • With no key set, Greenmask reads the storage as it is and knows nothing about encryption, so the same commands fail on an encrypted dump with a metadata parsing error such as cannot decode metadata. list-dumps shows true in the ENCRYPTED column for such a dump: set the key to read it.
  • list-dumps does not fail: it shows the dump's status and true in the ENCRYPTED column, and leaves the date, database, sizes, duration and description empty.
  • delete needs no key. --retain-recent, --retain-for, --before-date and --prune-failed classify an encrypted dump by its heartbeat, like a plain dump, and without the key date it by its ID, the time the dump started. delete <dumpId> deletes it.
  • A key that is not an age X25519 identity fails with invalid encryption key: not an age X25519 identity, before the command touches the storage. The error does not contain the key.

Other things to know:

  • An encrypted dump is not readable by native pg_restore as it lies in the storage. Decrypt each file except encryption.json and heartbeat with age -d, as below, and the result is a regular directory-format dump.
  • While a command runs, the schema is in plain text in common.tmp_dir: pg_dump writes the schema there during a dump, and restore puts toc.dat there. Protect that directory on the host.
  • Client-side encryption differs from the S3 sse option: with sse, S3 encrypts the objects and decrypts them for anyone with read access to the bucket. With client-side encryption, the storage only ever sees ciphertext. The two can be used together.
decrypt a dump for native pg_restore
mkdir plain
for f in <dumpId>/*; do
case "$(basename "$f")" in
encryption.json|heartbeat) ;;
*) age -d -i key.txt -o "plain/$(basename "$f")" "$f" ;;
esac
done
pg_restore -l plain

dump section​

In the dump section of the configuration, you configure the greenmask dump command. It includes the following parameters:

  • pg_dump_options — a map of pg_dump options to configure the behavior of the command itself. You can refer to the list of supported pg_dump options in the Greenmask dump command documentation.

  • transformation — this section contains configuration for applying transformations to table columns during the dump operation. It includes the following sub-parameters:

    • schema — the schema name of the table

    • name — the name of the table

    • subset_conds - list of the conditions to filter the rows to be dumped. The conditions are combined with AND operator. For details read Database subset

    • query — an optional parameter for specifying a custom query to be used in the COPY command. By default, the entire table is dumped, but you can use this parameter to set a custom query.

      warning

      Be cautious when using the query parameter, as it may lead to constraint violation errors during restoration, and Greenmask currently cannot handle query validation.

    • columns_type_override — allows you to override the column types explicitly. You can associate a column with another type that is supported by your transformer. This is useful when the transformer works strictly with specific types of columns. For example, if a column named post_code is of the TEXT type, but the RandomInt transformer works only with INT family types, you can override it as shown in the example provided.

      column type overridden example
      columns_type_override:
      post_code: "int4" # (1)
      1. Change the data type of the post_code column to INT4 (INTEGER)
    • apply_for_inherited — an optional parameter to apply the same transformation to all partitions if the table is partitioned. This can save you from defining the transformation for each partition manually.

      warning

      It is recommended to use the --load-via-partition-root parameter when dealing with partitioned tables, as the partition key value might change.

    • transformers — a list of transformers to apply to the table, along with their parameters. Each transformation item includes the following sub-parameters:

      • name — the name of the transformer
      • params — a map of the provided transformer parameters
      transformers config example
      transformers:
      - name: "RandomDate"
      params:
      min: "2023-01-01 00:00:00.0+03"
      max: "2023-01-02 00:00:00.0+03"
      column: "scheduled_departure"

      - name: "NoiseDate"
      params:
      max_ratio: "01:00:00"
      column: "scheduled_arrival"

Here is an example configuration for the dump section:

dump section config example
dump:
pg_dump_options:
dbname: "host=/run/postgresql user=postgres dbname=demo"
jobs: 10
exclude-schema: "(\"teSt\"*|test*)"
table: "bookings.flights"
load-via-partition-root: true

transformation:
- schema: "bookings"
name: "flights"
query: "select * from bookings.flights3 limit 1000000"
columns_type_override:
post_code: "int4" # (1)
transformers:
- name: "RandomDate"
params:
min: "2023-01-01 00:00:00.0+03"
max: "2023-01-02 00:00:00.0+03"
column: "scheduled_departure"

- name: "NoiseDate"
params:
max_ratio: "01:00:00"
column: "scheduled_arrival"

- name: "RegexpReplace"
params:
column: "status"
regexp: "On Time"
replace: "Delayed"

- name: "RandomInt" # (2)
params:
column: "post_code"
min: "11"
max: "99"

- schema: "bookings"
name: "aircrafts_data"
subset_conds: # (3)
- "bookings.aircrafts_data.model = 'Boeing 777-300-2023'"
transformers:
- name: "Json"
params:
column: "model"
operations:
- operation: "set"
path: "en"
value: "Boeing 777-300-2023"
- operation: "set"
path: "crewSize"
value: 10

- name: "NoiseInt"
params:
ratio: 0.9
column: "range"
  1. Override the post_code column type to int4 (INTEGER). This is necessary because the post_code column originally has a TEXT type, but it contains values that resemble integers. By explicitly overriding the type to int4, we ensure compatibility with transformers that work with integer types, such as RandomInt.
  2. After the type is overridden, we can apply a compatible transformer.
  3. Database subset condition applied to the aircrafts_data table. The subset condition filters the data based on the model column.

Excluding columns from a table dump​

Greenmask has no per-column include or exclude option. A table entry in transformation accepts only schema, name, query, subset_conds, columns_type_override, apply_for_inherited, when and transformers. Every dumped table keeps its full column list, because the schema is restored unchanged and the data is loaded with COPY ... (all non-generated columns) FROM stdin.

To keep a column's values out of the dump, use one of these options instead:

  • Clear or mask the column. Use SetNull for a nullable column, or a masking transformer such as Replace or Hash for a NOT NULL column. greenmask validate warns if a transformer that can produce NULL targets a NOT NULL column.

    drop the values of a column
    transformation:
    - schema: "public"
    name: "users"
    transformers:
    - name: "SetNull"
    params:
    column: "notes"
    - name: "Replace"
    params:
    column: "password_hash"
    value: "redacted"
  • Use a custom query. The query runs as COPY (<query>) TO STDOUT. It must return every non-generated column of the table, in table order and with compatible types, because the restore side expects exactly those columns. You can return NULL or a constant for a column, but you cannot omit it. If the table is part of a subset, Greenmask replaces query with the generated subset query.

    replace a column with NULL in a custom query
    transformation:
    - schema: "public"
    name: "users"
    query: "SELECT id, email, NULL::text AS notes FROM public.users"
  • Skip the table data. Use the exclude-table-data option in pg_dump_options, or the --exclude-table-data flag, to dump the table definition without rows. Use exclude-table to skip the table completely.

    dump the table schema without rows
    dump:
    pg_dump_options:
    exclude-table-data:
    - "public.audit_log"

Generated columns​

Greenmask handles generated (GENERATED ALWAYS AS ... STORED) columns automatically. You do not need to configure anything for them:

  • They are not dumped. Greenmask leaves them out of the table columns, the COPY statements and the subset queries.
  • PostgreSQL computes them again on restore from the restored base columns, for both COPY and --inserts restores.
  • Transformers cannot target them. A transformer whose column is a generated column fails validation with column does not exist. To change a generated value, transform the columns it is computed from.

validate section​

In the validate section of the configuration, you can specify parameters for the greenmask validate command. Here is an example of the validate section configuration:

validate section config example
validate:
tables: # (1)
- "orders"
- "public.cart"
data: true # (2)
diff: true # (3)
rows_limit: 10 # (4)
resolved_warnings: # (5)
- "8d436fae67b2b82b36bd3afeb0c93f30"
table_format: "horizontal" # (7)
format: "text" # (6)
schema: true # (8)
transformed_only: true # (9)
warnings: true # (10)
strict: true # (11)
diff_mode: "values" # (12)
diff_unchanged_threshold: 90 # (13)
  1. A list of tables to validate. If this list is not empty, the validation operation will only be performed for the specified tables. Tables can be written with or without the schema name (e.g., "public.cart" or "orders").
  2. Specifies whether to perform data transformation for a limited set of rows. If set to true, data transformation will be performed, and the number of rows transformed will be limited to the value specified in the rows_limit parameter (default is 10).
  3. Specifies whether to perform diff operations for the transformed data. If set to true, the validation process will find the differences between the original and transformed data. See more details in the validate command documentation.
  4. Limits the number of rows to be transformed during validation. The default limit is 10 rows, but you can change it by modifying this parameter.
  5. A hash list of resolved warnings. These warnings have been addressed and resolved in a previous validation run.
  6. Specifies the format of the transformation output. Possible values are [horizontal|vertical]. The default format is horizontal. You can choose the format that suits your needs. See more details in the validate command documentation.
  7. The output format (json or text)
  8. Specifies whether to validate the current schema with the previous and print the differences if any.
  9. If set to true, transformation output will be only with the transformed columns and primary keys
  10. If set to true then all the warnings will be printed. This only controls printing and does not affect the exit code.
  11. If set to true, the validate command exits with a non-zero code when there are any unresolved warnings (warnings-as-errors). Warnings listed in resolved_warnings are not treated as failures. Useful for CI/CD pipelines.
  12. How diff shows the difference: values (default) prints original and transformed values, summary prints per-column counts only and no value. Applies only with --data and --diff; summary with --data and without --diff is an error. See Summary diff.
  13. With diff_mode: "summary", warn when a transformed column keeps more than this percentage (0-100) of its non-NULL values. Checked only with diff_mode: "summary". Default 90; 100 turns the warning off. With strict: true a warning not listed in resolved_warnings makes validate exit with a non-zero code.

restore section​

In the restore section of the configuration, you can specify parameters for the greenmask restore command. It contains pg_restore settings and custom script execution settings. Below you can find the available parameters:

  • pg_restore_options — a map of pg_restore options that are used to configure the behavior of the pg_restore utility during the restoration process. You can refer to the list of supported pg_restore options in the Greenmask restore command documentation.

  • scripts — a map of custom scripts to be executed during different restoration stages. Each script is associated with a specific restoration stage and includes the following attributes:

    • [pre-data|data|post-data] — the name of the restoration stage when the script should be executed; has the following parameters:
      • name — the name of the script
      • when — specifies when to execute the script, which can be either "before" or "after" the specified restoration stage
      • query — an SQL query string to be executed
      • query_file — the path to an SQL query file to be executed
      • command — a command with parameters to be executed. It is provided as a list, where the first item is the command name.

    Messages a script reports to the server — RAISE NOTICE, RAISE WARNING and friends — are forwarded to the Greenmask log: WARNING at warn level, NOTICE, INFO and LOG at info, DEBUG at debug. They are logged between the executing script and script execution complete entries of the script that produced them.

    Notices raised while dumping or restoring table data (for example by row-level triggers) are logged too, tagged with the worker id. On those connections NOTICE, INFO and LOG are logged at debug so a trigger raising one per row does not flood the log; WARNING stays at warn.

  • insert_error_exclusions — a list of error codes that should be ignored during the restoration process. This is useful when you want to skip specific errors that are not critical for the restoration process.

As mentioned in the architecture, a backup contains three sections: pre-data, data, and post-data. The custom script execution allows you to customize and control the restoration process by executing scripts or commands at specific stages. The available restoration stages and their corresponding execution conditions are as follows:

  • pre-data — scripts or commands can be executed before or after restoring the pre-data section
  • data — scripts or commands can be executed before or after restoring the data section
  • post-data — scripts or commands can be executed before or after restoring the post-data section
Skipped sections skip their scripts

A section's scripts run only when that section is restored. If a section is skipped — for example with --data-only, --schema-only or --section — its scripts are skipped too, and Greenmask logs a warning naming the skipped section and the option that skipped it. With --data-only, put scripts that must run under the data section.

Each stage can have a "when" condition with one of the following possible values:

  • before — execute the script or SQL command before the mentioned restoration stage
  • after — execute the script or SQL command after the mentioned restoration stage

Below you can find one of the possible versions for the scripts part of the restore section:

scripts definition example
scripts:
pre-data: # (1)
- name: "pre-data before script [1] with query"
when: "before"
query: "create table script_test(stage text)"
- name: "pre-data before script [2]"
when: "before"
query: "insert into script_test values('pre-data before')"
- name: "pre-data after test script [1]"
when: "after"
query: "insert into script_test values('pre-data after')"
- name: "pre-data after script with query_file [1]"
when: "after"
query_file: "pre-data-after.sql"
data: # (2)
- name: "data before script with command [1]"
when: "before"
command: # (4)
- "data-after.sh"
- "param1"
- "param2"
- name: "data after script [1]"
when: "after"
query_file: "data-after.sql"
post-data: # (3)
- name: "post-data before script [1]"
when: "before"
query: "insert into script_test values('post-data before')"
- name: "post-data after script with query_file [1]"
when: "after"
query_file: "post-data-after.sql"
  1. List of pre-data stage scripts. This section contains scripts that are executed before or after the restoration of the pre-data section. The scripts include SQL queries and query files.
  2. List of data stage scripts. This section contains scripts that are executed before or after the restoration of the data section. The scripts include shell commands with parameters and SQL query files.
  3. List of post-data stage scripts. This section contains scripts that are executed before or after the restoration of the post-data section. The scripts include SQL queries and query files.
  4. Command in the first argument and the parameters in the rest of the list. When specifying a command to be executed in the scripts section, you provide the command name as the first item in a list, followed by any parameters or arguments for that command. The command and its parameters are provided as a list within the script configuration.

restoration error exclusion​

You can configure which errors to ignore during the restoration process by setting the insert_error_exclusions parameter. This parameter can be applied globally or per table. If both global and table-specific settings are defined, the table-specific settings will take precedence. Below is an example of how to configure the insert_error_exclusions parameter. You can specify constraint names from your database schema or the error codes returned by PostgreSQL. codes in the PostgreSQL documentation.

parameter definition
insert_error_exclusions:

global:
error_codes: ["23505"] # (1)
constraints: ["PK_ProductReview_ProductReviewID"] # (2)
tables: # (3)
- schema: "production"
name: "productreview"
constraints: ["PK_ProductReview_ProductReviewID"]
error_codes: ["23505"]

  1. List of strings that contains postgresql error codes
  2. List of strings that contains constraint names (globally)
  3. List of tables with their schema, name, constraints, and error codes

Here is an example configuration for the restore section:

restore:
scripts:
pre-data: # (1)
- name: "pre-data before script [1] with query"
when: "before"
query: "create table script_test(stage text)"

insert_error_exclusions:
tables:
- schema: "production"
name: "productreview"
constraints:
- "PK_ProductReview_ProductReviewID"
error_codes:
- "23505"
global:
error_codes:
- "23505"

pg_restore_options:
jobs: 10
exit-on-error: false
dbname: "postgresql://postgres:example@localhost:54316/transformed"
table:
- "productreview"
pgzip: true
inserts: true
on-conflict-do-nothing: true
restore-in-order: true

Environment variable configuration​

It's also possible to configure Greenmask through environment variables.

Greenmask will automatically parse any environment variable that matches the configuration in the config file by substituting the dot (.) separator for an underscore (_) and uppercasing it. As an example, the config file below would apply the same configuration as defining the LOG_LEVEL=debug environment variable

config.yaml
log:
level: debug

Secrets are better set this way than in the config file. For example, set the client-side encryption key with STORAGE_ENCRYPTION_KEY, see Client-side encryption.

Global configuration variables​

  • GREENMASK_GLOBAL_SALT - global salt value hex encoded with variadic length, used for the hash engine. For details read Transformation engines section.

Postgres connection variables​

Additionally, there are some environment variables exposed by the dump and restore commands to facilitate the connection configuration with a Postgres database

  • PGHOST - host used to connect to the postgres database
  • PGPORT - port where postgres is exposed
  • PGDATABASE - name of the database to dump/restore
  • PGUSER - username used to connect to the postgres database
  • PGPASSWORD - password used to authenticate to the postgres database
Tools and expertise for reproducible, production-like environments.
Copyright © 2026 Greenmask, Inc.
Privacy Policy