Back to Skills

postgresql-replication

verified

PostgreSQL streaming replication - setup, monitoring, failover

View on GitHub

Marketplace

pluginagentmarketplace-postgresql

pluginagentmarketplace/custom-plugin-postgresql

Plugin

ultrathink

Repository

pluginagentmarketplace/custom-plugin-postgresql
1stars

skills/postgresql-replication/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-postgresql/blob/main/skills/postgresql-replication/SKILL.md -a claude-code --skill postgresql-replication

Installation paths:

Claude
.claude/skills/postgresql-replication/
Powered by add-skill CLI

Instructions

# PostgreSQL Replication Skill

> Atomic skill for streaming replication

## Overview

Production-ready patterns for streaming replication, monitoring, and failover with Patroni.

## Prerequisites

- PostgreSQL 16+
- Multiple server nodes
- Network connectivity

## Parameters

```yaml
parameters:
  operation:
    type: string
    required: true
    enum: [setup_primary, setup_replica, monitor, failover]
  replication_mode:
    type: string
    enum: [async, sync]
    default: async
```

## Quick Reference

### Primary Setup
```sql
-- postgresql.conf
wal_level = replica
max_wal_senders = 10
max_replication_slots = 10

-- Create replication user
CREATE ROLE replicator WITH REPLICATION LOGIN PASSWORD 'secret';

-- Create slot
SELECT pg_create_physical_replication_slot('replica1');
```

### Replica Setup
```bash
pg_basebackup -h primary -D /data -U replicator -v -P -R
```

### Monitor Lag
```sql
-- On primary
SELECT client_addr, state,
    pg_size_pretty(pg_wal_lsn_diff(sent_lsn, replay_lsn)) as lag
FROM pg_stat_replication;

-- On replica
SELECT pg_is_in_recovery(), pg_last_wal_replay_lsn();
```

### Patroni HA
```yaml
scope: cluster
bootstrap:
  dcs:
    ttl: 30
    maximum_lag_on_failover: 1048576
```

## Replication Modes

| Mode | Data Safety | Latency |
|------|------------|---------|
| async | Possible loss | Low |
| sync | No loss | Higher |

## Troubleshooting

| Problem | Cause | Solution |
|---------|-------|----------|
| Lag increasing | Slow replica | Check I/O |
| Slot inactive | Replica down | Drop old slot |
| Failover failed | etcd issue | Check cluster |

## Usage

```
Skill("postgresql-replication")
```

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
1582 chars