---
title: "Deploy ElectricSQL | Postgres Sync Engine, Database Included"
description: "Electric sync engine + Postgres with logical replication already on."
category: "Storage"
url: https://railway.com/deploy/electricsql-or-postgres-sync-engine-data
---

# Deploy ElectricSQL | Postgres Sync Engine, Database Included

Electric sync engine + Postgres with logical replication already on.

**[Deploy ElectricSQL | Postgres Sync Engine, Database Included on Railway](https://railway.com/template/electricsql-or-postgres-sync-engine-data)**

- **Creator:** SuperSlowSloth
- **Category:** Storage

## Template content

### postgres

- **Image:** postgres:18.4-trixie
- **Start command:** `/usr/local/bin/docker-entrypoint.sh postgres -c wal_level=logical -c max_wal_senders=10 -c max_replication_slots=10`

### electric

- **Image:** electricsql/electric:1.7.8
- **Start command:** `/bin/sh -c 'export ELECTRIC_PORT="${PORT:-3000}" ELECTRIC_LISTEN_ON_IPV6=true ELECTRIC_DATABASE_USE_IPV6=true ELECTRIC_STORAGE_DIR=/var/lib/electric/persistent; exec /app/bin/entrypoint start'`
- **Health check:** /v1/health
- **Public domain:** Yes

## Documentation

# Deploy and Host ElectricSQL with Postgres on Railway

ElectricSQL is an open-source Postgres sync engine. It streams little subsets of your Postgres data — called shapes — out to local apps over a simple HTTP API, so your frontend reads from a local cache that stays live instead of round-tripping to your API on every render. This template ships Electric **together with its own Postgres**, already configured for logical replication, so there is nothing to fill in and nothing to reconfigure.

## About Hosting ElectricSQL with Postgres

Electric's one hard requirement is a Postgres running with `wal_level = logical` and a role holding the `REPLICATION` attribute. That is exactly the setting most managed Postgres providers leave off by default, and it is the step that turns "just point Electric at your database" into an afternoon of provider documentation.

This template removes that step. It deploys two services: the official `postgres:18.4-trixie` image started with `-c wal_level=logical -c max_wal_senders=10 -c max_replication_slots=10`, and the official `electricsql/electric` image already pointed at it over Railway's private network. Postgres data persists on a volume at `/var/lib/postgresql`; Electric's shape logs persist on their own volume at `/var/lib/electric/persistent`, so a redeploy does not force every client to re-sync from scratch. Electric follows Railway's injected `$PORT`, listens on IPv6 for the private network, and exposes `/v1/health` for the platform healthcheck.

The deploy form is empty. `POSTGRES_PASSWORD` and `ELECTRIC_SECRET` are generated for you at deploy time, and `DATABASE_URL` is wired from the Postgres service by reference — you click deploy and get a working sync engine with a database behind it.

## Why Deploy ElectricSQL with Postgres 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 ElectricSQL on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, sync engines, and more on Railway.

- **Nothing to configure** — logical replication, the replication role, private networking, and both volumes are already wired.
- **Database included** — no separate Postgres to provision, and no provider whose logical replication settings you cannot change.
- **Real-time reads without websockets** — Electric's HTTP API is cacheable by any CDN or proxy; there is no bespoke socket server to run.
- **Secure by default** — `ELECTRIC_SECRET` is generated at deploy and required on every shape request; only `/v1/health` stays open.

## Common Use Cases

- **Local-first and offline-capable apps** — keep a live local copy of the rows a user actually needs, and read from it instantly.
- **Real-time dashboards and collaborative UIs** — stream inserts, updates, and deletes straight out of Postgres without polling.
- **Replacing hand-rolled websocket layers** — drop the bespoke pub/sub service and let Postgres' own replication stream be the source of truth.

## Dependencies for ElectricSQL Hosting

- A Postgres running with logical replication enabled — **included in this template**, no external database required.
- A volume for Postgres data at `/var/lib/postgresql` (included).
- A volume for Electric's shape logs at `/var/lib/electric/persistent` (included).

### Deployment Dependencies

- [ElectricSQL](https://github.com/electric-sql/electric) — upstream sync engine by Electric DB Ltd (Apache-2.0)
- [ElectricSQL documentation](https://electric-sql.com/docs/api/http) — HTTP API and client reference
- [electricsql/electric Docker image](https://hub.docker.com/r/electricsql/electric) — the official image this template deploys
- [postgres Docker image](https://hub.docker.com/_/postgres) — the official Postgres image this template deploys

### Implementation Details

Create a table in the bundled Postgres, then read it back through Electric as a shape:

```bash
# 1. create a table (via any Postgres client connected to the postgres service)
CREATE TABLE items (id int PRIMARY KEY, name text);
INSERT INTO items VALUES (1, 'alpha'), (2, 'beta');

# 2. read the initial snapshot through Electric
curl 'https:///v1/shape?table=items&amp;offset=-1&amp;secret=$ELECTRIC_SECRET'

# 3. follow live changes from the offset and handle the response returned above
curl 'https:///v1/shape?table=items&amp;handle=$HANDLE&amp;offset=$OFFSET&amp;live&amp;secret=$ELECTRIC_SECRET'
```

Inserts, updates, and deletes arrive on the live endpoint as they are committed. Official client libraries are available for TypeScript, React, and React Native, plus integrations for TanStack Query and Phoenix.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/electricsql-or-postgres-sync-engine-data
