pgdiff
Overview
This pgdiff gem compares two PostgreSQL databases and generates SQL statements to update the source database to match the target datbase.
The script detects differences in:
* Schemas
* Extensions
* Domains
* Tables
* 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:
gem install pgdiff
Usage
To use pgdiff open a command prompt and runn the following command:
pg_diff --source "source_connection_string" --target "destination_connection_string"
The format of the connection strings are documented in the Ruby PG gem at www.rubydoc.info/gems/pg/PG/Connection.new.
For eample:
"host=localhost dbname=a_database user=a_user password=a_password"
Ignore Schemas
By default, pgdiff will not process the following system schemas:
* pg_catalog
* pg_toast
* information_schema
You may specify additions schemas to ingore using the ‘–ingore-schemas` flag:
pgdiff --ignore_schemas=schema1,schema2
Output
By default, pgdiff will output results to stdout. You may also specify a file path via the ‘–output` command line parameter:
pgdiff --ouput=/tmp/diff.sql
You can then run this sql script against your database.
Run The Script
The sql script generated by pgdiff will change your database. It is YOUR responsibility to verify the script before running it. pgdiff may have bugs, which could result in catastrophic, unrecoverable changes to your database. DO NOT RUN THIS ON A PRODUCTION DATABASE WITHOUT BACKING UP AND TESTING FIRST.
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.