pgdiff

Overview

This ruby gem provides a pgdiff script that compares two PostgreSQL databases and generates SQL statements to make their structures the same. The original version was posted at www.dzone.com/snippets/pgdiff-compare-two-postgresql.

The script detects differences in:

* Domains
* Schemas
* Tables
* Table field order
* Sequences
* Views
* Constraints
* Indices
* Functions
* Triggers
* Rules

Two objects with the same name are considered equal if they have the same definitions.

pgdiff does not currently compare ownership, user rights, object dependencies, table inheritance, type casts, aggregates or operators. Patches are welcome to add this functionality.

Installation

Install pgdiff using Ruby Gems:

gem install "pgdiff"

Usage

To use pgdiff open a command prompt and runn the following command:

pg_diff "source_connection_string" "destination_connection_string"

The format of the two connection strings is documented in the Ruby pg gem. For more information see www.rubydoc.info/gems/pg/PG/Connection:initialize

Output

pgdiff will output the necesssary sql statements to update the source database to have the same structure as the destination database. PLEASE VERIFY the accuracy of the generated sql statements before running them, it is always possible the script has bugs.

Support

If you have any questions or want to contribute to pgdiff please visit github.com/cfis/pgdiff.git

License

pgdiff is provided under the MIT license.