Physical PostgreSQL 18 Isolation & Default-Deny Row-Level Security
How Habify Base provisions physical hb_proj_<ulid> databases, enforces SET LOCAL ROLE hb_rls_<ulid> even on anonymous hb_pk_* calls, and balances clusters at 500 DBs / 70% disk.
Last updated: 2026-11-24
1. Two Isolated Schemas: public vs habify_sys
Every Managed Project receives a dedicated PostgreSQL 18 database (hb_proj_<ulid>) pooled via PgBouncer. Your business tables live in public, while habify_sys hosts Billing Kit, audit_logs, and webhook_deliveries.
2. Mandatory SET LOCAL ROLE hb_rls_<ulid> for Anon Requests
Requests presenting only hb_pk_* without a user JWT still execute inside a transaction with SET LOCAL ROLE hb_rls_<ulid>, app.current_role = 'anon', and app.current_user_id = NULL. Any table lacking ENABLE + FORCE RLS or at least one policy fails closed with 403 RLS_POLICY_REQUIRED.
BEGIN;
SET LOCAL ROLE hb_rls_01j9x...;
SELECT set_config('app.current_user_id', '', true);
SELECT set_config('app.current_role', 'anon', true);
SELECT * FROM public.catalog_items LIMIT 20;
COMMIT;3. RLS-Safe Read-Only SQL Views (WITH (security_invoker = true))
To join multiple public tables safely for GET /v1/db/tables/{view}, create PostgreSQL Views WITH (security_invoker = true). The Data API recursively verifies that every referenced relation resides in public and enforces ENABLE + FORCE RLS with at least one policy; Views omitting security_invoker = true fail closed with 403 VIEW_SECURITY_INVOKER_REQUIRED and mutations return 405 VIEW_READ_ONLY.
CREATE VIEW public.order_summaries
WITH (security_invoker = true) AS
SELECT o.id, o.status, o.total_minor, c.display_name
FROM public.orders o
JOIN public.customers c ON c.id = o.customer_id;4. Cluster Thresholds (500 DBs / 70% Disk) & Physical Replica
Clusters cap at 500 databases or 70% disk utilization before routing new projects or migrating cleanly via base:move-project. Clusters stream continuously to a physical replica inside Vietnam (vn_replica).