Postgresql – Creating Synonym For a Table in PostgreSQL over dblink

dblinkpostgresqlpostgresql-9.5synonyms

I have two PostgreSQL databases connected over dblink extension. I want to create synonym for a table in first database so the queries that are coming through application I can route them to the table in the second database. It will be good to mention that both databases has the same structure.

Is it possible to create a synonym or is there any alternative way to do so?

Best Answer

That's exactly what foreign data wrappers and foreign tables were created for:

You create a foreign server pointing to the source server, and then a foreign table that enables access to that remote server.

Some examples for that are in the description of the Postgres foreign data wrapper:

https://www.postgresql.org/docs/current/static/postgres-fdw.html