> ## Documentation Index
> Fetch the complete documentation index at: https://docs.powersync.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosted Instance Configuration

> How to configure a self-hosted PowerSync Service instance with a config file, and a reference of all available options.

A PowerSync instance is a running deployment of the [PowerSync Service](https://docs.powersync.com/architecture/powersync-service.md): it replicates data from your source database and streams it to clients based on your [Sync Streams](https://docs.powersync.com/sync/streams/overview.md). When self-hosting, you run the Service in your own infrastructure and configure each instance with a config file, as described below.

## Configure Your Instance

A self-hosted instance needs four things before clients can sync:

1. A connection to your [source database](https://docs.powersync.com/configuration/source-db/setup.md), which PowerSync replicates data from.
2. A [bucket storage](https://docs.powersync.com/architecture/powersync-service.md#bucket-storage) database, where the PowerSync Service stores the data it prepares for syncing to clients. MongoDB and Postgres are supported.
3. [Client authentication](https://docs.powersync.com/configuration/auth/overview.md). When getting started, you can use temporary [development tokens](https://docs.powersync.com/configuration/auth/development-tokens.md) instead of setting up a full auth provider.
4. A sync configuration defining what data syncs to which clients, written as [Sync Streams](https://docs.powersync.com/sync/streams/overview.md).

You define all of these in the main config file, along with some operational settings. We recommend keeping the sync configuration in a separate file that the main config references, though it can also be defined inline. The skeleton below shows the most common options; the [Configuration Reference](#configuration-reference) documents all of them.

```yaml service.yaml theme={null}
# Settings for source database replication
replication:
  # Specify database connection details
  # Note only 1 connection is currently supported
  # Multiple connection support is on the roadmap
  connections:
    - type: postgresql
      # The PowerSync server container can access the Postgres DB via the DB's service name.
      # In this case the hostname is pg-db

      # The connection URI or individual parameters can be specified.
      uri: postgresql://postgres:mypassword@pg-db:5432/postgres

      # SSL settings
      sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable'
      # Note: 'disable' is only suitable for local/private networks, not for public networks

# Connection settings for bucket storage (MongoDB and Postgres are supported)
storage:
  # Option 1: MongoDB Storage
  type: mongodb
  uri: mongodb://mongo:27017/powersync_demo
  # Use these if authentication is required. The user should have `readWrite` and `dbAdmin` roles
  # username: myuser
  # password: mypassword

  # Option 2: Postgres Storage
  # type: postgresql
  # This accepts the same parameters as a Postgres replication source connection
  # uri: postgresql://powersync_storage_user:secure_password@storage-db:5432/postgres
  # sslmode: disable

# The port which the PowerSync API server will listen on (defaults to 8080)
port: 8080

# Sync configuration (see the sync_config section below)
sync_config:
  path: sync-config.yaml

# Settings for client authentication
client_auth:
  # Enable this if using Supabase Auth
  # supabase: true
  # supabase_jwt_secret: your-secret

  # JWKS URIs can be specified here.
  jwks_uri: http://demo-backend:6060/api/auth/keys

  # JWKS audience
  audience: ['powersync-dev', 'powersync']

# Settings for telemetry reporting
# See https://docs.powersync.com/maintenance-ops/self-hosting/usage-reporting
telemetry:
  # Opt out of reporting anonymized usage metrics to PowerSync telemetry service
  disable_telemetry_sharing: false

# System-level configuration options
system:
  # Service logging configuration
  logging:
    # Log level for the Service logs
    level: info #  'silly', 'debug', 'verbose', 'http', 'info', 'warn', 'error'
    format: text # 'json' or 'text'
```

> [card] [Example service.yaml](https://github.com/powersync-ja/self-host-demo/blob/main/demos/nodejs/powersync/service.yaml)
>
> The config used by the Node.js (Postgres) demo in `self-host-demo`. Similar examples exist for MongoDB, MySQL, and SQL Server. Use the demos as a working reference for your own setup.

## Supplying the Config File

Both YAML and JSON config files are supported. The PowerSync Service can read the config in three ways:

1. From a config file mounted on a volume
2. From an environment variable containing the Base64 encoding of the config file
3. From a command line parameter (also Base64 encoded)

You can see examples of these methods in the [docker-compose](https://github.com/powersync-ja/self-host-demo/blob/d61cea4f1e0cc860599e897909f11fb54420c3e6/docker-compose.yaml#L46) file of our `self-host-demo` app.

### Environment Variable Substitution

The config file uses custom tags for environment variable substitution.

`!env [variable name]` substitutes the value of the environment variable named `[variable name]`. For example, with the environment variable `PS_MONGO_URI=mongodb://mongo:27017/powersync`, the YAML

```yaml service.yaml theme={null}
storage:
  type: mongodb
  uri: !env PS_MONGO_URI
```

resolves to `uri: mongodb://mongo:27017/powersync`.

Only environment variables with names starting with `PS_` can be substituted.

Substituted values are strings. For options that expect a number or boolean, append `::number` or `::boolean` to the variable name to cast the value. A `::boolean` cast accepts `true` or `false`.

```yaml service.yaml theme={null}
storage:
  max_pool_size: !env PS_STORAGE_POOL_SIZE::number

telemetry:
  disable_telemetry_sharing: !env PS_DISABLE_TELEMETRY::boolean
```

## Configuration Reference

The config file supports the following top-level keys, documented in the sections below:

| Key | Purpose |
| - | - |
| [`replication`](#replication) | Source database connection(s) to replicate from |
| [`storage`](#storage) | Bucket storage database connection |
| [`port`](#port) | Port for the PowerSync API server |
| [`sync_config`](#sync_config) | Sync Streams definition |
| [`client_auth`](#client_auth) | JWT authentication for client connections |
| [`api`](#api) | Admin API tokens and performance/safety limits |
| [`telemetry`](#telemetry) | Telemetry sharing and Prometheus metrics |
| [`healthcheck`](#healthcheck) | Health check probe mechanisms |
| [`migrations`](#migrations) | Storage database schema migration behavior |
| [`system`](#system) | Service logging |

> [!TIP]
>
> A machine-readable [JSON schema](https://unpkg.com/@powersync/service-schema@latest/json-schema/powersync-config.json) of the config file is available, published as `@powersync/service-schema`.
>
> Add this comment to the top of your YAML config file to get validation and autocomplete in editors that support the [YAML language server](https://github.com/redhat-developer/yaml-language-server) (for example VS Code with the YAML extension):
>
> ```yaml theme={null}
> # yaml-language-server: $schema=https://unpkg.com/@powersync/service-schema@latest/json-schema/powersync-config.json
> ```

### `replication`

The `replication` section defines the source database that PowerSync replicates data from. Specify the connection details in `replication.connections`. Only one connection is currently supported; multiple connection support is on our roadmap.

For instructions on preparing your source database, see [Source Database Setup](https://docs.powersync.com/configuration/source-db/setup.md).

> [!NOTE]
>
> Hosted Supabase only allows direct database connections over IPv6, and PowerSync cannot connect using the connection pooler. You can:
>
> * Enable IPv6 for Docker as per [the Docker docs](https://docs.docker.com/config/daemon/ipv6/).
> * Enable IPv4 on your Supabase project.
> * Run Supabase locally.

All connection types support these common options:

**type** `string` *required*

The connection type. One of `postgresql`, `mongodb`, `mysql`, `mssql`, or `convex`.

**id** `string` (default: default)

Unique identifier for the connection. Optional when only a single connection is present.

**tag** `string` (default: default)

Additional meta tag for the connection, used for categorization or grouping.

The remaining options depend on the connection type:

> [accordion] Postgres connection options
>
> ```yaml service.yaml theme={null}
> replication:
>   connections:
>     - type: postgresql
>       uri: postgresql://postgres:mypassword@pg-db:5432/postgres
>       sslmode: verify-full
> ```
>
> **uri** `string`
>
> Connection URI in the format `postgresql://user:password@hostname:5432/database`. Individual connection parameters take precedence over values in the URI.
>
> **hostname** `string`
>
> Database hostname. Required if not specified in `uri`.
>
> **port** `number` (default: 5432)
>
> Database port.
>
> **username** `string`
>
> Database username. Required if not specified in `uri`.
>
> **password** `string`
>
> Database password. Required if not specified in `uri`.
>
> **database** `string`
>
> Database name. Required if not specified in `uri`.
>
> **sslmode** `string` (default: verify-full)
>
> SSL mode: `verify-full`, `verify-ca`, or `disable`. `disable` is only suitable for local/private networks, not for public networks.
>
> **cacert** `string`
>
> CA certificate content in PEM format. Required for `verify-ca`, optional for `verify-full`.
>
> **client\_certificate** `string`
>
> Client certificate content in PEM format, for TLS client authentication.
>
> **client\_private\_key** `string`
>
> Client private key content in PEM format, for TLS client authentication.
>
> **tls\_servername** `string`
>
> Use a servername for TLS that is different from `hostname`.
>
> **slot\_name\_prefix** `string` (default: powersync\_)
>
> Prefix for Postgres logical replication slot names and replication stream names.
>
> **max\_pool\_size** `number` (default: 8)
>
> Maximum number of connections to the source database, per Service process.
>
> **connect\_timeout** `number`
>
> Connection timeout in seconds. Takes precedence over a `connect_timeout` query parameter in the URI.
>
> **snapshot\_socket\_timeout** `number` (default: 30)
>
> Idle timeout in seconds for snapshot connection sockets. If the storage database cannot keep up during the initial snapshot, a storage flush can stall the snapshot for longer than this timeout, which closes the source connection mid-snapshot. This appears in the Service logs as `Socket timed out` errors during the initial snapshot. Increase the timeout if you see these errors. Available since Service version 1.26.0.
>
> **heartbeat\_interval\_seconds** `number` (default: 60)
>
> Interval in seconds between source connection heartbeats. Must be between 5 and 60. Available since Service version 1.24.0.

> [accordion] MongoDB connection options
>
> ```yaml service.yaml theme={null}
> replication:
>   connections:
>     - type: mongodb
>       uri: mongodb+srv://myuser:mypassword@cluster0.abcde.mongodb.net/mydatabase
>       post_images: auto_configure
> ```
>
> **uri** `string` *required*
>
> Connection URI in the format `mongodb://` or `mongodb+srv://`. Standard connection options such as `connectTimeoutMS`, `socketTimeoutMS`, `serverSelectionTimeoutMS`, `maxPoolSize` and `maxIdleTimeMS` can be set as query parameters in the URI.
>
> **database** `string`
>
> Database name. Defaults to the database in the URI path.
>
> **username** `string`
>
> Database username. Defaults to the username in the URI.
>
> **password** `string`
>
> Database password. Defaults to the password in the URI.
>
> **post\_images** `string` (default: off)
>
> Controls how change stream post-images are used: `off`, `auto_configure`, or `read_only`. `auto_configure` is recommended for new instances. See [Post Images](https://docs.powersync.com/configuration/source-db/setup.md#post-images) for details on each option.
>
> **heartbeat\_interval\_seconds** `number` (default: 60)
>
> Interval in seconds between source connection heartbeats. Must be between 5 and 60. Available since Service version 1.24.0.

> [accordion] MySQL connection options
>
> > [!NOTE]
> >
> > MySQL support is currently in a [Beta release](https://docs.powersync.com/resources/feature-status.md).
>
> ```yaml service.yaml theme={null}
> replication:
>   connections:
>     - type: mysql
>       uri: mysql://repl_user:mypassword@mysql-db:3306/inventory
> ```
>
> **uri** `string`
>
> Connection URI in the format `mysql://user:password@hostname:3306/database`. Individual connection parameters take precedence over values in the URI.
>
> **hostname** `string`
>
> Database hostname. Required if not specified in `uri`.
>
> **port** `number` (default: 3306)
>
> Database port.
>
> **username** `string`
>
> Database username. Required if not specified in `uri`.
>
> **password** `string`
>
> Database password. Required if not specified in `uri`.
>
> **database** `string`
>
> Database name. Required if not specified in `uri`.
>
> **cacert** `string`
>
> CA certificate content in PEM format.
>
> **client\_certificate** `string`
>
> Client certificate content in PEM format, for TLS client authentication.
>
> **client\_private\_key** `string`
>
> Client private key content in PEM format, for TLS client authentication.
>
> **binlog\_queue\_memory\_limit** `number` (default: 50)
>
> The combined size in MB of binlog events that can be queued in memory before throttling is applied.

> [accordion] SQL Server connection options
>
> > [!NOTE]
> >
> > SQL Server support is currently in a [Beta release](https://docs.powersync.com/resources/feature-status.md). Also see [SQL Server Additional Configuration](https://docs.powersync.com/configuration/source-db/sql-server-additional-configuration.md).
>
> ```yaml service.yaml theme={null}
> replication:
>   connections:
>     - type: mssql
>       uri: mssql://powersync_user:mypassword@mssql-db:1433/inventory
> ```
>
> **uri** `string`
>
> Connection URI in the format `mssql://user:password@hostname:1433/database`. Individual connection parameters take precedence over values in the URI.
>
> **hostname** `string`
>
> Database hostname. Required if not specified in `uri`.
>
> **port** `number` (default: 1433)
>
> Database port.
>
> **username** `string`
>
> Database username. Required if not specified in `uri` or `authentication`.
>
> **password** `string`
>
> Database password. Required if not specified in `uri` or `authentication`.
>
> **database** `string`
>
> Database name. Required if not specified in `uri`.
>
> **schema** `string` (default: dbo)
>
> The database schema to replicate from.
>
> **cacert** `string`
>
> CA certificate content in PEM format. Available since Service version 1.25.0.
>
> **tls\_servername** `string`
>
> Use a servername for TLS that is different from `hostname`. Available since Service version 1.25.0.
>
> **authentication** `object`
>
> Alternative authentication configuration, instead of `username` and `password`.
>
> **properties**
>
> **type** `string` *required*
>
> Authentication method: `default` (SQL Server login) or `azure-active-directory-service-principal-secret`.
>
> **options** `object` *required*
>
> For `default`: `userName` and `password`. For `azure-active-directory-service-principal-secret`: `clientId`, `clientSecret` and `tenantId` from your registered Azure application.
>
> **additionalConfig** `object`
>
> Additional replication settings.
>
> **properties**
>
> **pollingIntervalMs** `number` (default: 1000)
>
> Interval in milliseconds to wait between CDC polling cycles.
>
> **pollingBatchSize** `number` (default: 10)
>
> Maximum number of transactions to poll per polling cycle.
>
> **trustServerCertificate** `boolean` (default: false)
>
> Whether to trust the server certificate. Set to `true` for local development and self-signed certificates.
>
> **heartbeat\_interval\_seconds** `number` (default: 60)
>
> Interval in seconds between source connection heartbeats. Must be between 5 and 60. Available since Service version 1.24.0.

> [accordion] Convex connection options
>
> > [!NOTE]
> >
> > The Convex replicator is currently released as an [experimental feature](https://docs.powersync.com/resources/feature-status.md) and is available since Service version v1.22.0. See [Convex source database setup](https://docs.powersync.com/configuration/source-db/setup.md#convex).
>
> ```yaml service.yaml theme={null}
> replication:
>   connections:
>     - type: convex
>       deployment_url: https://happy-animal-123.convex.cloud
>       deploy_key: !env PS_CONVEX_DEPLOY_KEY
> ```
>
> **deployment\_url** `string` *required*
>
> The URL of your Convex deployment.
>
> **deploy\_key** `string` *required*
>
> A deploy key for the Convex deployment, used to authenticate against the Convex Streaming Export API.
>
> **polling\_interval\_ms** `number` (default: 1000)
>
> Interval in milliseconds between polling for new changes.
>
> **request\_timeout\_ms** `number` (default: 60000)
>
> Timeout in milliseconds for requests to the Convex API.

### `storage`

The PowerSync Service requires a storage database to store the data and metadata for [buckets](https://docs.powersync.com/architecture/powersync-service.md#bucket-system). You can use either MongoDB or Postgres for this purpose.

> [!NOTE]
>
> The *bucket storage database* is separate from your *source database*.

**type** `string` *required*

The storage backend type: `mongodb` or `postgresql`.

**max\_pool\_size** `number` (default: 8)

Maximum number of connections to the storage database, per Service process.

**default\_storage\_version** `number`

Storage version to use when deploying a Sync Config that does not specify a storage version. When unset, MongoDB bucket storage uses [storage version 4](https://docs.powersync.com/sync/advanced/storage-version-4.md) and Postgres bucket storage uses version 2. Service versions 1.26.x default to version 2. An explicit `config.storage_version` takes precedence over this default. Available since Service version 1.26.0.

> [!NOTE]
>
> Postgres bucket storage does not currently support version 4.

#### MongoDB Storage

```yaml service.yaml theme={null}
storage:
  type: mongodb
  uri: mongodb://mongo:27017/powersync_demo
```

**uri** `string` *required*

Connection URI in the format `mongodb://` or `mongodb+srv://`.

**database** `string`

Database name. Defaults to the database in the URI path.

**username** `string`

Database username. Defaults to the username in the URI. See **Required Permissions** below for the roles the user needs.

**password** `string`

Database password. Defaults to the password in the URI.

**clear\_batch\_throttle\_rate** `number` (default: 0.2)

Throttles the clearing of old bucket data after deploying a new sync configuration, by pausing between batches. The pause is proportional to the previous batch duration. Increase this to reduce the impact of clear operations on the storage cluster, or use `0` to clear as fast as possible. Must be between 0 and 20. Available since Service version 1.24.0.

**bulk\_read\_preference** `string`

Read preference for bulk checksum and bucket data reads: `primary`, `primaryPreferred`, `secondary`, `secondaryPreferred`, or `nearest`. If unset, MongoDB driver defaults are used. This is an experimental option and may be removed in a future release. Available since Service version 1.23.2.

**stats\_read\_preference** `string`

Read preference for collection storage statistics: `primary`, `primaryPreferred`, `secondary`, `secondaryPreferred`, or `nearest`. If unset, MongoDB driver defaults are used. Not relevant for most self-hosted deployments. Available since Service version 1.28.2.

**chunk\_compaction\_concurrency** `number`

Maximum number of buckets that chunk-merge compaction processes at the same time on [storage version 4](https://docs.powersync.com/sync/advanced/storage-version-4.md). Defaults to `4` when `object_storage` is configured, otherwise `2`. Must be between 1 and 64. Full compaction still processes one bucket at a time.

Chunk-merge compaction runs after initial replication, before the new Sync Config becomes active, and as part of scheduled [`compact`](https://docs.powersync.com/maintenance-ops/compacting-buckets) runs. With object storage, request latency, not processing, takes most of the time per bucket. A higher value lets the Service merge more buckets during those waits, which shortens the delay before activation. All compaction jobs in a Service process share this limit. Available since Service version 1.26.1.

**object\_storage** `object`

Stores large blocks of bucket data in Amazon S3 or an S3-compatible object store instead of MongoDB. Requires Service version 1.26.0 or later with [storage version 4](https://docs.powersync.com/sync/advanced/storage-version-4.md), the default since Service version 1.27.0. Sync Configs on version 2 keep all data in MongoDB even when this is configured.

Follow [Self-Hosted S3 Setup](https://docs.powersync.com/sync/advanced/storage-version-4.md#self-hosted-s3-setup) to create the bucket, configure permissions and lifecycle settings, and enable object storage in the Service. The fields below describe the available configuration options.

**properties**

**type** `string` *required*

Must be `s3`.

**bucket** `string` *required*

Name of the S3 bucket.

**region** `string`

Region of the S3 bucket.

**prefix** `string`

Key prefix for stored objects.

**endpoint** `string`

Custom endpoint, for S3-compatible object storage providers.

**force\_path\_style** `boolean`

Use path-style addressing, required by some S3-compatible providers.

**access\_key\_id** `string`

Access key ID for authentication.

**secret\_access\_key** `string`

Secret access key for authentication.

**concurrency\_limit** `number` (default: 64)

Maximum number of concurrent object storage requests. Service versions before 1.26.1 default to `16`.

**defaults\_mode** `string` (default: standard)

Sets the timeouts for all object storage requests at once, based on the expected latency between the Service and the object storage endpoint, mirroring the AWS SDK's [smart configuration defaults](https://docs.aws.amazon.com/sdkref/latest/guide/feature-smart-config-defaults.html). `standard` is safe for most deployments, so you can usually leave this unset. Use `in-region` when the Service and the bucket run in the same region and you want stalled requests to fail faster, or `mobile` when the endpoint is slow enough that the standard timeouts cause spurious failures. `cross-region` is accepted for compatibility with the AWS SDK.

When this option is unset, the Service reads the `AWS_DEFAULTS_MODE` environment variable, then falls back to `standard`. Setting `defaults_mode` in an AWS shared config file has no effect. Available since Service version 1.26.0.

**inline\_threshold\_bytes** `number` (default: 16384)

Chunks smaller than this byte threshold stay inline in MongoDB instead of being offloaded to object storage.

##### Required Permissions

The Service creates and manages all collections and indexes in the storage database itself, so no manual schema setup is needed. When authentication is enabled, the user needs the built-in `readWrite` and `dbAdmin` roles on the storage database:

```text theme={null}
readWrite@<storage_database>
dbAdmin@<storage_database>
```

No access beyond the storage database is required. The `readWrite` role covers regular operation, including creating and dropping collections and indexes. The `dbAdmin` role is additionally needed to drop the database when an instance is torn down.

Create the user with:

```javascript theme={null}
use powersync_demo
db.createUser({
  user: "powersync_storage_user",
  pwd: "secure_password",
  roles: ["readWrite", "dbAdmin"]
})
```

MongoDB authenticates against the database where the user was created, so creating the user in the storage database itself works with the connection URI shown above. If you create the user in a different database, such as `admin`, add `authSource=admin` to the connection URI. On MongoDB Atlas, assign the same two roles restricted to the storage database.

##### Replica Set Requirement

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](https://docs.powersync.com/maintenance-ops/self-hosting/deployment-architecture.md) deployments.

[MongoDB Atlas](https://www.mongodb.com/products/platform/atlas-database) enables replica sets by default for new clusters.

However, if you're using your own environment you can enable this manually by running:

```bash theme={null}
mongosh "mongodb+srv://powersync.abcdef.mongodb.net/" --apiVersion 1 --username myuser --eval 'try{rs.status().ok && quit(0)} catch {} rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "mongo:27017" }]})'
```

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:

```yaml docker-compose.yaml theme={null}
  # Initializes the MongoDB replica set. This service will not usually be actively running
  mongo-rs-init:
    image: mongo:9.0
    depends_on:
      - mongo
    restart: "no"
    entrypoint:
      - bash
      - -c
      - 'sleep 10 && mongosh --host mongo:27017 --eval ''try{rs.status().ok && quit(0)} catch {} rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "mongo:27017" }]})'''
```

#### Postgres Storage

You can use Postgres as an alternative bucket storage database.

```yaml service.yaml theme={null}
storage:
  type: postgresql
  uri: postgresql://powersync_storage_user:secure_password@storage-db:5432/postgres
```

Postgres storage accepts the same connection options as a [Postgres replication connection](#replication): `uri`, `hostname`, `port`, `username`, `password`, `database`, `sslmode`, `cacert`, `client_certificate`, `client_private_key`, `tls_servername` and `connect_timeout`. In addition, batch limits can be tuned:

**batch\_limits** `object`

Limits for batch operations during replication. Increasing these limits can improve replication performance, at the cost of higher memory usage.

**properties**

**max\_estimated\_size** `number` (default: 5000000)

Maximum estimated byte size of operations written in a single transaction.

**max\_record\_count** `number` (default: 2000)

Maximum number of records written in a single transaction.

**max\_current\_data\_batch\_size** `number` (default: 50000000)

Maximum byte size of `current_data` documents looked up at a time.

##### 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):

```sql theme={null}
CREATE USER powersync_storage_user WITH PASSWORD 'secure_password';
-- The user should only have access to the schema it created
GRANT CREATE ON DATABASE postgres TO powersync_storage_user;
```

2. Or manually create the schema:

```sql theme={null}
CREATE USER powersync_storage_user WITH PASSWORD 'secure_password';
CREATE SCHEMA IF NOT EXISTS powersync AUTHORIZATION powersync_storage_user;
GRANT CONNECT ON DATABASE postgres TO powersync_storage_user;
GRANT USAGE ON SCHEMA powersync TO powersync_storage_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA powersync TO powersync_storage_user;
```

A demo app with Postgres bucket storage is available [here](https://github.com/powersync-ja/self-host-demo/tree/main/demos/nodejs-postgres-bucket-storage).

##### 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. |

### `port`

The `port` setting determines where clients and tools connect to your instance. Change it if the default conflicts with another service in your deployment.

**port** `number` (default: 8080)

The port on which the PowerSync API server will listen for connections. Can be specified as a number or string.

### `sync_config`

The `sync_config` section points the Service at your [Sync Streams](https://docs.powersync.com/sync/streams/overview.md) definition, usually a separate file referenced with `path`:

```yaml service.yaml theme={null}
sync_config:
  path: sync-config.yaml
```

```yaml sync-config.yaml theme={null}
config:
  edition: 3
streams:
  todos:
    auto_subscribe: true
    query: SELECT * FROM todos WHERE owner_id = auth.user_id()
```

**path** `string`

Path to the sync configuration YAML file. Ensure the file is available at that path, e.g. in the same directory as your main config or on a mounted volume.

**content** `string`

The sync configuration inline as a string, as an alternative to `path`.

**exit\_on\_error** `boolean` (default: true)

Whether to exit the process when the configured Sync Config has a parsing error or a fatal validation error, such as using a feature that the source does not support.

Since Service version 1.28.0, setting this to `false` keeps the Service running without storing, replicating, or serving the rejected config to clients. Pending config processing stops, while any previous active config continues replicating and serving clients. Inspect `deploying_sync_rules.errors[]` in the [Diagnostics API](https://docs.powersync.com/maintenance-ops/self-hosting/diagnostics.md#errors-and-warnings) to identify and correct the errors.

The top-level `sync_rules` key is a deprecated alias for `sync_config`. Use `sync_config` in new configurations.

### `client_auth`

The `client_auth` section defines how the Service verifies your app's users when they connect to sync. Clients authenticate with JWTs, which the Service validates using the settings here. For more details, see [Client Authentication](https://docs.powersync.com/configuration/auth/overview.md).

```yaml service.yaml theme={null}
client_auth:
  # Enable this if using Supabase Auth
  # supabase: true
  # supabase_jwt_secret: your-secret

  # Option 1: JWKS URI endpoint
  jwks_uri: http://demo-backend:6060/api/auth/keys

  # Option 2: Static collection of public keys for JWT verification
  # jwks:
  #   keys:
  #     - kty: 'RSA'
  #       n: '[rsa-modulus]'
  #       e: '[rsa-exponent]'
  #       alg: 'RS256'
  #       kid: '[key-id]'

  # JWKS audience
  audience: ['powersync-dev', 'powersync']
```

**jwks\_uri** `string | string[]`

URI or array of URIs pointing to JWKS endpoints, used to fetch public keys for JWT verification.

**jwks** `object`

Inline JWKS configuration, as an alternative or in addition to `jwks_uri`.

**properties**

**keys** `object[]` *required*

An array of JSON Web Keys (JWKs). Supported key types are RSA (`RS256`, `RS384`, `RS512`), HMAC (`HS256`, `HS384`, `HS512`), OKP (`EdDSA` with `Ed25519` or `Ed448`) and EC (`ES256`, `ES384`, `ES512` with curves `P-256`, `P-384` or `P-521`). See [Custom Authentication](https://docs.powersync.com/configuration/auth/custom.md) for details.

**supabase** `boolean` (default: false)

Enables Supabase authentication integration. JWKS details are derived from the Supabase connection. See [Supabase Auth](https://docs.powersync.com/configuration/auth/supabase-auth.md).

**supabase\_jwt\_secret** `string`

Legacy JWT secret for Supabase authentication (HS256 shared secret).

**audience** `string[]`

Valid audiences for JWT validation.

> [!NOTE]
>
> 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](https://docs.powersync.com/configuration/auth/custom.md) for more details.

### `api`

The `api` section protects the Service's admin API routes with access tokens, and sets limits that protect the Service from excessive load. Configure `tokens` if you use the [PowerSync CLI](https://docs.powersync.com/tools/cli.md) against this instance; the limits rarely need changing.

**tokens** `string[]`

Access tokens for the Service's admin API routes, provided by clients as a Bearer token. If no tokens are configured, the admin API routes reject all requests.

**parameters** `object`

Performance and safety parameters for the API.

**properties**

**max\_concurrent\_connections** `number` (default: 200)

Maximum number of connections (HTTP streams or WebSockets) per API process.

**max\_data\_fetch\_concurrency** `number` (default: 10)

Maximum concurrency when fetching data from storage. This should not be significantly more than `storage.max_pool_size`, otherwise it would block on the pool. Increasing this can significantly increase memory usage in some cases.

**max\_buckets\_per\_connection** `number` (default: 1000)

Maximum number of buckets for each connection. More buckets increase latency and memory usage. While the actual number is controlled by your sync configuration, this hard limit ensures that the Service errors instead of crashing when the sync configuration is misconfigured.

**max\_parameter\_query\_results** `number` (default: 1000)

Related to `max_buckets_per_connection`, but this limit applies directly to parameter query results, before they are converted into a unique set of buckets.

**checkpoint\_request\_retention\_minutes** `number` (default: 60)

Number of minutes to keep client-requested write checkpoint records. Expired records are removed by the compact job. Must be a positive integer. Available since Service version 1.24.0.

**bucket\_count\_cache\_ttl\_minutes** `number` (default: 60)

How long to keep cached bucket counts before refreshing them, in minutes. Bucket counts may be affected by compacting. Available since Service version 1.23.2.

### `telemetry`

The `telemetry` section controls the operational metrics the Service shares with PowerSync and exposes for your own monitoring. See [Usage Reporting](https://docs.powersync.com/maintenance-ops/self-hosting/usage-reporting.md) and [Monitoring](https://docs.powersync.com/maintenance-ops/self-hosting/monitoring.md) for details.

**disable\_telemetry\_sharing** `boolean` *required*

When `true`, disables sharing of anonymized usage metrics with the PowerSync telemetry service.

**prometheus\_port** `number`

Port on which Prometheus metrics will be exposed. When set, metrics will be available on this port for scraping.

### `healthcheck`

Configures how health check status is exposed. See [Health Checks](https://docs.powersync.com/maintenance-ops/self-hosting/healthchecks.md) for details on the available probes and endpoints.

**probes** `object`

Mechanisms for exposing health check data. If this is not configured, the Service defaults to legacy behavior for backwards compatibility (filesystem probes always enabled, plus HTTP probes depending on the Service mode). When `probes` is configured, each mechanism requires explicit opt-in.

**properties**

**use\_filesystem** `boolean` (default: false)

Enables exposing health check status via filesystem files.

**use\_http** `boolean` (default: false)

Enables exposing health check status via HTTP endpoints.

### `migrations`

The `migrations` section controls whether the Service updates its bucket storage database schema automatically when a new version starts up. Most deployments can keep the default automatic behavior.

**disable\_auto\_migration** `boolean` (default: false)

When `true`, disables automatic storage database schema migrations on startup. Migrations can then be triggered externally by altering the container `command`.

### `system`

The `system` section configures how the Service itself runs. Currently this covers logging.

**logging** `object`

Service logging configuration.

**properties**

**level** `string` (default: info)

Log level for the Service logs: `silly`, `debug`, `verbose`, `http`, `info`, `warn`, or `error`. The `PS_LOG_LEVEL` environment variable takes precedence over this option.

**format** `string`

Log output format: `json` or `text`. Defaults to `text`, or to `json` when the `NODE_ENV` environment variable is set to `production`. The `PS_LOG_FORMAT` environment variable takes precedence over this option.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.