Skip to content

hanks/pg_diff

Repository files navigation

Build Status Coverage Status

pg diff

A simple tool to diff serveral properties of schemas in two postgresql databases.

Now supported diff options are:

  • table_name
  • table_count
  • table_schema
  • row_count
  • table_size
  • index_size
  • table_total_size
  • sequence

Why

Recently I worked on database migration things, and very need a tool to analyze the consistency between source and target database. So I make this tool to some simple comparison, and it looks good to me:)

Prerequisite

You need to install postgresql firstly, because pg_diff will use psycopg2 to execute some commands.

Installation

pip install pg_diff

Usage

pg_diff --type=table_count 'host=source dbname=test user=postgres password=secret port=5432' 'host=target dbname=test user=postgres password=secret port=5432' --verbose

Usage:
  pg_diff --type=T_NAME SOURCE_DSN TARGET_DSN [--verbose]
  pg_diff -h | --help
  pg_diff --version

Arguments:
  SOURCE_DSN     dsn for source database, like "host=xxx dbname=test user=postgres password=secret port=5432"
  TARGET_DSN     dsn for target database, like "host=xxx dbname=test user=postgres password=secret port=5432"

Options:
  --type=T_NAME  Type name to compare in category, valid input likes: table_name, table_count, table_schema, row_count, table size. index size, table_total_size, sequence
  -h --help      Show help info.
  --verbose      Show verbose information.
  --version      Show version.

Implementation

Mainly using libraries below to make this tool:

  • docopt==0.6.2
  • schema==0.6.5
  • deepdiff==2.5.1
  • psycopg2==2.6.2

And I use some SQL to query the status of schema, like table size, index size and etc.

Contribution

  1. Fork the repository on GitHub.
  2. Make a branch off of master and commit your changes to it.
  3. Run the tests with tox
  • Either use tox to build against all supported Python versions (if you have them installed) or use tox -e py{version} to test against a specific version, e.g., tox -e py27 or tox -e py33.
  1. Submit a Pull Request to the master branch on GitHub.

If you’d like to have a development environment for pg_diff, you should create a virtualenv and then do pip install -e . from within the directory.

Lisence

MIT Lisence

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published