I have two databases running on the same PostgreSQL 9.3 server (running on Windows). The two databases have the very same structure: same tables, same keys, same constraints, etc; the only difference is that data gets periodically moved from one to the other. Think of it like a database with info on clients and orders, where every week data related to clients older than, say, 2 years is moved from one to the other.
Is there a quick way to create tables which combine data from the new and the old database? Something like:
select * from NewDatabase.MyTable
UNION
select * from OldDatabase.MyTable
to be run on about 25 of the 170 tables of the databases.
The 2 key problems I see are:
1) PostgreSQL doesn't really allow cross database queries. Foreign data wrappers or db links (as mentioned here: Possible to perform cross-database queries with postgres?) are very cumbersome to use because (if I understand correctly) I must pre-declare the entire structure of the tables I wish to access.
2) I'd need to find a way to automate this so that I can code it automatically for each of the 25 tables I need, and it runs every week.
I have no preference whatsoever on how this is done (Pentaho-Kettle, command script, sql script, etc.) as long as it can be automated efficiently.
Thanks!