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
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:)
You need to install postgresql
firstly, because pg_diff
will use
psycopg2
to execute some commands.
pip install pg_diff
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.
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.
- Fork the repository on GitHub.
- Make a branch off of master and commit your changes to it.
- Run the tests with
tox
- Either use
tox
to build against all supported Python versions (if you have them installed) or usetox -e py{version}
to test against a specific version, e.g.,tox -e py27
ortox -e py33
.
- 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.
MIT Lisence