Server: withPostgresAdminClient

Alpha. Contributes ctx.postgresAdmin — a pg client that bypasses RLS, for full-table access. The direct-connection counterpart to withSupabaseAdminClient, and the deliberate opt-out from the guardrails withPostgresClient (@supabase/server/middleware/postgres) enforces.

Queries run as-is, as the role in the connection string: no claim injection, no role switching, no wrapping transaction. Whatever that role may read, the caller may read.

Unlike withPostgresClient this declares no upstream prerequisite — it never looks at ctx.jwtClaims, so it composes in any auth mode, including auth: 'secret' and auth: 'none':

import { withSupabase } from '@supabase/server'
import { withPostgresAdminClient } from '@supabase/server/middleware/postgres-admin'

export default {
  fetch: withSupabase(
    { auth: 'secret', middleware: [withPostgresAdminClient()] },
    async (_req, ctx) => {
      const rows = await ctx.postgresAdmin.query`select user_id, count(*) from notes group by user_id`
      return Response.json(rows)
    },
  ),
}

Compose both halves when a handler needs each in turn — they share one pool, and ctx.postgres stays RLS-scoped regardless:

middleware: [withPostgresClient(), withPostgresAdminClient()]

Authorization is yours now. RLS is not consulted, so any per-user scoping has to be a where clause you write. Reach for withPostgresClient unless you specifically need to cross user boundaries.

Runtime note. pg needs raw TCP, so this runs on Node/Deno (including the Supabase Edge runtime), not on Workers-style isolates.

The composable middleware surface tracks @supabase/middleware 0.x — entry shapes, context keys, and config options may change between 0.x releases.