# A look at Foreign Data Wrappers

DevFeed: [A look at Foreign Data Wrappers](<https://devfeed.tech/articles/a-look-at-foreign-data-wrappers-41148.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2013/08/05/A-look-at-Foreign-Data-Wrappers/>)

Author: Map

Published: 2013-08-05T20:55:56Z

Content type: tutorial

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Heroku Postgres](<https://devfeed.tech/topics/heroku-postgres.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [JOIN](<https://devfeed.tech/topics/join.md>)

Tags: [heroku-postgres](<https://devfeed.tech/tags/heroku-postgres.md>), [join](<https://devfeed.tech/tags/join.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

A tutorial on PostgreSQL foreign data wrappers (FDWs), including how to enable postgres_fdw on PostgreSQL 9.3, configure a remote server and user mapping, define foreign tables, and query data across databases.

## Source excerpt

There are two particular sets of features that continue to keep me very excited about the momentum of Postgres. And while PostgreSQL has had some great momentum in the past few years these features may give it an entirely new pace all together. One is extensions, which is really its own category. Dimitri Fontaine was talking about doing a full series just on extensions, so here's hoping he does so I dont have to :) One subset of extensions which I consider entirely separate is the other thing, which is foreign data wrappers or FDWs. FDWs allow you to connect to other data sources from within Postgres. From there you can query them with SQL, join across disparate data sets, or join across different systems. Recently I had a good excuse to give the postgres_fdw a try. And while I've blogged about the Redis FDW previously, the Postgres one is particularly exciting because with PostgreSQL 9.3 it will ship as a contrib module, which means all Postgres installers should have it... you just have to turn it on. Let's take a look at getting it setup and then dig into it a bit. First, because I don't have Postgres 9.3 sitting around on my system I'm going to provision one from Heroku Postgres: $ heroku addons:add heroku-postgresql:crane --version 9.3 Once it becomes available I'm going to connect to it then enable the extension: $ heroku pg:psql BLACK -acraig # CREATE EXTENSION postgres_fdw; Now its there, so we can actually start using it. To use the FDW there's four basic things you'll want to do: Create the remote server Create a user mapping for the remote server Create your foreign tables Start querying some things The setup You'll only need to do each of the following once, once you're server, user and foreign table are all setup you can simply query away. This is a nice advantage over db_link which only exists for the set session. One downside I did find was that you can't use a full Postgres connection string, which would make setting it up much simpler. So onto setting