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 two required variables are:
DATABASE_URL
in the format of a Postgres Connection URILOGICAL_PUBLISHER_HOST
that the sync service is running on (must be accessible from the Postgres instance to establish an inbound replication subscription)
DATABASE_URL="postgresql://user:password@localhost:5432/electric"
LOGICAL_PUBLISHER_HOST="localhost"
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 pull electricsql/electric:latest
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
-p 5433:5433 \
electricsql/electric
Compose
You can deploy the sync service together with a Postgres database in a Docker Compose file. For example:
version: '3.1'
services:
pg:
image: postgres
environment:
POSTGRES_PASSWORD: "pwd"
ports:
- 5432:5432
restart: always
volumes:
pg_data:/var/lib/postgresql/data
electric:
image: electricsql/electric
depends_on:
- pg
environment:
DATABASE_URL: postgresql://postgres:pwd@pg
LOGICAL_PUBLISHER_HOST: electric
AUTH_MODE: insecure
ports:
- 5133:5133
restart: always
volumes:
- electric_data:/app/data
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 "AUTH_MODE=insecure" \
-p 5133:5133 \
-p 5433:5433 \
-it 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