Postgresql – Copying Tables (partly replicating) databases remotely

copypostgresql-9.4

I am having hard time figuring out a possible solution copying data from a tables to another.

I have 2 databases
(DB1 and DB2).

DB1 and DB2 has the following tables (eg):

  1. Product
  2. Contacts
  3. Sales

Copying Part,

When a data is inserted, updated to DB1 product tables, it has to be copied to DB2 also.

However,
if DB2 product table is inserted / updated, it should not reflect to DB1 (i assume this might not be a issue).

Further Complication:

If in DB2 Sales table, if new data is inserted/updated, it has to be copied to DB1 and DB1 can make changes and update the table which should reflect to DB2.

I have very less experience with database, although i am using it for quite frequently but have not attempted to do this sort of work, i am finding this a bit complicated. I attempted to look few of the Tutorials, videos. There are techniques using replications, hot standby, which is good but not suitable for my case.

Is it possible to do this thing, i am sure there are tools but i am not sure which tools is very useful for my case? Any suggestions or help is much appreciated.

AFAIK, if we can sync between 2 different database we need to use GUID / UUID (i have used this for one way replication). For this case i use a python server calculate and do the transaction. to retrieve about 10000 records it takes around 5-10 minutes which is tediously slow and useless for my new case. My new case might need to retrieve more than 100 thousan records at a time.

Any suggestions i much appreciated. I am just looking forward for some sign of hope as i could not google any solution.

Best Answer

Create 2 DBLinks between the 2 databases(DB1 to DB2 and vice versa), and use these links to insert/update data by creating triggers for insert/update for the tables.