Deploy PostgREST

Instant Restful APIs for your PostgreSQL database

Deploy PostgREST

Postgres

railwayapp-templates/postgres-ssl:17

Just deployed

/var/lib/postgresql/data

postgrest

postgrest/postgrest:latest

Just deployed

Deploy and Host PostgREST on Railway

What is PostgREST? PostgREST is a standalone web server that turns a PostgreSQL database directly into a RESTful API. It auto-generates endpoints from tables, views, and RPC functions, respects database permissions and RLS, and serves OpenAPI docs—perfect for data-centric backends without writing (or maintaining) application code.

About Hosting PostgREST

Hosting PostgREST on Railway is simple: run the official Docker image and point it at a Railway PostgreSQL add-on via DATABASE_URL. Configure at runtime with env vars (e.g., PGRST_DB_URI, PGRST_DB_SCHEMAS, PGRST_DB_ANON_ROLE, and PGRST_SERVER_PORT=$PORT). Define roles/grants in SQL, enable RLS where needed, and (optionally) set PGRST_JWT_SECRET for authenticated access. Railway gives you a public HTTPS URL, logs, env-var management, and one-click scaling. Redeploy to apply config changes—no app code or build pipeline required.

Common Use Cases

  • Instant, secure CRUD API over Postgres for internal tools and dashboards
  • Minimal backend for web/mobile apps where Postgres is the source of truth
  • Data gateway microservice exposing a curated schema/views only
  • Read-only analytics API or prototyping data access layer

Dependencies for PostgREST Hosting

  • PostgreSQL (Railway Postgres add-on)
  • Docker image: postgrest/postgrest
  • Optional: JWT auth provider (e.g., Auth0/Clerk/Supabase Auth)
  • Optional: Migration tool (psql/Sqitch/Flyway/Prisma/Drizzle)

Deployment Dependencies

Implementation Details

Core environment variables

PGRST_DB_URI=${DATABASE_URL}            # provided when you attach Railway Postgres
PGRST_DB_SCHEMAS=public                 # comma-separated list, e.g. "public,api"
PGRST_DB_ANON_ROLE=web_anon             # role used for unauthenticated requests
PGRST_SERVER_HOST=0.0.0.0               # listen on all interfaces
PGRST_SERVER_PORT=${PORT}               # Railway sets PORT automatically
# Optional hardening:
# PGRST_JWT_SECRET=your_256bit_secret
# PGRST_OPENAPI_SERVER_PROXY_URI=https://your.custom.domain

Minimal SQL setup

-- Anonymous, read-only role
CREATE ROLE web_anon NOLOGIN;
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;

-- Enable RLS on sensitive tables (example)
ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
-- Add RLS policies as needed…

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.


Template Content

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

View Template
mellow-vue
A full-stack Vue app with The Boring JavaScript Stack.

View Template
Openfront
Deploy and Host Openfront with Railway