diff --git a/configuration/source-db/postgres-maintenance.mdx b/configuration/source-db/postgres-maintenance.mdx
index 62298a01..2827b83c 100644
--- a/configuration/source-db/postgres-maintenance.mdx
+++ b/configuration/source-db/postgres-maintenance.mdx
@@ -7,7 +7,7 @@ description: "Manage Postgres replication slots and WAL lag for reliable PowerSy
Postgres logical replication slots are used to keep track of [replication](/architecture/powersync-service#replication-from-the-source-database) progress (recorded as a [LSN](https://www.postgresql.org/docs/current/datatype-pg-lsn.html)).
-Every time a new version of [Sync Streams or Sync Rules](/sync/overview) are deployed, PowerSync creates a new replication slot, then switches over and deletes the old replication slot when the reprocessing of the new Sync Streams/Rules version is done.
+Every time a new version of [Sync Streams or Sync Rules](/sync/overview) is deployed, PowerSync creates a new replication slot. Once the new version is fully processed, PowerSync switches to use the new slot and deletes the old one.
The replication slots can be viewed using this query:
@@ -22,9 +22,9 @@ Example output:
| powersync\_1\_c3c8cf21 | 0/70D8240 | 1 | 56 bytes |
| powersync\_2\_e62d7e0f | 0/70D8240 | 1 | 56 bytes |
-In some cases, a replication slot may remain without being used. In this case, the slot prevents Postgres from deleting older WAL entries. One such example is when a PowerSync instance has been deprovisioned.
+In some cases, a replication slot may remain without being used. In this case, the slot prevents Postgres from deleting older WAL entries. For example, this happens when a PowerSync instance has been deprovisioned.
-While this is desired behavior for slot replication downtime, it could result in excessive disk usage if the slot is not used anymore.
+Keeping unused slots alive prevents WAL cleanup, which can lead to excessive disk usage. If a slot is no longer needed, it should be dropped.
Inactive slots can be dropped using:
@@ -32,15 +32,41 @@ Inactive slots can be dropped using:
select slot_name, pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false;
```
-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.
+Postgres prevents active slots from being dropped. If an active slot is somehow dropped while a PowerSync instance is disconnected, PowerSync will automatically recreate the slot when it reconnects and restart replication.
+
+### Recovering from an invalidated slot
+
+A replication slot becomes invalidated when its `wal_status` is `lost`. This happens when the WAL data needed by the slot has been removed, typically because the replication lag exceeded `max_slot_wal_keep_size`.
+
+When this occurs, you will see an error such as:
+
+> Replication slot powersync\_1\_xxxx was invalidated (reason: wal\_removed). Increase max\_slot\_wal\_keep\_size on the source database and delete the existing slot to recover.
+
+To recover:
+
+1. Increase `max_slot_wal_keep_size` on the source Postgres database to prevent re-occurrence. See the [production readiness guide](/maintenance-ops/production-readiness-guide#managing--monitoring-replication-lag) for sizing guidance.
+
+2. Drop the invalidated slot:
+
+```sql
+SELECT pg_drop_replication_slot('powersync_1_xxxx');
+```
+
+Replace `powersync_1_xxxx` with the actual slot name from the error message.
+
+3. Restart the PowerSync Service. It will create a new replication slot and begin replication from scratch.
+
+If the slot was invalidated during the initial snapshot (before it completed), the PowerSync Service will not automatically retry. You must drop the invalidated slot manually before the service can recover.
+
+If the invalidation reason is `idle_timeout` (Postgres 18+), the slot was invalidated due to inactivity. In this case, increase `idle_replication_slot_timeout` on the source database instead.
### 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\.
+Postgres is configured with a maximum number of replication slots per server. Each PowerSync instance uses one replication slot for replication and an additional one while deploying a new Sync Streams or Sync Rules version. The maximum number of PowerSync instances you can connect to one Postgres server is equal to the maximum number of replication slots, minus one.
If other clients are also using replication slots, this number is reduced further.
-The maximum number of slots can be configured by setting `max_replication_slots` (not all hosting providers expose this), and checked using:
+To configure the maximum number of slots, set `max_replication_slots` (though not all hosting providers expose this setting). Check the current value using:
```sql
select current_setting('max_replication_slots')
diff --git a/debugging/error-codes.mdx b/debugging/error-codes.mdx
index 098e6eb8..775e4083 100644
--- a/debugging/error-codes.mdx
+++ b/debugging/error-codes.mdx
@@ -62,6 +62,11 @@ This reference documents PowerSync error codes organized by component, with trou
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**:
@@ -143,6 +148,17 @@ This reference documents PowerSync error codes organized by component, with trou
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
@@ -235,6 +251,17 @@ This reference documents PowerSync error codes organized by component, with trou
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**:
@@ -303,7 +330,7 @@ This does not include auth configuration errors on the service.
- **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.
diff --git a/maintenance-ops/production-readiness-guide.mdx b/maintenance-ops/production-readiness-guide.mdx
index 28f06d5c..725621f2 100644
--- a/maintenance-ops/production-readiness-guide.mdx
+++ b/maintenance-ops/production-readiness-guide.mdx
@@ -262,7 +262,7 @@ Because PowerSync relies on Postgres logical replication, it's important to cons
The WAL growth rate is expected to increase substantially during the initial replication of large datasets with high update frequency, particularly for tables included in the PowerSync publication.
-During normal operation (after Sync Streams (or legacy Sync Rules) are deployed) the WAL growth rate is much smaller than the initial replication period, since the PowerSync Service can replicate ~5k operations per second, meaning the WAL lag is typically in the MB range as opposed to the GB range.
+During normal operation (after Sync Streams/Sync Rules are deployed) the WAL growth rate is much smaller than the initial replication period, since the PowerSync Service can replicate ~5k operations per second, meaning the WAL lag is typically in the MB range as opposed to the GB range.
When deciding what to set the `max_slot_wal_keep_size` configuration parameter the following should be taken in account:
1. Database size - This impacts the time it takes to complete the initial replication from the source Postgres database.
@@ -271,7 +271,7 @@ When deciding what to set the `max_slot_wal_keep_size` configuration parameter t
To view the current replication slots that are being used by PowerSync you can run the following query:
-```
+```sql
SELECT slot_name,
plugin,
slot_type,
@@ -281,14 +281,14 @@ FROM pg_replication_slots;
```
To view the current configured value of the `max_slot_wal_keep_size` you can run the following query:
+
+```sql
+SHOW max_slot_wal_keep_size
```
-SELECT setting as max_slot_wal_keep_size
-FROM pg_settings
-WHERE name = '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 the slot is invalidated mid-snapshot, PowerSync detects the problem and stops replication with error [`PSYNC_S1146`](/debugging/error-codes#psync_s11xx-postgres-replication-issues). On the source database, increase `max_slot_wal_keep_size` and delete the existing replication slot. PowerSync creates a new slot and restarts the snapshot.
+
+During a snapshot, PowerSync warns when less than 50% of the WAL budget remains. You may see this warning in the PowerSync dashboard, in the [Diagnostics API](/maintenance-ops/self-hosting/diagnostics) if you self-host, and in PowerSync Service logs. Increase `max_slot_wal_keep_size` or reduce snapshot work before the slot is invalidated. Use the considerations above to set a high enough cap.
### Managing Replication Slots
@@ -311,7 +311,7 @@ FROM pg_replication_slots where active = false;
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.
-The `idle_replication_slot_timeout` [configuration parameter](https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-IDLE-REPLICATION-SLOT-TIMEOUT) is only available from PostgresSQL 18 and above.
+The `idle_replication_slot_timeout` [configuration parameter](https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-IDLE-REPLICATION-SLOT-TIMEOUT) is only available from Postgres 18 onward.
The `idle_replication_slot_timeout` will invalidate replication slots that have remained inactive for longer than the value set for the `idle_replication_slot_timeout` parameter.
diff --git a/maintenance-ops/self-hosting/diagnostics.mdx b/maintenance-ops/self-hosting/diagnostics.mdx
index fbce499f..7f2d735a 100644
--- a/maintenance-ops/self-hosting/diagnostics.mdx
+++ b/maintenance-ops/self-hosting/diagnostics.mdx
@@ -1,43 +1,73 @@
---
title: "Diagnostics"
-description: "Use the PowerSync Diagnostics API to inspect replication status and sync health."
+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
-If you have the [PowerSync CLI](/tools/cli) installed, use `powersync status` to check instance status without calling the API directly. This works with any running PowerSync instance — local or remote.
+If you have the [PowerSync CLI](/tools/cli) installed, use `powersync status` to check instance status without calling the API directly. This works with any running PowerSync instance, whether local or remote.
```bash
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
```
-Make sure to use a secure API token as part of this configuration
+
+Use a secure, randomly generated API token.
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:
+
+**`connections`** — whether PowerSync can reach the configured source database and any connection-level errors.
+
+**`active_sync_rules`** — the currently serving sync config (Sync Streams or Sync Rules). Contains a `connections[]` array with details about each replication connection including slot name, WAL status, and tables being replicated. Also includes an `errors[]` array for warnings or errors.
+
+**`deploying_sync_rules`** — only present while a new sync config is being deployed and the initial replication is in progress. PowerSync runs this process in parallel so clients continue to be served by the existing active config. Once initial replication completes, this section disappears and `active_sync_rules` updates.
+
+Each connection in `active_sync_rules.connections[]` includes:
+
+| Field | Description |
+| --- | --- |
+| `slot_name` | The name of the Postgres replication slot used by this sync rules version. |
+| `initial_replication_done` | Whether the initial snapshot has completed. |
+| `replication_lag_bytes` | Replication lag in bytes. |
+| `wal_status` | The WAL status of the replication slot (`reserved`, `extended`, `unreserved`, or `lost`). |
+| `safe_wal_size` | Remaining WAL budget in bytes before the slot risks invalidation. |
+| `max_slot_wal_keep_size` | The configured `max_slot_wal_keep_size` value on the source Postgres database. |
+
+### Errors and warnings
+
+Warnings and errors appear in the `errors[]` array at the sync rules level (`active_sync_rules.errors[]` or `deploying_sync_rules.errors[]`). This includes:
+
+- **Replication lag warnings** are raised if no replicated commit has been received in more than 5 minutes (warning level) or 15 minutes (fatal level).
+- **WAL budget warnings** appear when the remaining WAL budget drops below 50%.
+- **Replication errors** such as `PSYNC_S1146` appear when a replication slot is invalidated (when `wal_status` is `lost`).
+
+
+For guidance on configuring `max_slot_wal_keep_size` and managing replication slots, see [Postgres maintenance](/configuration/source-db/postgres-maintenance).
+
\ No newline at end of file