Skip to main content

Sync service

The Electric sync service is an Elixir application that manages active-active replication between your Postgres database and your local apps.

You can run the pre-packaged Docker images published on Docker Hub, or build and run your own Docker image, or run it directly as an Elixir service.

Configuration

The Electric sync service is configured using environment variables. The three required variables are:

  • DATABASE_URL in the format of a Postgres Connection URI
  • LOGICAL_PUBLISHER_HOST that the sync service is running on (must be accessible from the Postgres instance to establish an inbound replication subscription)
  • PG_PROXY_PASSWORD to safe-guard access to the Migrations proxy
DATABASE_URL="postgresql://user:password@localhost:5432/electric"
LOGICAL_PUBLISHER_HOST="localhost"
PG_PROXY_PASSWORD="..."

See API -> Sync service for the full list of configuration options.

Docker

Images

Pre-packaged images are available on Docker Hub at electricsql/electric. Run using e.g.:

docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
-p 5433:5433 \
-p 65432:65432 \
-t \
electricsql/electric

Compose

You can deploy the sync service together with a Postgres database in a Docker Compose file. For example, save below contents to a file named compose.yaml:

version: "3.1"

volumes:
pg_data:

services:
pg:
image: postgres:14-alpine
environment:
POSTGRES_PASSWORD: pg_password
command:
- -c
- wal_level=logical
ports:
- 5432:5432
restart: always
volumes:
- pg_data:/var/lib/postgresql/data

electric:
image: electricsql/electric
depends_on:
- pg
environment:
DATABASE_URL: postgresql://postgres:pg_password@pg/postgres
DATABASE_REQUIRE_SSL: false
LOGICAL_PUBLISHER_HOST: electric
PG_PROXY_PASSWORD: proxy_password
AUTH_MODE: insecure
ports:
- 5133:5133
- 65432:65432
restart: always

Then start the services:

docker compose -f compose.yaml up

Build

See the Makefile for more details but e.g.:

docker build -t electric:local-build .

Then run:

docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
-p 5433:5433 \
-p 65432:65432 \
-t \
electric:local-build

Elixir

See the source code and usage instructions at electric-sql/electric/components/electric.

Make sure you have Elixir 1.15 compiled with Erlang 25 installed.

Build:

mix deps.get
mix compile

Test:

mix test

Release:

MIX_ENV="prod" mix release

Run:

./_build/prod/rel/electric/bin/electric start