Skip to content

Foreign Data Wrapper

Spicy — senior dev territoryDatabase

ELI5 - The Vibe Check

A foreign data wrapper lets Postgres pretend a completely different system, another database, a CSV file, even a REST API, is just another local table. You write a normal SELECT, and Postgres quietly reaches across the wire to fetch the real data and hands it back like nothing weird happened.

Real Talk

A Foreign Data Wrapper (FDW) is a PostgreSQL extension mechanism that exposes external data sources as foreign tables queryable with standard SQL. Popular wrappers like postgres_fdw and mysql_fdw let a single Postgres connection join across systems without building a separate ETL step.

Show Me The Code

CREATE EXTENSION postgres_fdw;
CREATE SERVER remote_db FOREIGN DATA WRAPPER postgres_fdw
  OPTIONS (host 'other-host', dbname 'analytics');
CREATE FOREIGN TABLE remote_orders (id int, total numeric)
  SERVER remote_db OPTIONS (table_name 'orders');

When You'll Hear This

"We used an FDW to join the analytics DB straight from the app database." / "postgres_fdw saved us from building a whole sync pipeline."

Made with passive-aggressive love by manoga.digital. Powered by Claude.