pg_restapi
alohadb · AlohaDB: Experimental SQL and worker-based HTTP CRUD handlers
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102402 | pg_restapi | alohadb | 1.3 | FEAT | MIT | C |
PostgreSQL · 18
Usage
Sources:
pg_restapi 1.3 provides SQL CRUD handlers and an optional HTTP/OTLP server in AlohaDB 21.7.0, a PostgreSQL 18 fork. It also supplies PostgREST-compatible routing and the network surface for optional authentication and object-storage modules. Stock PostgreSQL compatibility is not established.
SQL and Network Enablement
A superuser installs the SQL objects. To enable the worker, preserve existing preload entries, add pg_restapi, configure the target database/schema and a dedicated non-superuser default role, restrict the listen address, then restart. Direct SQL handlers are separate from this listener.
The default listener covers all IPv4 addresses. Configure native TLS through pg_restapi.ssl, certificate and key settings, or use a trusted TLS proxy before sending credentials. TLS settings reload; a failed certificate reload retains the previous usable configuration, so inspect logs and verify the endpoint.
Authentication and Role Boundaries
The table API refuses superuser roles and needs pg_restapi.default_role. The legacy X-PG-Role override is restricted by pg_restapi.allowed_roles; an empty list does not allow arbitrary role changes. pg_restapi.api_token can protect legacy /api/ endpoints. A shared token is not independent user authentication.
For HS256 JWT routes, set a strong random pg_restapi.jwt_secret of at least 32 characters and a narrow pg_restapi.jwt_roles allowlist. HS256 role claims select only allowed non-superuser roles; expiry and not-before are enforced, with optional audience validation. Authorization Bearer takes precedence over apikey. Protect service-role keys, which may bypass RLS, and grant only necessary table/schema/function access.
Routes and Optional Modules
/rest/v1 offers the documented PostgREST subset with transaction-scoped roles, grants and RLS. RPC/function schemas require explicit configuration. pg_auth supplies /auth/v1, while pg_storage supplies metadata for /storage/v1; install and configure those separately. Realtime WebSocket database-change delivery additionally requires logical WAL. Compatibility claims do not guarantee every Supabase service or client feature.
OTLP and Upgrade
/v1/traces now accepts OTLP/HTTP protobuf or JSON, optionally gzip-compressed. Optional pg_restapi.otlp_grpc_port adds the TraceService Export endpoint over HTTP/2 and needs restart to change. Both use pg_restapi.otlp_token, decompressed-body limits and the same JSONB ingestion function as the non-superuser default role; X-PG-Role is ignored. Configure pg_restapi.otlp_traces_function, for example agenttrace.agenttrace_ingest_otlp, and grant the writer explicitly. An empty function disables ingestion, and errors roll back that request.
The extension’s SQL version is now 1.3, separate from distribution 21.7.0. Install matching AlohaDB files, restart the preloaded worker and use the supplied 1.0-to-1.1-to-1.2-to-1.3 SQL chain via ALTER EXTENSION pg_restapi UPDATE TO '1.3'. Review secrets, role allowlists, RLS, endpoint limits and verified backups before exposing new routes. The older name alohadb_restapi needs its separate conversion procedure.
1.3 Public Keys and Persistent HTTP
RS256/ES256 JWTs use pg_restapi.jwt_jwks with configured HTTPS URLs or local key files, an explicit pg_restapi.jwt_issuers allowlist, and the audience/role restrictions. Keep accepted issuers narrow; retaining old keys on a fetch failure affects revocation timing. Do not assume signature verification alone authorizes a request.
pg_restapi_jwt_verify_jwks(token,jwks) verifies the signature and exp/nbf only. Its caller must separately validate issuer, audience and all other required claims. The HTTP verifier also applies the configured issuer, audience and role policy.
HTTP/1.1 keepalive defaults to a 15-second idle timeout and 1000 requests. The settings are reloadable; timeout 0 disables keepalive. Clients that formerly read until close must use Content-Length or send Connection: close.