---
title: "Postgres FDW: Pushdown is a negotiation"
description: "pg_clickhouse, a Postgres foreign data wrapper for ClickHouse, decides clause by clause how much of a query to push down as ClickHouse SQL."
url: "https://swe.quest/articles/postgres-fdw-pushdown-is-a-negotiation-623facded31963c6"
canonical: "https://clickhouse.com/blog/postgres-fdw-pushdown-negotiation"
source: "ClickHouse"
published: "2026-05-14"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 16
tags: ["postgres","query-engines","analytics","performance"]
---

# Postgres FDW: Pushdown is a negotiation

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-05-14, 16 min read, Deep dive. Original: [https://clickhouse.com/blog/postgres-fdw-pushdown-negotiation](https://clickhouse.com/blog/postgres-fdw-pushdown-negotiation)

## Summary

pg\_clickhouse, a Postgres foreign data wrapper for ClickHouse, decides clause by clause how much of a query to push down as ClickHouse SQL. One analytical query (join, GROUP BY, FILTER aggregate, percentile, window function, JSON predicate, LIMIT) runs in about 80 ms when fully pushed down, but takes minutes to half an hour when any single clause stays local, because grouped pushdown is all-or-nothing and millions of rows must stream back to Postgres. The post walks through the FDW planner callbacks (GetForeignPaths, GetForeignJoinPaths, GetForeignUpperPaths) and the deparser, then traces shipped steps such as cost-based join pushdown, emitting ALL INNER JOIN to keep Postgres join semantics, and mapping percentile\_cont to quantile. It also explains why some translations were refused or revoked when they would have changed results.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- PostgreSQL query planner basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- SQL aggregates and window functions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- Foreign data wrappers concept

## Keywords

pg\_clickhouse, ClickHouse, postgres\_fdw, Foreign Data Wrapper, clickhouse\_fdw

## Related posts

- [Introducing pg\_clickhouse: A Postgres extension for querying ClickHouse](https://swe.quest/articles/introducing-pg-clickhouse-a-postgres-extension-for-querying-clickhouse-98de49fb9ae8bb75.md): ClickHouse · 2025-12-10 · Medium · 11 min read · PostgreSQL, Query engines, Analytics & OLAP, SQL
  pg\_clickhouse v0.1.0 is an Apache 2-licensed PostgreSQL foreign data wrapper, derived from clickhouse\_fdw, that runs analytics queries on ClickHouse from Postgres so existing queries can work unmodified by changing search\_path.
- [ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1](https://swe.quest/articles/clickhouse-and-postgresql-a-match-made-in-data-heaven-part-1-7c7668b9b4913b70.md): ClickHouse · 2022-12-20 · Medium · 18 min read · Analytics & OLAP, PostgreSQL, Query engines, Performance engineering, SQL
  ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine.
- [What's new in pg\_clickhouse v0.10.0: Subqueries, TPC-H Speedups, C Driver, and Aggregates](https://swe.quest/articles/what-s-new-in-pg-clickhouse-v0-10-0-subqueries-tpc-h-speedups-c-driver-and-178ced76a7784be7.md): ClickHouse · 2026-08-11 · Hard · 11 min read · PostgreSQL, Query engines, Analytics & OLAP, SQL, Performance engineering
  pg\_clickhouse v0.10.0 pushes correlated scalar subqueries, IN and NOT IN down to ClickHouse as remote subqueries and anti/semi-joins, raising full TPC-H pushdown from 12 to 16 of 22 queries.
- [pg\_clickhouse 0.11.1: Now with pgvector, UPDATE, DELETE pushdown](https://swe.quest/articles/pg-clickhouse-0-11-1-now-with-pgvector-update-delete-pushdown-a96a06584d05c765.md): ClickHouse · 2026-11-19 · Medium · 7 min read · PostgreSQL, Analytics & OLAP, Vector search, Query engines
  pg\_clickhouse 0.11.1 maps pgvector's vector type to ClickHouse Array(Float32/Float64) columns.
- [Postgres week in the Netherlands: PGDay Lowlands & Percona Live 2026](https://swe.quest/articles/postgres-week-in-the-netherlands-pgday-lowlands-percona-live-2026-0eb593178690a919.md): ClickHouse · 2026-09-18 · Easy · 7 min read · PostgreSQL, Observability, Analytics & OLAP, Query engines
  Notes from PGDay Lowlands in Utrecht and Percona Live in Amsterdam, covering two ClickHouse-maintained Postgres extensions and several PostgreSQL 19 features. pg\_clickhouse is a foreign data wrapper that lets unmodified Postgres queries and ORMs run against ClickHouse via pushdown, with 15 of 22 TPC-H queries fully pushed down. pg\_stat\_ch streams per-query execution events through a shared-memory ring buffer to ClickHouse without back-pressure.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
