Skip to content

Sync service configuration

This page documents the config options for self-hosting the Electric sync engine.

Advanced only

You don't need to worry about this if you're using Electric Cloud.

Also, the only required configuration options are DATABASE_URL and ELECTRIC_SECRET.

Configuration

The sync engine is an Elixir application developed at packages/sync-service and published as a Docker image at electricsql/electric.

Configuration options can be provided as environment variables, e.g.:

shell
docker run \
    -e "DATABASE_URL=postgresql://..." \
    -e "ELECTRIC_DB_POOL_SIZE=10" \
    -p 3000:3000 \
    electricsql/electric

These are passed into the application via config/runtime.exs.

Database

DATABASE_URL

VariableDATABASE_URLrequired
Description

Postgres connection string. Used to connect to the Postgres database.

The connection string must be in the libpg Connection URI format of postgresql://[userspec@][hostspec][/dbname][?sslmode=<sslmode>].

The userspec section of the connection string specifies the database user that Electric connects to Postgres as. They must have the REPLICATION role.

For a secure connection, set the sslmode query parameter to require.

ExampleDATABASE_URL=postgresql://user:password@example.com:54321/electric

ELECTRIC_QUERY_DATABASE_URL

VariableELECTRIC_QUERY_DATABASE_URL
DefaultDATABASE_URL
Description

Postgres connection string. Used to connect to the Postgres database for anything but the replication, will default to the same as DATABASE_URL if not provided.

The connection string must be in the libpg Connection URI format of postgresql://[userspec@][hostspec][/dbname][?sslmode=<sslmode>].

The userspec section of the connection string specifies the database user that Electric connects to Postgres as. This can point to a connection pooler and does not need a REPLICATION role as it does not handle the replication.

For a secure connection, set the sslmode query parameter to require.

ExampleELECTRIC_QUERY_DATABASE_URL=postgresql://user:password@example-pooled.com:54321/electric

ELECTRIC_DATABASE_USE_IPV6

VariableELECTRIC_DATABASE_USE_IPV6
Defaultfalse
Description

Set to true to prioritise connecting to the database over IPv6. Electric will fall back to an IPv4 DNS lookup if the IPv6 lookup fails.

ExampleELECTRIC_DATABASE_USE_IPV6=true

ELECTRIC_DB_POOL_SIZE

VariableELECTRIC_DB_POOL_SIZE
Default20
Description

How many connections Electric opens as a pool for handling shape queries.

ExampleELECTRIC_DB_POOL_SIZE=10

ELECTRIC_DATABASE_CA_CERTIFICATE_FILE

VariableELECTRIC_DATABASE_CA_CERTIFICATE_FILEoptional
Description

The path on local disk to a file containing trusted certificate(s) that Electric will use to verify the database server identity.

Trusted certificates are those that have been signed by trusted certificate authorities (CA); they are also known as root certificates. Every operating system and most web browsers include a bundle of well-known root certificates (aka CA store). You can instruct Electric to use the default bundle provided by your OS by specifying an absolute path to it. This page from Neon lists the typical locations for different operating systems.

Some managed Postgres providers such as Supabase and DigitalOcean use a self-signed root certificate that won't be found in OS-specific CA stores. If you're using one of those, download the trusted certificate from the provider's website and put it somewhere on your local disk where Electric can access it.

Certificate verification and sslmode

Electric doesn't support sslmode=verify-ca or sslmode=verify-full query params in DATABASE_URL. Those values are specific to psql. When you configure Electric with a trusted certificate file, it will always try to verify the server identity and will refuse to open a database connection if the verification does not succeed.

Note, however, that setting sslmode=disable in DATABASE_URL and enabling certificate verification at the same time will result in a startup error.

ExampleELECTRIC_DATABASE_CA_CERTIFICATE_FILE=/root/.postgresql/root.crt

ELECTRIC_REPLICATION_STREAM_ID

VariableELECTRIC_REPLICATION_STREAM_ID
Defaultdefault
Description

Suffix for the logical replication publication and slot name.

ExampleELECTRIC_REPLICATION_STREAM_ID=my-app

Electric

ELECTRIC_SECRET

VariableELECTRIC_SECRETrequired
Description

Secret for shape requests to the HTTP API. This is required unless ELECTRIC_INSECURE is set to true. By default, the Electric API is public and authorises all shape requests against this secret. More details are available in the security guide.

ExampleELECTRIC_SECRET=1U6ItbhoQb4kGUU5wXBLbxvNf

ELECTRIC_INSECURE

VariableELECTRIC_INSECURE
Defaultfalse
Description

When set to true, runs Electric in insecure mode and does not require an ELECTRIC_SECRET. Use with caution. API requests are unprotected and may risk exposing your database. Good for development environments. If used in production, make sure to lock down access to Electric.

ExampleELECTRIC_INSECURE=true

ELECTRIC_INSTANCE_ID

VariableELECTRIC_INSTANCE_ID
DefaultElectric.Utils.uuid4()
Description

A unique identifier for the Electric instance. Defaults to a randomly generated UUID.

ExampleELECTRIC_INSTANCE_ID=some-unique-instance-identifier

ELECTRIC_SERVICE_NAME

VariableELECTRIC_SERVICE_NAME
Defaultelectric
Description

Name of the electric service. Used as a resource identifier and namespace.

ExampleELECTRIC_SERVICE_NAME=my-electric-service

ELECTRIC_ENABLE_INTEGRATION_TESTING

VariableELECTRIC_ENABLE_INTEGRATION_TESTING
Defaultfalse
Description

Expose some unsafe operations that faciliate integration testing. Do not enable this in production.

ExampleELECTRIC_ENABLE_INTEGRATION_TESTING=true

ELECTRIC_LISTEN_ON_IPV6

VariableELECTRIC_LISTEN_ON_IPV6
Defaultfalse
Description

By default, Electric binds to IPv4. Enable this to listen on IPv6 addresses as well.

ExampleELECTRIC_LISTEN_ON_IPV6=true

ELECTRIC_TCP_SEND_TIMEOUT

VariableELECTRIC_TCP_SEND_TIMEOUT
Default30s
Description Timeout for sending a response chunk back to the client. Defaults to 30 seconds.

Slow response processing on the client or bandwidth restristrictions can cause TCP backpressure leading to the error message:

Error while streaming response: :timeout

This environment variable increases this timeout.

ExampleELECTRIC_TCP_SEND_TIMEOUT=60s

ELECTRIC_SHAPE_CHUNK_BYTES_THRESHOLD

VariableELECTRIC_SHAPE_CHUNK_BYTES_THRESHOLD
Default10485760
Description

Limit the maximum size of a shape log response, to ensure they are cached by upstream caches. Defaults to 10MB (10 * 1024 * 1024).

See #1581 for context.

ExampleELECTRIC_SHAPE_CHUNK_BYTES_THRESHOLD=20971520

ELECTRIC_PORT

VariableELECTRIC_PORT
Default3000
Description

Port that the HTTP API is exposed on.

ExampleELECTRIC_PORT=8080

Caching

ELECTRIC_CACHE_MAX_AGE

VariableELECTRIC_CACHE_MAX_AGE
Default60
Description

Default max-age for the cache headers of the HTTP API.

ExampleELECTRIC_CACHE_MAX_AGE=5

ELECTRIC_CACHE_STALE_AGE

VariableELECTRIC_CACHE_STALE_AGE
Default300
Description

Default stale-age for the cache headers of the HTTP API.

ExampleELECTRIC_CACHE_STALE_AGE=5

Storage

ELECTRIC_PERSISTENT_STATE

VariableELECTRIC_PERSISTENT_STATE
DefaultFILE
Description

Where to store shape metadata. Defaults to storing on the filesystem. If provided must be one of MEMORY or FILE.

ExampleELECTRIC_PERSISTENT_STATE=MEMORY

ELECTRIC_STORAGE

VariableELECTRIC_STORAGE
DefaultFILE
Description

Where to store shape logs. Defaults to storing on the filesystem. If provided must be one of MEMORY or FILE.

ExampleELECTRIC_STORAGE=MEMORY

ELECTRIC_STORAGE_DIR

VariableELECTRIC_STORAGE_DIR
Default./persistent
Description

Path to root folder for storing data on the filesystem.

ExampleELECTRIC_STORAGE_DIR=/var/example

Telemetry

These environment variables allow configuration of metric and trace export for visibility into performance of the Electric instance.

ELECTRIC_OTLP_ENDPOINT

VariableELECTRIC_OTLP_ENDPOINToptional
Description

Set an OpenTelemetry endpoint URL to enable telemetry.

ExampleELECTRIC_OTLP_ENDPOINT=https://example.com

ELECTRIC_OTEL_DEBUG

VariableELECTRIC_OTEL_DEBUG
Defaultfalse
Description

Debug tracing by printing spans to stdout, without batching.

ExampleELECTRIC_OTEL_DEBUG=true

ELECTRIC_HNY_API_KEY

VariableELECTRIC_HNY_API_KEYoptional
Description

Honeycomb.io api key. Specify along with HNY_DATASET to export traces directly to Honeycomb, without the need to run an OpenTelemetry Collector.

ExampleELECTRIC_HNY_API_KEY=your-api-key

ELECTRIC_HNY_DATASET

VariableELECTRIC_HNY_DATASEToptional
Description

Name of your Honeycomb Dataset.

ExampleELECTRIC_HNY_DATASET=your-dataset-name

ELECTRIC_PROMETHEUS_PORT

VariableELECTRIC_PROMETHEUS_PORToptional
Description

Expose a prometheus reporter for telemetry data on the specified port.

ExampleELECTRIC_PROMETHEUS_PORT=9090

ELECTRIC_STATSD_HOST

VariableELECTRIC_STATSD_HOSToptional
Description

Enable sending telemetry data to a StatsD reporting endpoint.

ExampleELECTRIC_STATSD_HOST=https://example.com

Logging

ELECTRIC_LOG_LEVEL

VariableELECTRIC_LOG_LEVELoptional
Description

Verbosity of Electric's log output.

Available levels, in the order of increasing verbosity:

  • error
  • warning
  • info
  • debug
ExampleELECTRIC_LOG_LEVEL=debug

ELECTRIC_LOG_COLORS

VariableELECTRIC_LOG_COLORSoptional
Description

Enable or disable ANSI coloring of Electric's log output.

By default, coloring is enabled when Electric's stdout is connected to a terminal. This may be undesirable in certain runtime environments, such as AWS which displays ANSI color codes using escape sequences and may incorrectly split log entries into multiple lines.

ExampleELECTRIC_LOG_COLORS=false

ELECTRIC_LOG_OTP_REPORTS

VariableELECTRIC_LOG_OTP_REPORTS
Defaultfalse
Description

Enable OTP SASL reporting at runtime.

ExampleELECTRIC_LOG_OTP_REPORTS=true

Usage reporting

ELECTRIC_USAGE_REPORTING

These environment variables allow configuration of anonymous usage data reporting back to https://electric-sql.com

VariableELECTRIC_USAGE_REPORTING
Defaulttrue
Description

Configure anonymous usage data about the instance being sent to a central checkpoint service. Collected information is anonymised and doesn't contain any information from the replicated data. You can read more about it in our telemetry docs.

ExampleELECTRIC_USAGE_REPORTING=true