MA

managing-database-replication

Provides setup guidance for replication and sharding for PostgreSQL, MySQL, and MongoDB.

Install

mkdir -p .claude/skills/managing-database-replication && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5446" && unzip -o skill.zip -d .claude/skills/managing-database-replication && rm skill.zip

Installs to .claude/skills/managing-database-replication

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Process use when you need to work with database scalability.
60 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Configure PostgreSQL streaming and logical replication topologies
  • Initialize MySQL source-replica and group replication
  • Deploy MongoDB replica sets with automatic leader election
  • Implement automated failover using Patroni or MySQL InnoDB Cluster
  • Monitor replication lag and health via database-specific queries
  • Configure read routing using PgBouncer or ProxySQL

How it works

The skill configures database-specific replication parameters and users, initializes replicas via base backups or cluster commands, and sets up monitoring and routing tools. It automates the synchronization process and provides procedures for failover and conflict resolution.

Inputs & outputs

You give it
Database server connection details and topology requirements
You get back
Replication configuration files, initialization scripts, and failover runbooks

When to use managing-database-replication

  • Set up read replicas
  • Configure database sharding
  • Implement failover automation
  • Monitor replication lag

About this skill

Database Replication Manager

Overview

Configure and manage database replication topologies for PostgreSQL (streaming replication, logical replication), MySQL (source-replica, group replication), and MongoDB (replica sets). This skill covers primary-replica setup, read scaling through replica routing, failover automation, replication lag monitoring, and conflict resolution for multi-primary configurations.

Prerequisites

  • Superuser or replication-role credentials on primary and replica servers
  • Network connectivity between all replication nodes (verify with pg_isready or mysqladmin ping)
  • psql, mysql, or mongosh CLI tools installed on all nodes
  • Matching major database versions across all replication nodes
  • Sufficient disk space on replicas (equal to or greater than primary)
  • SSH access to replica servers for initial base backup transfer

Instructions

  1. Choose the replication topology based on requirements:

    • Single primary + read replicas: Best for read-heavy workloads. All writes go to primary; reads distributed across replicas.
    • Multi-primary (active-active): Best for geographic distribution. Requires conflict resolution. Use PostgreSQL logical replication or MySQL Group Replication.
    • Cascading replication: Replica A replicates from primary, Replica B replicates from Replica A. Reduces primary load for many replicas.
  2. For PostgreSQL streaming replication, configure the primary:

    • Set wal_level = replica, max_wal_senders = 10, max_replication_slots = 10
    • Create replication user: CREATE ROLE replicator WITH REPLICATION LOGIN PASSWORD 'secure_password'
    • Add replication entry to pg_hba.conf: host replication replicator replica_ip/32 scram-sha-256
    • Reload configuration: SELECT pg_reload_conf()
  3. Initialize the replica with a base backup: pg_basebackup -h primary_host -U replicator -D /var/lib/postgresql/data -Fp -Xs -P -R. The -R flag creates standby.signal and configures primary_conninfo automatically.

  4. For MySQL source-replica replication, configure the source:

    • Set server-id = 1, log_bin = mysql-bin, binlog_format = ROW
    • Create replication user: CREATE USER 'replicator'@'replica_ip' IDENTIFIED BY 'secure_password'; GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'replica_ip'
    • Record binary log position: SHOW MASTER STATUS
  5. Configure the MySQL replica: CHANGE REPLICATION SOURCE TO SOURCE_HOST='primary_host', SOURCE_USER='replicator', SOURCE_PASSWORD='...', SOURCE_LOG_FILE='mysql-bin.000001', SOURCE_LOG_POS=154; START REPLICA.

  6. For MongoDB replica sets: initialize with rs.initiate({_id: "rs0", members: [{_id: 0, host: "node1:27017"}, {_id: 1, host: "node2:27017"}, {_id: 2, host: "node3:27017"}]}). MongoDB handles leader election and failover automatically.

  7. Monitor replication lag continuously:

    • PostgreSQL: SELECT client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, (sent_lsn - replay_lsn) AS lag_bytes FROM pg_stat_replication
    • MySQL: SHOW REPLICA STATUS\G (check Seconds_Behind_Source)
    • MongoDB: rs.printReplicationInfo() and rs.printSecondaryReplicationInfo()
  8. Configure application-level read routing: direct write queries to the primary connection and read queries to a load-balanced replica pool. Use connection poolers (PgBouncer, ProxySQL) or application middleware for automatic routing.

  9. Set up automated failover using Patroni (PostgreSQL), MySQL InnoDB Cluster + MySQL Router, or MongoDB's built-in election mechanism. Test failover by stopping the primary and verifying the replica promotes automatically within the target RTO.

  10. Configure alerting for replication lag exceeding 10 seconds, replication slot inactive for more than 1 hour, and replica connection drops. Stale replication slots in PostgreSQL cause WAL accumulation and can fill the disk.

Output

  • Replication configuration files for primary and replica nodes
  • Base backup and initialization scripts for setting up new replicas
  • Replication monitoring queries with lag measurement and health checks
  • Failover runbook with manual and automated promotion procedures
  • Read routing configuration for application or connection pooler

Error Handling

ErrorCauseSolution
Replication lag increasing steadilyReplica cannot keep up with primary write volumeCheck replica I/O and CPU; increase max_parallel_workers on replica; consider upgrading replica hardware; reduce write-heavy batch operations on primary
replication slot is inactive warningReplica disconnected or paused, WAL accumulating on primaryReconnect replica; if permanently removed, drop the slot with SELECT pg_drop_replication_slot('slot_name') to prevent disk fill
could not connect to primary on replicaNetwork partition, primary down, or authentication failureVerify network connectivity; check pg_hba.conf entries; confirm replication user credentials; check primary process status
Replica has diverged from primarySplit-brain after failed failover or manual writes to replicaRe-initialize replica from fresh base backup; for PostgreSQL, use pg_rewind if timeline divergence is small
Conflict in logical replicationSame row modified on both publisher and subscriberConfigure conflict resolution policy; use UPDATE conflict handler; design schema to avoid cross-node writes to same rows

Examples

Setting up PostgreSQL read replicas for a web application: A primary database handles 2,000 writes/second but read traffic is 10x higher. Two streaming replicas are added with PgBouncer routing read queries to replicas in round-robin. Result: primary CPU drops from 90% to 40%, read latency improves by 60%.

Automated failover with Patroni: A 3-node PostgreSQL cluster managed by Patroni with etcd for consensus. When the primary fails, Patroni promotes the most up-to-date replica within 10 seconds. Application reconnects automatically through the Patroni-managed VIP or DNS endpoint.

Cross-region logical replication for compliance: EU customer data must stay in EU region. Logical replication publishes only non-PII tables to the US region replica. EU application reads locally; US analytics queries use the replicated subset. Publication filter: CREATE PUBLICATION us_analytics FOR TABLE orders, products, categories.

Resources

When not to use it

  • When database versions are mismatched across nodes
  • When network connectivity between replication nodes is unavailable

Prerequisites

Superuser or replication-role credentialspsql, mysql, or mongosh CLI toolsMatching major database versionsSSH access to replica servers

Limitations

  • Stale PostgreSQL replication slots can cause WAL accumulation and disk fill
  • Logical replication conflicts require manual resolution policies
  • Replica hardware must have disk space equal to or greater than the primary

How it compares

Unlike manual configuration, this skill provides automated initialization scripts and standardized monitoring queries for specific replication topologies across PostgreSQL, MySQL, and MongoDB.

Compared to similar skills

managing-database-replication side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
managing-database-replication (this skill)127dReviewAdvanced
aws-aurora14moReviewIntermediate
local-cluster-manager227dReviewIntermediate
supabase-load-scale127dCautionAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

Search skills

Search the agent skills registry