fdw-developmentlisted
Install: claude install-skill matejformanek/postgres-claude
# fdw-development — Foreign Data Wrappers
An FDW lets a PG backend access external data (another PG, MySQL, files, HTTP APIs) as if it were a local relation. The system supports:
- SELECT (with pushdown of quals, joins, aggregates, LIMITs).
- INSERT / UPDATE / DELETE (with pushdown for `postgres_fdw`).
- TRUNCATE.
- COPY FROM.
- Async scans (PG 14+).
- Extended-explain output.
The **core FDW support** is small — `src/backend/foreign/foreign.c` (22 KB) — and lives around the `FdwRoutine` callback struct. The heavy work is in per-wrapper contrib modules (`contrib/postgres_fdw/` for PG-to-PG, `contrib/file_fdw/` for CSV/text files).
## The file map
| File | Role |
|---|---|
| `src/backend/foreign/foreign.c` | Core FDW support — foreign-table cache, GetForeignServer / GetUserMapping helpers, wrapper's `handler` fn is looked up + cached here. |
| `src/backend/commands/foreigncmds.c` | CREATE / ALTER / DROP for SERVER / USER MAPPING / FOREIGN TABLE. |
| `src/backend/executor/nodeForeignscan.c` | `ForeignScan` executor node — dispatches to the FDW's Begin/Iterate/End callbacks. |
| `src/backend/optimizer/util/appendinfo.c` + `plancat.c` | Planner-side foreign-table hooks. |
| `src/include/foreign/fdwapi.h` | The FdwRoutine struct definition — 30+ callback pointers. |
| `contrib/postgres_fdw/postgres_fdw.c` | Reference implementation. Big and non-trivial (has to handle pushdown + connection pooling + prepared statements + async). |
| `contrib/postgres_fdw/deparse.c` | Deparse —