DEV Community

Muhammad Adil Shahid
Muhammad Adil Shahid

Posted on

Foreign Data Wrappers (FDWs) in PostgresSQL

In this blog we will understand foreign data wrappers.
Foreign Data Wrappers(FDWs) is the library in PostgresSQL that allows to access the data like tables from External sources. To manage the foreign tables that are on a remote server, FDWs use SQL Management of External Data (SQL/MED).

  • The analyzer/analyser creates the query tree of the input SQL using definitions of the foreign tables which are stored in catalog.

  • To get connected to the remote server, the planner uses specific libraries. For example, while connecting to the remote PostgresSQL server, the library that will be used by postgres_fdw is libpq.

  • use_remote_estimate is used to control the EXPLAIN command use. If the use_remote_estimate` option is ON, then the planner wil execute the EXPLAIN command to estimate the cost of each path.

  • The planner uses the plan tree's scan paths of the foreign tables to create the plain SQL statements and this process is known as deparsing.

  • After the process of deparsing, the executor takes those plain SQL statements and send them to the remote server. The method of sending those SQL statements depends on the developer of each extension. For instance, the foreign data wrappers in mysql i.e. mysql_fdw sends the SQL statement without using a transaction.

Then FDW receive the results from the remote server and converts it into the PostgresSQL readable data.

References:

https://www.interdb.jp/pg/pgsql04.html

Top comments (0)