Package: postgres-db-diff
Postgres DB diffCommand line tool to compare two PostgreSQL databases. It is based on parsingpsqlmeta commands output. Such as\dtfor tables and\dvfor
views.https://www.postgresql.org/docs/current/static/app-psql.htmlHow to installThere are two options:Use any python package installing tool. Recommendedpip.Just copy/pastepostgresdbdiff.pyinto your dir and run it usingpython postgresdbdiff.pyUsageusage: postgresdbdiff.py [-h] --db1 DB1 --db2 DB2 [--diff-folder DIFF_FOLDER]

optional arguments:
  -h, --help            show this help message and exit
  --db1 DB1             First DB name
  --db2 DB2             Second DB name
  --diff-folder DIFF_FOLDER
                        Directory to output diffsExampleCreate two DBs. One using this SQL:CREATETABLEtable_a(idINTEGERPRIMARYKEY,test_uniqueVARCHAR(100)UNIQUE,test_not_nullVARCHAR(100)NOTNULL,test_checksINTEGERNOTNULL);CREATETABLEtable_b(idINTEGERPRIMARYKEY,table_a_idintegerREFERENCEStable_a(id));CREATETABLEtable_c(idINTEGERPRIMARYKEY);CREATEVIEWview_aASSELECTid,test_unique,42ASsome_numberFROMtable_a;Other using this SQL:CREATETABLEtable_a(idINTEGERPRIMARYKEY,test_uniqueVARCHAR(100),test_not_nullVARCHAR(100),test_checksINTEGERNOTNULLCHECK(test_checks>0));CREATETABLEtable_b(idINTEGERPRIMARYKEY,table_a_nointegerREFERENCEStable_a(id));CREATEVIEWview_aASSELECTid,test_uniqueFROMtable_a;Then run this commandpython postgresdbdiff.py --db1 diff_a --db2 diff_b --diff-folder diffsOutput should be like thisTABLES: additional in "diff_a"
  table_c

TABLES: not matching
  table_a
  table_b

VIEWS: not matching
  view_aAnd there should be the folder nameddiffswith files looking like this# diffs/table_a.diff--- TABLES.diff_a.table_a+++ TABLES.diff_b.table_a@@ -1,12 +1,13 @@Table "public.table_a"Column     |          Type          | Collation | Nullable | Default---------------+------------------------+-----------+----------+---------id            | integer                |           | not null |test_checks   | integer                |           | not null |- test_not_null | character varying(100) |           | not null |+ test_not_null | character varying(100) |           |          |test_unique   | character varying(100) |           |          |Indexes:"table_a_pkey" PRIMARY KEY, btree (id)-    "table_a_test_unique_key" UNIQUE CONSTRAINT, btree (test_unique)+Check constraints:+    "table_a_test_checks_check" CHECK (test_checks > 0)Referenced by:-    TABLE "table_b" CONSTRAINT "table_b_table_a_id_fkey" FOREIGN KEY (table_a_id) REFERENCES table_a(id)+    TABLE "table_b" CONSTRAINT "table_b_table_a_no_fkey" FOREIGN KEY (table_a_no) REFERENCES table_a(id)# diffs/table_b.diff--- TABLES.diff_a.table_b+++ TABLES.diff_b.table_b@@ -1,9 +1,9 @@Table "public.table_b"Column   |  Type   | Collation | Nullable | Default------------+---------+-----------+----------+---------id         | integer |           | not null |- table_a_id | integer |           |          |+ table_a_no | integer |           |          |Indexes:"table_b_pkey" PRIMARY KEY, btree (id)Foreign-key constraints:-    "table_b_table_a_id_fkey" FOREIGN KEY (table_a_id) REFERENCES table_a(id)+    "table_b_table_a_no_fkey" FOREIGN KEY (table_a_no) REFERENCES table_a(id)# diffs/view_a.diff--- VIEWS.diff_a.view_a+++ VIEWS.diff_b.view_a@@ -1,6 +1,5 @@View "public.view_a"Column    |          Type          | Collation | Nullable | Default-------------+------------------------+-----------+----------+---------id          | integer                |           |          |- some_number | integer                |           |          |test_unique | character varying(100) |           |          |