Skip to main content
Build status

This tool allows to extract data from a PostgreSQL database with greater flexibility that tools like pg_dump allow.

pg_seldump reads one of more dump definitions from YAML files and selects what tables or other database objects to save. It is possible to extract only certain columns of the tables, only certain records, or to replace certain values with a different expression, for instance to anonymize data.

The output of the program is a text file which can be used by psql to restore data into a database with a complete schema but with no data (or at least no conflicting data), e.g. using:

$ pg_seldump --dsn="dbname=sourcedb" datadump.yaml > dump.sql
...
$ psql -1X --set ON_ERROR_STOP=1 -f dump.sql "dbname=targetdb"

Program usage

Usage:

pg_seldump [-h] [--version] [--dsn DSN] [--outfile OUTFILE] [--test]
           [-q | -v]
           config [config ...]

Create a selective dump of a PostgreSQL database.

positional arguments:
  config                yaml file describing the data to dump

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --dsn DSN             database connection string [default: '']
  --outfile OUTFILE, -o OUTFILE
                        the file where to save the dump [default: stdout]
  --test                test the configuration to verify it works as expected
  -q, --quiet           talk less
  -v, --verbose         talk more

The config files must be YAML files containing a db_objects list of entries. Each entry may have:

Selectors (all the specified ones must match):

  • name: name of the db object to dump

  • names: list of names or regex of db objects to dump

  • schema: schema name of the db object to dump

  • schemas: list of schema names or regexp to match schema names of the db object to dump

  • kind: kind of object to match. Can be:

    • table

    • sequence

    • paritioned table

    • materialized view

  • kinds: list of kind of objects to match (like for kind)

  • adjust_score: adjustment for the match score to break rules ties

Data modifiers:

  • action: what to do with the matched object:

    • dump: dump the object in the output (default)

    • skip: don’t dump the object

    • error: raise an error in case of match (useful to create strict descriptions where all the db objects must be mentioned explicitly)

  • no_columns: list of columns names to omit

  • filter: WHERE condition to include only a subset of the records in the dump

  • replace: mapping from column names to SQL expressions to replace values into the dump with somethings else

The objects in the database are matched to the rules in the config files. Every match will have a score according to how specific was the selector matched the object.

  • name or names list: 1000

  • names regexp: 500

  • schema or schemas list: 100

  • schemas regexp: 50

  • kind or kinds: 10

The rule with the highest score will apply. If two rules have exactly the same score the program will report an error: you can use adjust_score to break the tie.

Metadata

Release files for pg-seldump 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pg-seldump 0.3.3
File Size Uploaded
pg_seldump-0.3.3.tar.gz 29.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pg-seldump 0.3.3
File Interpreter ABI Platform
pg_seldump-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 57.5 kB

Release files / pg_seldump-0.3.3.tar.gz

Download URL pg_seldump-0.3.3.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8977c757f5ed9ade477aea9aaeba8d905cd6c18126ddf50f1d540187b0589ef1
BLAKE2b-256 checksum
How to use checksums
fc7534d08752acb80a0aa4f896b1ef46feb7c7352c42a543ebf426187c0e5d87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / pg_seldump-0.3.3-py3-none-any.whl

Download URL pg_seldump-0.3.3-py3-none-any.whl
Size 28.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
009934ff03027312e355d23117ea71532707f4269edca8a7327bfa76de99f01d
BLAKE2b-256 checksum
How to use checksums
ec91ce7e8157a07f817b6c412b6332772dfe5784cce821f42e940bf43efe4826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page