Configuration Methods
The PowerSync Service is configured using key/value pairs in a config file, and supports the following configuration methods:- Inject config as an environment variable (which contains the Base64 encoding of a config file)
- Use a config file mounted on a volume
- Specify the config as a command line parameter (again Base64 encoded)
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 detailedservice.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 thereplication section of the config file:
service.yaml
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 thestorage 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:docker-compose file to configure a replica set as once-off operation:
Postgres Storage
Available since version 1.3.8 of thepowersync-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:- Let PowerSync create the schema (recommended):
- 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.| Postgres Version | Server configuration |
|---|---|
| Below 14 | Separate servers are required for the source and bucket storage. Replication will be blocked if the same server is detected. |
| 14 and above | The source database and bucket storage database can be on the same server. Using the same database (with separate schemas) is supported but may lead to higher CPU usage. Using separate servers remains an option. |
Sync Streams
Your Sync Streams (or legacy Sync Rules) configuration can be in a separate file (recommended) or inline in the main config. Thesync_config: key is used for both Sync Streams and Sync Rules.
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 theclient_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.
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: