← ClaudeAtlas

fdw-developmentlisted

Building or modifying a Foreign Data Wrapper (FDW) — the SQL/MED interface for accessing external data as if it were PG tables. Covers the `FdwRoutine` callback set (`GetForeignRelSize` / `GetForeignPaths` / `GetForeignPlan` / `BeginForeignScan` / `IterateForeignScan` / `ReScanForeignScan` / `EndForeignScan` for scans, `BeginForeignInsert` / `ExecForeignInsert` / … for DML), the `postgres_fdw` reference implementation, plan pushdown (WHERE / JOIN / AGG / LIMIT), extended-explain support, and the FDW-related core code (`src/backend/foreign/foreign.c`, foreign-table catalog, user mappings). Loads when the user asks about writing an FDW, `CREATE FOREIGN TABLE`, why postgres_fdw is fast, pushdown decisions (`use_remote_estimate`, `fdw_startup_cost`), user mappings and password security (`password_required`), the loopback-back-to-self bypass-RLS pattern from postgres_fdw, or adding a new pushdown-shape. Skip when the ask is about specific non-postgres_fdw wrappers (file_fdw, oracle_fdw external, mysql_fdw external
matejformanek/postgres-claude · ★ 0 · AI & Automation · score 70
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 —