Skip to main content

Configuration Methods

The PowerSync Service is configured using key/value pairs in a config file, and supports the following configuration methods:
  1. Inject config as an environment variable (which contains the Base64 encoding of a config file)
  2. Use a config file mounted on a volume
  3. Specify the config as a command line parameter (again Base64 encoded)
Both YAML and JSON config files are supported. You can see examples of the above configuration methods in the docker-compose file of our self-host-demo app.

Configuration File Structure

Below is a skeleton config file you can copy and paste to edit locally:
service.yaml

Example

A detailed service.yaml config example with additional comments can be found here:

self-host-demo/config/service.yaml at main · powersync-ja/self-host-demo

Config File Schema

The config file schema is available here:

@powersync/service-schema

Source Database Connections

Specify the connection to your source database in the replication section of the config file:
service.yaml
For details on connecting to your source database, see Connect PowerSync to Your Source Database in the Setup Guide.
If you are using hosted Supabase, you will need to enable IPv6 for Docker as per the Docker docsIf your host OS does not support Docker IPv6 e.g. macOS, you will need to run Supabase locally.This is because Supabase only allows direct database connections over IPv6 — PowerSync cannot connect using the connection pooler.

Bucket Storage Database

The PowerSync Service requires a storage database to store the data and metadata for buckets. You can use either MongoDB or Postgres for this purpose. The bucket storage database should be specified in the storage section of the config file:
service.yaml
The bucket storage database is separate from your source database.

MongoDB Storage

MongoDB requires at least one replica set node. A single node is fine for development/staging environments, but a 3-node replica set is recommended for production deployments. MongoDB Atlas enables replica sets by default for new clusters. However, if you’re using your own environment you can enable this manually by running:
If you are rolling your own Docker environment, you can include this init script in your docker-compose file to configure a replica set as once-off operation:

Postgres Storage

Available since version 1.3.8 of the powersync-service, you can use Postgres as an alternative bucket storage database.

Database Setup

You’ll need to create a dedicated user and schema for PowerSync bucket storage. You can either:
  1. Let PowerSync create the schema (recommended):
  1. Or manually create the schema:

Demo App

A demo app with Postgres bucket storage is available here.

Postgres Version Requirements

Separate Postgres servers are required for replication connections (i.e. source database) and bucket storage if using Postgres versions below 14.

Sync Streams

Your Sync Streams (or legacy Sync Rules) configuration can be in a separate file (recommended) or inline in the main config. The sync_config: key is used for both Sync Streams and Sync Rules.
Separate file: Referencing a file with path: keeps your main config tidy and makes editing Sync Streams/Sync Rules easier. Ensure the file is available at that path (e.g. in the same directory as your main config or on a mounted volume).
For more information, see Sync Streams (recommended) or Sync Rules (legacy).
To verify that your Sync Rules are functioning correctly, inspect the contents of your bucket storage database.

MongoDB Example

If you are running MongoDB in Docker, run the following:

Client Authentication

Client authentication is configured in the client_auth section:
service.yaml
For production environments, we recommend using JWKS with asymmetric keys (RS256, EdDSA, or ECDSA) rather than shared secrets (HS256). Asymmetric keys provide better security through public/private key separation and easier key rotation. See Custom Authentication for more details.
For more details, see Client Authentication.

Environment Variables

The config file uses custom tags for environment variable substitution. Using !env [variable name] will substitute the value of the environment variable named [variable name]. Only environment variables with names starting with PS_ can be substituted. See examples here:

self-host-demo/config/service.yaml at main · powersync-ja/self-host-demo