
Deploy PostgREST
Instant REST API from your Postgres schema with OpenAPI docs
Just deployed
/var/lib/postgresql/data
postgrest
Just deployed
Deploy and Host PostgREST on Railway
PostgREST is an open-source web server that turns any PostgreSQL database directly into a RESTful API. It auto-generates endpoints from tables, views, and RPC functions, enforces database roles and Row-Level Security, and serves OpenAPI docs at the root — a complete data API without writing application code.

About Hosting PostgREST
Hosting PostgREST takes one service beside a managed PostgreSQL database. This template wraps the pinned official PostgREST binary with a bootstrap step: on startup it waits for PostgreSQL, creates an idempotent read-only web_anon role with SELECT-only grants, then execs PostgREST — so the API is usable immediately after deploy with no manual SQL. PostgREST listens on port 3000, serves its OpenAPI documentation at the root path, and takes all configuration from environment variables. Railway terminates TLS at the edge and injects the database connection string, so the only variables to set are the database references.
Common Use Cases
- Instant, read-safe REST API over Postgres for internal tools and dashboards.
- Minimal backend for web and mobile apps where Postgres is the source of truth.
- Expose a curated schema or views as a versioned, documented API.
- Prototype a data-access layer before committing to a full application server.
- Feed AI agents a documented REST API over structured data with OpenAPI.
Dependencies for PostgREST Hosting
- Official Docker image
postgrest/postgrest:v16.6(pinned; the binary is copied into apostgres:16-alpinebase for the bootstrap step). - One PostgreSQL database (Railway-managed).
- One public HTTP service on port
3000; no Redis, cache, or persistent volume is used.
Implementation Details
The bootstrap step applies this SQL once per start, idempotently:
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'web_anon') THEN
CREATE ROLE web_anon NOLOGIN;
END IF;
END
$$;
GRANT USAGE ON SCHEMA public TO web_anon;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO web_anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO web_anon;
The result: anonymous requests can read, but every write requires a real database role. Open a table or function to writes by granting to web_anon yourself, or enable PostgREST's built-in JWT authentication before exposing write endpoints. After creating new tables, ask PostgREST to refresh its schema cache with NOTIFY pgrst, 'reload schema'; — this is PostgREST's standard reload mechanism, not a template workaround.
Using the API is plain REST: GET /todos lists rows, GET /todos?id=eq.1 filters, POST with a Prefer: return=representation header inserts once you grant writes, and the OpenAPI document at the root describes every endpoint your schema exposes.
Comparison with Alternatives
✅ = built-in part of the workflow, ❌ = not available or requires workarounds.
| Capability | This template (PostgREST) | Hasura | Supabase (self-host) | NocoDB |
|---|---|---|---|---|
| REST API auto-generated from tables, views, and RPC | ✅ | ✅ | ✅ | ❌ (no-code app builder) |
| Authorization defined in the database (roles + RLS), no separate permission layer | ✅ | ❌ (own permission layer) | ✅ | ❌ (own permission layer) |
| Automatic bootstrap: role and read-only grants created at startup | ✅ | ❌ | ❌ | ❌ |
| Single service beside Postgres | ✅ | ✅ | ❌ (multiple services) | ✅ |
| OpenAPI served at the API root | ✅ | ✅ | ✅ | ❌ |
Sources: the PostgREST documentation, the PostgreSQL Row-Level Security documentation, and the upstream projects' documentation.
Security Considerations
- The bootstrap grants
web_anonread-only access to thepublicschema. Writes require granting to the role deliberately or setting up JWT authentication. - Enable Row-Level Security on tables with sensitive rows before relying on the read-only default.
- The database connection string is a Railway reference variable; rotate the database password from the database service's Config tab, and redeployed services pick it up automatically.
- Do not enable public access on the PostgreSQL service; PostgREST reaches it over the private network.
- Enable PostgREST's JWT authentication before exposing authenticated write endpoints.
Why Deploy PostgREST on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying PostgREST on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
The managed PostgreSQL service handles backups, password rotation, and upgrades; PostgREST is a stateless process that reloads configuration from its environment on every deploy.
License
PostgREST is licensed under MIT by the PostgREST contributors. This repository contains deployment packaging and documentation only; it is not affiliated with or endorsed by the PostgREST project.
Template Content