Deploy & Host PostgREST | Railway

Deploy and Host PostgREST on Railway

PostgREST turns a PostgreSQL database into a RESTful API. Tables, views and functions in the exposed schema become endpoints with filtering, pagination, embedding and OpenAPI docs. Permissions come from Postgres roles, grants and row-level security, and requests are authenticated with JWTs. It powers the REST layer of Supabase.

About Hosting PostgREST

This template deploys PostgREST v16.3, a Railway Postgres database and Swagger UI. On every start, a small wrapper creates the authenticator, web_anon and authenticated roles and the api schema, and it is safe to re-run. It also adds an event trigger so new tables appear in the API without a restart. Anonymous requests get nothing until you grant access. Requests carrying a JWT with "role": "authenticated", signed with the generated secret, can read and write tables in api. PostgREST is light and stateless, so the Hobby plan is enough for most projects.

Common Use Cases

Dependencies for PostgREST Hosting

Deployment Dependencies

Implementation Details

Service Source Networking Storage
postgrest repo aalfath/postgrest-railway-template public domain on 3000; private IPv4/IPv6 none
docs swaggerapi/swagger-ui:v5.33.0 public domain on 8080 none
Postgres Railway Postgres 18 private only volume

Create a table (for example with psql against the Postgres service) and it is live immediately:

create table api.todos (id bigint generated always as identity primary key, task text not null, done boolean default false);

Call it with a JWT signed (HS256) with PGRST_JWT_SECRET, payload {"role": "authenticated"}:

curl https:///todos -H "Authorization: Bearer "
curl -X POST https:///todos -H "Authorization: Bearer " \
  -H "Content-Type: application/json" -d '{"task": "ship it"}'

To allow anonymous reads of a table: grant select on api.todos to web_anon;

Variable Default Purpose
PGRST_JWT_SECRET generated 64-character secret Verifies request JWTs
PGRST_AUTHENTICATOR_PASSWORD generated secret Password of the low-privilege login role PostgREST uses
PGRST_DB_SCHEMAS api Exposed schema(s)
PGRST_DB_ANON_ROLE web_anon Role for requests without a JWT
DATABASE_URL ${{Postgres.DATABASE_URL}} Owner connection, used only for the bootstrap

Notes:

This is a community-maintained deployment package and does not imply affiliation with or endorsement by the PostgREST project.

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.