Directly access another database impossible. But who said that you can not do?
Set against Foreign Data Wrappers:
https://www.postgresql.org/docs/current/static/pos...
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:
https://www.postgresql.org/docs/current/static/dbl... pull request with joinem tables from one DB to the result table jointe second base.