Skip to main content

PostgreSQL utilities

Project description

travis-badge license-badge pypi-badge downloads-badge

This package contains two tools for backing up PostgreSQL database dumps.

Installing

To install in a virtualenv or globally as a superuser:

pip install pgtricks

To install only for the current user:

pip install --user pgtricks

pg_dump_splitsort

pg_dump_splitsort is a handy script for pre-processing PostgreSQL’s pg_dump output to make it more suitable for diffing and storing in version control.

Usage:

pg_dump_splitsort <filename>.sql

The script splits the dump into the following files:

0000_prologue.sql: everything up to the first COPY
0001_<schema>.<table>.sql
:
:
NNNN_<schema>.<table>.sql: COPY data for each table sorted by the first field
9999_epilogue.sql: everything after the last COPY

The files for table data are numbered so a simple sorted concatenation of all files can be used to re-create the database:

$ cat *.sql | psql <database>

I’ve found that a good way to take a quick look at differences between dumps is to use the meld tool on the whole directory:

$ meld old-dump/ new-dump/

Storing the dump in version control also gives a decent view on the differences. Here’s how to configure git to use color in diffs:

# ~/.gitconfig
[color]
        diff = true
[color "diff"]
        frag = white blue bold
        meta = white green bold
        commit = white red bold

Note: If you have created/dropped/renamed tables, remember to delete all .sql files before post-processing the new dump.

pg_incremental_backup

The pg_incremental_backup script

  • makes a database dump using pg_dump

  • splits the dump into per-table files using pg_dump_splitsort

  • creates or commits changes into a local Git repository containing the dump

  • pushes the changes to the remote repository

Usage:

pg_incremental_backup [-h] [--output-dir OUTPUT_DIR] database [remote]

positional arguments:
  database
  remote

optional arguments:
  -h, --help            show this help message and exit
  --output-dir OUTPUT_DIR, -o OUTPUT_DIR

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgtricks-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

pgtricks-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pgtricks-1.0.0.tar.gz.

File metadata

  • Download URL: pgtricks-1.0.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.0

File hashes

Hashes for pgtricks-1.0.0.tar.gz
Algorithm Hash digest
SHA256 026f956758b6cc10264978300b8603b60de84d295b50d099cc7db2379927782c
MD5 757d7baaa6cf999170a09ccc6a6b3f2b
BLAKE2b-256 ed69629aadf947e5b7641e6185415058705f2c6d08f524b2f3d9d858d3a89b52

See more details on using hashes here.

File details

Details for the file pgtricks-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pgtricks-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.0

File hashes

Hashes for pgtricks-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 215f7fdbbaef41ec14b95d73720ed37ddc8cb014b8dd3a3bc4d0cb55dae422dc
MD5 c7dde273798b517f01e4863e45cb2106
BLAKE2b-256 524fe8d35746dd1c80f7017c9e27233cb4333db707b7b65526b166d59a434bd2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page