---
title: "CDC Sink for PostgreSQL: Monitoring PostgreSQL"
description: "PostgreSQL-side monitoring for CDC Sink, including replication slot health, replication lag, and WAL disk usage queries."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/monitoring-postgres"
version: "7.2"
---

# CDC Sink for PostgreSQL: Monitoring PostgreSQL

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - This page covers PostgreSQL-side monitoring for CDC Sink tasks:  
>   replication slot health, replication lag, and WAL disk usage.
>
> - For RavenDB-side monitoring, see [Monitoring](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/monitoring.md).
>
> - In this article:
>   - [Replication slot health](#replication-slot-health)
>   - [Replication lag](#replication-lag)
>   - [WAL disk usage](#wal-disk-usage)

## Replication slot health {#replication-slot-health}

List CDC Sink replication slots that use the auto-generated slot-name prefix and check whether they are active:

```sql
SELECT slot_name, active, confirmed_flush_lsn
FROM pg_replication_slots
WHERE slot_name LIKE 'rvn_cdc_s_%';
```

The `rvn_cdc_s_` prefix matches only auto-generated slot names.
If the task uses a custom `SlotName`, replace the filter with that name or remove the filter and cross-check the results against your CDC Sink task configurations.

| Column | Meaning |
| - | - |
| `active` | `true` if CDC Sink is connected and consuming;<br />`false` if no process is currently connected to the slot. |
| `confirmed_flush_lsn` | The LSN up to which changes have been confirmed as consumed. |

A slot with `active = false` means CDC Sink is not currently connected.  
This is expected during failover or when the task is disabled or stopped.  
If the slot remains inactive for an extended period, investigate the task state in RavenDB Studio.

## Replication lag {#replication-lag}

Replication lag measures how far the slot is behind the current WAL position:

```sql
SELECT slot_name,
       pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) AS lag_bytes
FROM pg_replication_slots
WHERE slot_name LIKE 'rvn_cdc_s_%';
```

The `rvn_cdc_s_` prefix matches only auto-generated slot names.  
If the task uses a custom `SlotName`, adjust or remove the filter.

A consistently growing `lag_bytes` means CDC Sink is not keeping up with the rate
of changes in the source database. Consider:

- Checking CDC Sink performance statistics in RavenDB Studio for slow processing stages or scripts
- Increasing `CdcSink.MaxBatchSize` if the task is limited by batch size
- Reducing load on the source database

## WAL disk usage {#wal-disk-usage}

PostgreSQL retains WAL that is still required by replication slots.  
An inactive or slow CDC Sink slot can cause WAL files to accumulate on disk.

Check approximate WAL retained by CDC Sink slots that use the auto-generated slot-name prefix:

```sql
SELECT slot_name, active,
       pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS retained_wal_bytes
FROM pg_replication_slots
WHERE slot_name LIKE 'rvn_cdc_s_%'
ORDER BY retained_wal_bytes DESC NULLS LAST;
```

The `rvn_cdc_s_` prefix matches only auto-generated slot names.  
If the task uses a custom `SlotName`, adjust or remove the filter.

A high `retained_wal_bytes` value means PostgreSQL is retaining WAL for that slot.

- If the slot is active, CDC Sink is connected but may be processing changes slowly.
- If it is inactive, no process is currently consuming from it.

Before dropping a slot, verify that no CDC Sink task still needs it.
For cleanup guidance, see [Cleanup and Maintenance](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/cleanup-and-maintenance.md).

## See also

- [Cleanup and Maintenance](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/cleanup-and-maintenance.md)
- [Monitoring](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/monitoring.md)
- [Failover and Consistency](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/failover-and-consistency.md)
