Repository navigation
An org reads the SQL surface from its own Postgres through pg_clickhouse - #461
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nd the test runs as the reader Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d the test runs the owner steps without a superuser Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ssion shares and what a managed service must allow Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d its examples carry neutral facts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s written Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
9 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #450
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
A guide shows how an org reads Loom's SQL surface from its own Postgres through the
pg_clickhouseextension and joins it with application tables, and CI tests that path on Postgres 16 and 18.Why
The SQL surface (#450) gives an org's SQL user read access to its memories, conversations and request ledger. Many apps keep their own data in Postgres, so the useful join is in Postgres: Loom's facts about a user next to the app's row for that user.
pg_clickhouseimports ClickHouse tables and views as foreign tables and pushes queries down. This PR documents that path and holds it to a CI test, so it keeps working as the views evolve.Design
docs/guides/query-from-postgres.mdcovers five steps:loom sql-access grant;CREATE SERVER … FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS (driver 'http', …), a user mapping for the owner and one for the reader, and the reader's session settings;IMPORT FOREIGN SCHEMA … LIMIT TO (the five views)and the reader's grants;CREATE EXTENSION, because the extension's control file does not mark it trusted.CREATEROLE,CREATEon the database andUSAGEon the wrapper runs steps 3 and 4. It creates the reader role, so it may set that role's defaults. It needs its own user mapping, becauseIMPORT FOREIGN SCHEMAconnects as the role that runs it.join_use_nulls,group_by_use_nulls,final,transform_null_in. These are the extension's defaults, written down so a later release's defaults cannot add one. Any other setting fails withREADONLYin ClickHouse, whatever the role says, because the SQL user's profile refuses it.CREATE TABLE … AS SELECT, a materialized view, a dump) belongs to the org and is outside Loom's erasure.LOOM_PG_DSN, and Loom's own database needs no extension. Neitherpg_clickhousenor Managed Postgres CDC takes part in Loom's writes; that was decided earlier, for vectors, erasure fencing and failover.pg_clickhouse0.11.0 (GitHub release of 2026-09-30) through the official imagesghcr.io/clickhouse/pg_clickhouse:{16,18}-0.11.0. 0.11.1 came out the day this was written and is not pinned yet. The extension reportsextversion0.11, and the test checks it against the pinned release.Scope and risk
dev/ci_start_pg_clickhouse.sh: host network, listening on 127.0.0.1:5433 only, withtest_web_exposurechecking that;tests/integration/test_pg_clickhouse_live_ch.py;integration-postgresCI job, which now also starts the image and runs this test plustest_sql_surface_live_ch.py. The latter now also runs the SQL surface under the Postgres memory authority, the deployment shape; both files passed in that job's memory step on an earlier head of this PR;docs/development/testing.md.ghcr.io/clickhouse/pg_clickhousefor each Postgres major. A registry outage would fail that job's start step.Compatibility, rollout and rollback
Tests
tests/integration/test_pg_clickhouse_live_ch.pyruns againstpg_clickhouse16-0.11.0 locally and passes. It runs the guide's roles: steps 3 and 4 as a non-superuser owner on its own connection, step 5 as the reader. It skips withoutLOOM_PGCH_DSN. It covers:accountstable that returns only that tenant's rows, with thehighvalue and its hash NULL;max_threads 2refused withREADONLY;loom sql-access revoke, the next query failing to authenticate.make format lint typecheck,test_web_exposure,test_doc_links,test_public_copy,test_agent_instructionsandtest_integration_suite_targetspass.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The design went through an architect review to zero findings. The integration test was run by hand against the pinned image.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code