Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions configuration/source-db/postgres-maintenance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@
Inactive slots can be dropped using:

```bash
select slot_name, pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false;

Check warning on line 31 in configuration/source-db/postgres-maintenance.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

configuration/source-db/postgres-maintenance.mdx#L31

Did you really mean 'slot_name'?
```

Postgres prevents active slots from being dropped. If it does happen (e.g. while a PowerSync instance is disconnected), PowerSync would automatically re-create the slot, and restart replication.

### WAL Slot Invalidation

Postgres can invalidate a replication slot when the amount of retained WAL data exceeds the `max_slot_wal_keep_size` limit. This is most likely to happen during a long-running initial snapshot — PowerSync must hold the slot open while copying your entire dataset, and WAL accumulates throughout that time.

If the slot is invalidated mid-snapshot, PowerSync detects this early and aborts with error [`PSYNC_S1146`](/debugging/error-codes#psync_s11xx-postgres-replication-issues) rather than continuing a doomed snapshot. The fix is to increase `max_slot_wal_keep_size` on the source database and delete the existing replication slot. PowerSync will automatically create a new slot and restart the snapshot.

To check the current `max_slot_wal_keep_size` value:

```sql
SHOW max_slot_wal_keep_size
```

A value of `-1` means unlimited (no cap on WAL retention). If your database has a cap set, make sure it is large enough to cover the full WAL growth expected during an initial snapshot. See [Managing & Monitoring Replication Lag](/maintenance-ops/production-readiness-guide#managing--monitoring-replication-lag) for guidance on choosing an appropriate value.

You can monitor slot health in real time using the [Diagnostics API](/maintenance-ops/self-hosting/diagnostics). The `wal_status`, `safe_wal_size`, and `max_slot_wal_keep_size` fields on each connection object show how much WAL budget remains. The PowerSync Service also logs a warning when less than 50% of the WAL budget remains during a snapshot.

### Maximum Replication Slots

Postgres is configured with a maximum number of replication slots per server. Since each PowerSync instance uses one replication slot for replication and an additional one while deploying a new Sync Streams/Rules version, the maximum number of PowerSync instances connected to one Postgres server is equal to the maximum number of replication slots, minus 1\.
Expand Down
29 changes: 28 additions & 1 deletion debugging/error-codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

This reference documents PowerSync error codes organized by component, with troubleshooting suggestions for developers. Use the search bar to look up specific error codes (e.g., `PSYNC_R0001`).

# PSYNC_Rxxxx: Sync Rules issues

Check warning on line 9 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L9

Did you really mean 'PSYNC_Rxxxx'?

- **PSYNC_R0001**:
Catch-all [Sync Rules](/sync/rules/overview) parsing error, if no more specific error is available
Expand All @@ -23,7 +23,7 @@

## PSYNC_R24xx: SQL security warnings

# PSYNC_Sxxxx: Service issues

Check warning on line 26 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L26

Did you really mean 'PSYNC_Sxxxx'?

- **PSYNC_S0001**:
Internal assertion.
Expand Down Expand Up @@ -62,6 +62,11 @@

This may occur if there is very deep nesting in JSON or embedded documents.

- **PSYNC_S1005**:
Storage version not supported.

This could be caused by a downgrade to a version that does not support the current storage version.

## PSYNC_S11xx: Postgres replication issues

- **PSYNC_S1101**:
Expand Down Expand Up @@ -121,7 +126,7 @@
Create a publication using `WITH (publish = "insert, update, delete, truncate")` (the default).

- **PSYNC_S1143**:
Publication uses publish_via_partition_root.

Check warning on line 129 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L129

Did you really mean 'publish_via_partition_root'?

- **PSYNC_S1144**:
Invalid Postgres server configuration for replication and sync bucket storage.
Expand All @@ -143,6 +148,17 @@
An alternative is to create explicit policies for the replication role. If you have done that,
you may ignore this warning.

- **PSYNC_S1146**:
Replication slot invalidated.

The replication slot was invalidated by PostgreSQL, typically because WAL retention exceeded `max_slot_wal_keep_size` during a long-running snapshot. Increase `max_slot_wal_keep_size` on the source database and delete the existing replication slot to recover. PowerSync will create a new slot and restart replication automatically.

Other causes: `rows_removed` (catalog rows needed by the slot were removed), `wal_level_insufficient`, or `idle_timeout`.

`idle_timeout` is a PostgreSQL 18+ slot invalidation, in this case increase `idle_replication_slot_timeout` instead of `max_slot_wal_keep_size`.

See [Managing & Monitoring Replication Lag](/maintenance-ops/production-readiness-guide#managing--monitoring-replication-lag) for guidance on sizing `max_slot_wal_keep_size`.

## PSYNC_S12xx: MySQL replication issues

## PSYNC_S13xx: MongoDB replication issues
Expand Down Expand Up @@ -200,7 +216,7 @@
The MongoDB Change Stream has been invalidated.

Possible causes:
- Some change stream documents do not have postImages.

Check warning on line 219 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L219

Did you really mean 'postImages'?
- startAfter/resumeToken is not valid anymore.
- The replication connection has changed.
- The database has been dropped.
Expand Down Expand Up @@ -235,6 +251,17 @@
Possible causes:
- Older data has been cleaned up due to exceeding the retention period.

## PSYNC_S16xx: MSSQL replication issues

- **PSYNC_S1601**:
A replicated source table's capture instance has been dropped during a polling cycle.

Possible causes:
- CDC has been disabled for the table.
- The table has been dropped, which also drops the capture instance.

Replication for the table will only resume once CDC has been re-enabled for the table.

## PSYNC_S2xxx: Service API

- **PSYNC_S2001**:
Expand Down Expand Up @@ -264,15 +291,15 @@

Common causes:
1. **JWT signing key mismatch** (Supabase): The client is using tokens signed with a different key type (legacy vs. new JWT signing keys) than PowerSync expects. If you've migrated to new JWT signing keys, ensure users sign out and back in to get fresh tokens. See [Migrating from Legacy to New JWT Signing Keys](/installation/authentication-setup/supabase-auth#migrating-from-legacy-to-new-jwt-signing-keys).
2. **Missing or invalid key ID (kid)**: The token's kid header doesn't match any keys in PowerSync's keystore.

Check warning on line 294 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L294

Did you really mean 'keystore'?
3. **Incorrect JWT secret or JWKS endpoint**: Verify your authentication configuration matches your auth provider's settings.

- **PSYNC_S2102**:
Could not verify the auth token signature.

Typical causes include:
1. Token kid is not found in the keystore.

Check warning on line 301 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L301

Did you really mean 'keystore'?
2. Signature does not match the kid in the keystore.

Check warning on line 302 in debugging/error-codes.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

debugging/error-codes.mdx#L302

Did you really mean 'keystore'?

- **PSYNC_S2103**:
Token has expired. Check the expiry date on the token.
Expand Down Expand Up @@ -303,7 +330,7 @@
- **PSYNC_S2203**:
IPs in this range are not supported.

Make sure to use a publically-accessible JWKS URI.
Make sure to use a publicly-accessible JWKS URI.

- **PSYNC_S2204**:
JWKS request failed.
Expand Down
6 changes: 5 additions & 1 deletion maintenance-ops/production-readiness-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
```typescript App Entry Point
createRoot(document.getElementById("root")!,
{
onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {

Check warning on line 57 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L57

Did you really mean 'errorInfo'?
console.warn('Uncaught error', error, errorInfo.componentStack);
}),
// Callback called when React catches an error in an ErrorBoundary.
Expand Down Expand Up @@ -272,23 +272,27 @@
To view the current replication slots that are being used by PowerSync you can run the following query:

```
SELECT slot_name,

Check warning on line 275 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L275

Did you really mean 'slot_name'?
plugin,
slot_type,

Check warning on line 277 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L277

Did you really mean 'slot_type'?
active,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS replication_lag

Check warning on line 279 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L279

Did you really mean 'restart_lsn'?

Check warning on line 279 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L279

Did you really mean 'replication_lag'?
FROM pg_replication_slots;

Check warning on line 280 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L280

Did you really mean 'pg_replication_slots'?
```

To view the current configured value of the `max_slot_wal_keep_size` you can run the following query:
```
SELECT setting as max_slot_wal_keep_size

Check warning on line 285 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L285

Did you really mean 'max_slot_wal_keep_size'?
FROM pg_settings

Check warning on line 286 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L286

Did you really mean 'pg_settings'?
WHERE name = 'max_slot_wal_keep_size'

Check warning on line 287 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L287

Did you really mean 'max_slot_wal_keep_size'?
```

It's recommended to check the current replication slot lag and `max_slot_wal_keep_size` when deploying Sync Streams/Sync Rules changes to your PowerSync Service instance, especially when you're working with large database volumes.
If you notice that the replication lag is greater than the current `max_slot_wal_keep_size` it's recommended to increase value of the `max_slot_wal_keep_size` on the connected source Postgres database to accommodate for the lag and to ensure the PowerSync Service can complete initial replication without further delays.
If you notice that the replication lag is greater than the current `max_slot_wal_keep_size` it's recommended to increase the value of `max_slot_wal_keep_size` on the connected source Postgres database to accommodate for the lag and to ensure the PowerSync Service can complete initial replication without further delays.

If the slot is invalidated, PowerSync aborts the snapshot early and surfaces error [`PSYNC_S1146`](/debugging/error-codes#psync_s11xx-postgres-replication-issues). After increasing `max_slot_wal_keep_size`, delete the existing replication slot. PowerSync will automatically create a new slot and restart the snapshot.

You can also monitor slot health in real time using the [Diagnostics API](/maintenance-ops/self-hosting/diagnostics). Each connection object in the response includes `wal_status` (slot status from `pg_replication_slots`), `safe_wal_size` (bytes remaining before potential invalidation), and `max_slot_wal_keep_size` (the configured cap). The PowerSync Service logs a warning when less than 50% of the WAL budget is remaining during a snapshot.

### Managing Replication Slots

Expand All @@ -297,16 +301,16 @@

To check which replication slots used by a PowerSync Service are no longer active, the following query can be executed against the source Postgres database:
```
SELECT slot_name,

Check warning on line 304 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L304

Did you really mean 'slot_name'?
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS replication_lag

Check warning on line 305 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L305

Did you really mean 'restart_lsn'?

Check warning on line 305 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L305

Did you really mean 'replication_lag'?
FROM pg_replication_slots WHERE active = false;

Check warning on line 306 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L306

Did you really mean 'pg_replication_slots'?
```

If you have inactive replication slots that need to be cleaned up, you can drop them using the following query:
```
SELECT slot_name,

Check warning on line 311 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L311

Did you really mean 'slot_name'?
pg_drop_replication_slot(slot_name)
FROM pg_replication_slots where active = false;

Check warning on line 313 in maintenance-ops/production-readiness-guide.mdx

View check run for this annotation

Mintlify / Mintlify Validation (powersync) - vale-spellcheck

maintenance-ops/production-readiness-guide.mdx#L313

Did you really mean 'pg_replication_slots'?
```

The alternative to manually checking for inactive replication slots would be to configure the `idle_replication_slot_timeout` configuration parameter on the source Postgres database.
Expand Down
31 changes: 20 additions & 11 deletions maintenance-ops/self-hosting/diagnostics.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
---
title: "Diagnostics"
description: "How to use the PowerSync Service Diagnostics API"
description: "How to use the PowerSync Service Diagnostics API to inspect replication status, errors, and slot health."
---

All self-hosted PowerSync Service instances ship with a Diagnostics API.
This API provides the following diagnostic information:

- Connections → Connected backend source database and any active errors associated with the connection.
- Active Sync Streams / Sync Rules → Currently deployed Sync Streams (or legacy Sync Rules) and its status.
All self-hosted PowerSync Service instances ship with a Diagnostics API for inspecting replication state, surfacing errors, and monitoring source database health.

## CLI

Expand All @@ -17,27 +13,40 @@ If you have the [PowerSync CLI](/tools/cli) installed, use `powersync status` to
powersync status

# Extract a specific field
powersync status --output=json | jq '.connections[0]'
powersync status --output=json | jq '.data.active_sync_rules'
```

## Diagnostics API

# Configuration
### Configuration

1. To enable the Diagnostics API, specify an API token in your PowerSync YAML file:
1. Specify an API token in your PowerSync YAML file:

```yaml service.yaml
api:
tokens:
- YOUR_API_TOKEN
```
<Warning>Make sure to use a secure API token as part of this configuration</Warning>

<Warning>Use a secure, randomly generated API token.</Warning>

2. Restart the PowerSync Service.

3. Once configured, send an HTTP request to your PowerSync Service Diagnostics API endpoint. Include the API token set in step 1 as a Bearer token in the Authorization header.
3. Send a POST request to the diagnostics endpoint, passing the token as a Bearer token:

```shell
curl -X POST http://localhost:8080/api/admin/v1/diagnostics \
-H "Authorization: Bearer YOUR_API_TOKEN"
```

### Response structure

The response `data` object contains information about:

**`connections`** — whether PowerSync can reach the configured source database, and any connection-level errors.

**`active_sync_rules`** — the currently serving sync config (Sync Streams/Sync Rules). Shows which replication slot is in use, whether the initial snapshot has completed, replication lag, which tables are being replicated, and any errors.

**`deploying_sync_rules`** — only present while a new sync config is being deployed. PowerSync runs the new snapshot in parallel so clients continue to be served by the existing active config. Once the snapshot completes, this section disappears and `active_sync_rules` updates. Errors during deployment (snapshot failures, configuration problems) surface here rather than in `active_sync_rules`.

For Postgres sources on version 13 or later, each connection entry in `active_sync_rules` also includes `wal_status`, `safe_wal_size`, and `max_slot_wal_keep_size`. These fields show how much WAL budget remains before the replication slot could be invalidated, which is particularly useful to monitor when deploying a new sync config against a large database. When the WAL budget drops below 50%, a warning appears in the sync rules errors array. If the slot is fully invalidated, the error is reported via `last_fatal_error` with code [`PSYNC_S1146`](/debugging/error-codes#psync_s11xx-postgres-replication-issues).