I'm working on the same databse schema on different machines (PostgreSQL). I would like to know, how to merge data from one machine to another. Schema has many tables (around 10). What I want to achieve?
- Dump data from machine A to file A.dmp
- Restore data from file A.dmp to machine B
- When a record already exists in machine B, I would like to don't insert it into machine B.
I was trying dump data from machine A to simple SQL inserts commands, but when I'm trying to restore it, I am getting duplicate key errors. What is more, I would like to restore data from command line (I have to import 250 MB data), because now I'm trying to do it manually with pgAdmin.
What is the best way to do it?
insert into schema1.table1 select * from schema2.table1
? – Christelchristeninsert into schema1.table1 dst select * from schema2.table1 WHERE NOT EXISTS (SELECT * FROM schema2.table1 nx WHERE nx.pk = dst.pk);
PLUS: in the correct "topological" order to allow FKs to be populated before being referenced. Note: there might be smarter ways to do it, but for only ten tables it is not too much work IMO) – Chancelor