Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

PostgreSQL

Troubleshoot PostgreSQL replication

Find and fix the PostgreSQL source problems that stop or slow an Artie pipeline: skipped rows, growing or lost replication slots, and dropped connections.

Rows skipped for exceeding the message size limit

Artie limits the size of each change data capture (CDC) message it writes to Kafka. The limit is 2 MB by default and applies to every pipeline in your Artie account. Artie support raises it on request, up to 15 MB.

Artie skips a row whose message exceeds the limit and keeps replicating every other row. Each skipped row sends a row.skipped webhook event with the table name and primary key.

Find tables at risk

Run these queries against your source PostgreSQL database. This query lists your 20 largest tables:

SQL
SELECT schemaname, relname, pg_size_pretty(pg_total_relation_size(relid)) AS size
FROM pg_stat_user_tables
ORDER BY pg_total_relation_size(relid) DESC
LIMIT 20;

This query returns the largest row in one table:

SQL
SELECT pg_size_pretty(MAX(pg_column_size(t.*))::bigint) AS max_row_size
FROM SCHEMA_NAME.TABLE_NAME t;

Replace SCHEMA_NAME.TABLE_NAME with the table to check.

Reduce message size

Turn on message compression, exclude large columns, or both.

With Message compression, Artie gzips each message of 500 KB or more before the size check. It keeps the compressed form only when it’s smaller. See message compression.

With column exclusion, leave out binary blobs or encrypted payloads you don’t need in the destination. See the column exclusion guide.

To turn on message compression for an existing pipeline:

  1. On the pipeline’s overview page, select Edit pipeline.
  2. On the Source: PostgreSQL tab, open Advanced settings.
  3. Set Message compression to GZIP.
  4. Select Save changes.
  5. Select Deploy, then Deploy in the Validate and deploy dialog.

If Message compression is locked, other pipelines share this source’s settings, so change it in Terraform. Set message_compression = "gzip" on artie_source_reader (Terraform provider v2.3.34 and later).


Replication slot keeps growing

PostgreSQL keeps every write-ahead log (WAL) segment that Artie hasn’t consumed yet. If the slot size only grows, the retained WAL eventually fills the disk.

You see one or more of these:

  • Artie raises a Potential replication slot overflow detected alert (Large PostgreSQL replication slot on the Monitors page).
  • WAL disk usage grows or triggers storage alerts.
  • The retained_wal value from the slot size query keeps climbing.

Artie raises the alert when the slot passes 5% of your database size, kept between 10 GB and 100 GB. If 65% of max_slot_wal_keep_size is lower, that is the threshold instead. To change the threshold, create a custom monitor for the pipeline.

Check the slot size

Run this query to see each slot’s status and retained WAL:

SQL
SELECT
  slot_name,
  wal_status,
  active,
  pg_size_pretty(
    pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
  ) AS retained_wal
FROM pg_replication_slots;

Run this query to find sessions whose query started more than 5 minutes ago. A long-running transaction among them holds back the slot:

SQL
SELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes'
ORDER BY duration DESC;

Long-running transactions

Cause: A long-running or idle-in-transaction session stops PostgreSQL from advancing the replication slot past that transaction.

Fix: End the blocking session:

SQL
SELECT pg_terminate_backend(PID);

Replace PID with the session’s pid from the 5-minute query. To end idle transactions automatically, set idle_in_transaction_session_timeout.

Idle database without heartbeats

Cause: On an idle database, WAL accumulates because no changes reach the slot. Amazon RDS writes an internal heartbeat to its rdsadmin database every 5 minutes. That adds about 18 GB of WAL per day on an otherwise idle instance.

Fix: Turn on heartbeats in Artie. Artie then updates a heartbeat table every 5 minutes, so the slot keeps advancing. See Enabling heartbeats. For RDS details, see Prevent WAL growth on RDS.

Pipeline is paused or failing

Cause: When the pipeline is Paused or failing, Artie doesn’t read from the replication slot, so WAL builds up. With Delivery paused, Artie keeps reading and the slot still advances. Artie holds those changes for 14 days by default.

Fix: Check the pipeline’s status in the Artie dashboard. Select Resume pipeline, or fix the error and deploy the pipeline again.

No max_slot_wal_keep_size limit

Cause: max_slot_wal_keep_size defaults to -1, which means no limit. PostgreSQL keeps WAL for the slot indefinitely, so disk use grows without bound.

Fix: Set a limit that caps WAL retention. If the slot reaches the limit, PostgreSQL invalidates it (see Replication slot lost). To choose a value, see Set max_slot_wal_keep_size. This query shows the current value:

SQL
SHOW max_slot_wal_keep_size;

Confirm the slot shrinks

Re-run the slot size query in Check the slot size. retained_wal stops climbing and falls as Artie consumes the backlog.


Replication slot lost

A lost replication slot was dropped or invalidated, so the pipeline can’t stream changes from where it stopped.

You see one or more of these:

  • Artie raises a Replication slot lost alert (PostgreSQL replication slot error on the Monitors page) when the slot’s wal_status is lost.
  • Pipeline errors say the replication slot doesn’t exist.
  • Errors mention WAL segments that were removed.
  • pg_replication_slots returns no row for your slot, or shows wal_status = 'lost'.

If Artie reads from a standby, the alert also shows hot_standby_feedback, which must be on.

Check the slot

Run this query to see whether the slot exists and its status:

SQL
SELECT slot_name, wal_status, active, restart_lsn
FROM pg_replication_slots;

Run this query to see the current max_slot_wal_keep_size:

SQL
SHOW max_slot_wal_keep_size;

Slot invalidated by max_slot_wal_keep_size

Cause: The slot grew past max_slot_wal_keep_size, so PostgreSQL invalidated it. This often follows a replication slot that keeps growing.

Fix: An invalidated slot still exists, and Artie reuses an existing slot, so redeploying alone doesn’t help. Drop the slot first:

SQL
SELECT pg_drop_replication_slot('artie');

If you set Replication slot override (optional), use that name instead of artie. Then deploy the pipeline again: select Edit pipeline, then Deploy. Artie creates a new slot when its source reader starts. Changes made before the new slot existed aren’t replicated, so backfill the affected tables. To prevent a repeat, turn on heartbeats.

Slot dropped manually

Cause: Someone dropped the replication slot with pg_drop_replication_slot().

Fix: Deploy the pipeline again so Artie creates a new slot, then backfill the affected tables.

Database failover

Cause: During a failover, especially on Amazon Aurora, replication slots on the old primary don’t carry over to the new primary.

Fix: Deploy the pipeline again so Artie creates a slot on the new primary, then backfill the affected tables.

On PostgreSQL 17 or later, a failover slot syncs to standbys and survives a failover. Turn on Use PostgreSQL 17 failover replication slot in the pipeline’s Postgres settings, or Failover slot when you set up a new pipeline. Artie applies it only when it creates a slot, so an existing slot is unchanged.

Provider WAL retention limits

Cause: Some managed PostgreSQL providers apply their own WAL retention limits, which invalidate slots regardless of max_slot_wal_keep_size.

Fix: Check your provider’s documentation for its WAL retention policy. If pg_replication_slots still lists the slot with wal_status = 'lost', drop it with pg_drop_replication_slot(). Then deploy the pipeline again and backfill the affected tables. To keep the slot active, turn on heartbeats.

Confirm the new slot is active

Re-run the query in Check the slot. It returns your slot with active set to true.


terminating connection due to administrator command

Artie’s logs show this error:

Text
FATAL: terminating connection due to administrator command (SQLSTATE 57P01)

The database ended Artie’s connection. Something outside Artie called pg_terminate_backend(), or the database restarted or failed over. What happens next depends on the connection:

  • Replication: Artie reconnects and resumes from its last committed position, so no data is lost. Artie doesn’t alert or send a replication.error webhook for this error.
  • Backfills: Artie doesn’t restart a backfill. The backfill fails, sends a backfill.failed webhook event, and you start it again from the dashboard.

Each ended replication connection restarts Artie’s source reader. Changes wait in the replication slot until it reconnects, so repeated terminations add replication lag.

A connection reaper ends Artie’s session

Cause: A connection management tool ends long-lived or idle-looking sessions. Examples are PgBouncer, an in-house idle connection reaper, or a monitoring script. Replication connections stay open and look idle between commits, so reapers often pick them.

Fix: Find the tool or script calling pg_terminate_backend(). Exclude Artie’s sessions from it: Artie’s database user, the walsender backend type, or application_name = 'artie-reader'.

If the tool must keep ending idle backfill connections, set Max connection idle time (seconds) lower than the tool’s idle limit. Artie then replaces idle backfill connections before the tool ends them. The field is in the pipeline’s Postgres settings, defaults to 30 minutes, and applies after you deploy.

Database restart or failover

Cause: A planned restart, a provider-initiated restart or a failover ends every active connection with this error.

Fix: Replication needs nothing; Artie reconnects on its own. Start any failed backfills again from the dashboard once the database is back up. See backfills.


Replication slot used by another pipeline

Validation fails with this message:

Text
Another pipeline on this database server already uses this replication slot. Enter a different slot name.

Cause: Each pipeline on a database server needs its own replication slot. Another pipeline already uses this slot name, which defaults to artie.

Fix: Give this pipeline a different slot name:

  1. On the pipeline’s overview page, select Edit pipeline.
  2. On the Source: PostgreSQL tab, open Advanced settings.
  3. Under Postgres settings, enter a new name in Replication slot override (optional).
  4. Select Save changes.
  5. Select Deploy, then Deploy in the Validate and deploy dialog.

When you set up a new pipeline, Artie fills the Replication slot field with a free name if it finds the conflict.


Postgres has no free replication slot

Validation fails with this message:

Text
Postgres has no free replication slot. Check max_replication_slots and drop unused slots.

After Details:, the message shows PostgreSQL’s own error, such as pq: all replication slots are in use.

Cause: Every slot allowed by max_replication_slots is taken, so Artie can’t create its slot.

Fix: List your slots with the slot query in Check the slot. Drop slots that no pipeline uses with pg_drop_replication_slot(), or raise max_replication_slots.


Set max_slot_wal_keep_size

max_slot_wal_keep_size caps how much WAL PostgreSQL retains for a replication slot before invalidating it. Treat it as a break-glass limit: if the slot reaches it, PostgreSQL invalidates the slot and you need a full backfill to recover.

When you choose a value, consider:

  • Your database size: larger databases generate more WAL and need more headroom.
  • Historical slot size: how large your slot grew in normal operation and past incidents, such as pipeline pauses and long-running transactions.
  • Headroom: aim for at least 3 to 5 times your observed peak slot size.

This query shows the current slot size:

SQL
SELECT
  slot_name,
  pg_size_pretty(
    pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
  ) AS retained_wal
FROM pg_replication_slots;

Pair the limit with heartbeats to keep the slot advancing while the database is idle.

Was this page helpful?