Postgresql how to compare the tables which are present in different database

postgresqlpostgresql-9.4

How can I compare the data which is present in different database in postgresql.

For example, I have 2 databases db1 & db2

Both have the same tables like tb1 tb2 tb3

I want to compare which table has different record.

Best Answer

you could use the postgres_fdw to link the 2 dbs together and execute queries to compare the different tables as if they we're in the same db.

see the documentation on postgres_fdw for examples.
Note, this requires that you will be able to connect from one db to the other remotely. and queries might be resource intensive (as you are basically pulling the data of the remote table over the wire)