Skip to content

Postgres platform: pooling, read routing, branching workflow #9

Open

Description

@fgatti675

Guiding rule for this phase: every capability ships as an open-source interface with a working zero-configuration default. Hosted infrastructure is a different implementation behind that same interface — never the only implementation, and never a different API.

Most of what this phase needs already exists as a primitive. What is missing is the product wrapped around it.

Work

  • Connection pooling. Ship pgbouncer in the compose file and document pooled connection strings, so serverless clients cannot exhaust the connection limit
  • Read routing over the existing DATABASE_URL__<KEY> mechanism, which already follows the same environment-derived idiom as storage sources
  • Surface the security audit. packages/rls-check is thorough and nobody runs it, because it is a command. Run it on a schedule and show findings in the admin panel
  • Turn database branching into a workflow. CREATE DATABASE … TEMPLATE already works; tie branches to pull requests with preview environments
  • Evaluate pg_graphql as an opt-in extension for teams that want a GraphQL surface over the same schema
  • A foreign data wrapper catalog, for querying external sources as collections

Activity

  1. added
    enhancement
    roadmap
    on Aug 21, 2026
  2. fgatti675 commented on Aug 22, 2026

    @fgatti675
    MemberAuthor

    Third item landed in #15 — the RLS audit runs on a schedule and serves what it found at GET /api/admin/rls-audit, logging one line per run at warn when a finding reaches the threshold.

    One honest caveat: the scanner is passed in rather than imported, because @rebasepro/server has no database driver and @rebasepro/rls-check carries pg. So the managed runtime doesn't get this for free yet — the image would need to carry the package and wire scan. That's a deliberate follow-up involving a dependency and a lockfile change, not something to slip into a feature branch.

    Untouched here: connection pooling, read routing, and branching-as-a-workflow.

  3. fgatti675 commented on Aug 25, 2026

    @fgatti675
    MemberAuthor

    Connection pooling is in the compose file, behind a profile:

    docker compose --profile pooler up -d
    # postgres://rebase:$POSTGRES_PASSWORD@your-host:6432/rebase

    Behind a profile rather than always-on because the runtime does not need it — it holds a small, long-lived pool. What needs it is everything else on the same database that cannot hold a connection: a serverless function, a scheduled script, a BI tool, a worker that scales to fifty. max_connections is a hard limit in the low hundreds and each one is a process, so a lambda fan-out exhausts it long before the database is busy. A deployment with no such callers should not run a process it has no use for.

    The documentation is the part that matters more than the service, because transaction pooling quietly takes things away, and every one of them is something Rebase itself uses:

    • LISTEN/NOTIFY — realtime is built on it, and a listener needs a connection that outlives a transaction;
    • session state: SET (as opposed to SET LOCAL), advisory locks held across statements, WITH HOLD cursors, temp tables;
    • protocol-level prepared statements.

    Which is exactly why the runtime keeps its direct connection and this port is for other callers. SET LOCAL survives — that is what row-level security is set with — so RLS behaves identically through the pooled port.

    One honest caveat: it has never been started. This machine cannot reach Docker Hub, so docker compose config validates it and nothing has run it. The configuration follows the image's documented DATABASE_URL form, which generates its own userlist.txt rather than needing a second copy of the password. Worth one --profile pooler up before anyone relies on it.

    Read routing was looked at and deliberately not attempted. The environment idiom is the easy half — DATABASE_URL__<KEY> already exists and a replica URL would follow it. The hard half is that routing a statement to a replica is a correctness decision, not a configuration one: read-after-write inside a request, the RLS GUCs a scoped connection carries, and where a transaction's reads must go. Getting it wrong is silent and intermittent, which is the worst failure shape available, so it wants a design pass rather than an evening.

    Branching: CREATE DATABASE … TEMPLATE and its documentation are there; what the item asks for — branches tied to pull requests with preview environments — is not, and lives mostly in CI and the control plane rather than here.

    Landed on main locally and not pushed — pushing to main publishes a canary, which is yours to trigger.

  4. fgatti675 commented on Aug 25, 2026

    @fgatti675
    MemberAuthor

    Correcting the caveat above: it has been run now, and it was broken in two ways. The image finished pulling after that comment was written, so the "never been started" qualifier no longer applies — and neither bug would have been found by reading the file.

    • It could not authenticate to Postgres 18. The image defaults to md5; Postgres 18 stores a scram-sha-256 verifier, so every pooled connection died on FATAL: server login failed: wrong password type — which reads like a wrong password and is not one. AUTH_TYPE: scram-sha-256 fixes it. I had that line and removed it while simplifying onto DATABASE_URL, reasoning that a generated userlist holds the password in plain text so the type would not matter. It matters on the server side of the connection, which is the side I was not thinking about.
    • The healthcheck pointed at the host port, 6432, while pgbouncer listens on 5432 inside the container. It went unhealthy on every deployment.

    Verified against a real Postgres 18 now: a pooled client connects, the generated config reads pool_mode = transaction, auth_type = scram-sha-256, max_client_conn = 500, default_pool_size = 20, the container reports healthy, and SET LOCAL — the mechanism row-level security depends on — is visible inside its transaction and gone after the commit.

    One claim in the documentation was also too strong, and is now written the way it actually behaves. Neither session state nor LISTEN errors through the pooler. LISTEN answers LISTEN and then no notification ever arrives; and with a single idle client the next transaction usually lands on the same server connection, so a session-level SET is still there. Both therefore work while you are testing and stop working under the concurrency the pooler was introduced for — which is worth saying plainly, because "the next transaction will not see it" invites a developer to test it once, see it work, and conclude the documentation is wrong.

    A third thing turned up in CI rather than at runtime: check:runtime-image demands an automated publisher for every image a shipped compose file references, and its heuristic is that org/name is ours. edoburu/pgbouncer is the second third-party image with an org prefix (after pgvector/pgvector), so the canary went red until it was listed.

    All on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementroadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions