How to make a JOIN on tables from different databases?

We have about 10 tables in 2 different databases. One of the big tables (millions of records), in others hundreds of thousands of records (all the data in PostgreSQL).
Need: essentially to do the JOIN for all 10 tables and get the result for example for group by statistics.
Not necessarily in real-time, can be for example a couple of times a day.
How to best do this?
I mean that must be some kind of software that for example takes a set of files in csvand doing what you want with it.

PS My main PL - PHP. But I think it doesn't matter because the decision most likely needs to be a console.

I will appreciate any leads, thanks!
July 9th 19 at 10:47
2 answers
July 9th 19 at 10:49
Directly access another database impossible. But who said that you can not do?

Set against Foreign Data Wrappers:
Get the availability of both tables in one database. For the current versions of PG the scheduler may have to push the aggregation in the fdw alone and consider that there can be, and back to transmit only aggregatirovanie data.
Older method: take the good old dblink: pull request with joinem tables from one DB to the result table jointe second base.
Confused only that the join should be on the entire table, and it is a few hundred million records is planned. Is this will work well? - dell1 commented on July 9th 19 at 10:52
Somewhere to export - any read all that, too, is not very, very quickly. It is necessary to look more specifically, the first task, then explain's. - Ignacio_Romaguera commented on July 9th 19 at 10:55
July 9th 19 at 10:51
I could be wrong but from different databases is not provided. Run the script via cron it creates a table in a database, pulls from the database all the desired data, make desired query from this one table. All. In cron you can then the table to dropnode if the sampling result is somewhere saved and you don't need it.
I don't mean to do it natively database. I probably need something like pandas or hadoop only easier. - dell1 commented on July 9th 19 at 10:54

Find more questions by tags PostgreSQLSQL