Database replication
A curated pack of custom Claude Code skills for developers — installable as a Claude Code plugin marketplace.
npx -y skills add Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack --skill database-replicationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
When to activate: replication, leader-follower, CDC, Debezium, read replica, failover, logical replication, multi-master
SKILL.md
4.5 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it
Database Replication Patterns
PostgreSQL Logical Replication
-- Primary: enable logical replication
-- postgresql.conf: wal_level = logical
-- Create publication
CREATE PUBLICATION my_pub FOR TABLE users, orders, products;
-- Or all tables:
CREATE PUBLICATION my_pub FOR ALL TABLES;
-- Replica: create subscription
CREATE SUBSCRIPTION my_sub
CONNECTION 'host=primary-host port=5432 dbname=app user=replicator password=secret'
PUBLICATION my_pub;
-- Monitor replication lag
SELECT client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn,
(sent_lsn - replay_lsn) AS lag_bytes
FROM pg_stat_replication;
-- On replica: check replication delay
SELECT NOW() - pg_last_xact_replay_timestamp() AS replication_lag;
Change Data Capture with Debezium
// Debezium connector config (Kafka Connect)
{
"name": "postgres-cdc",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"database.hostname": "postgres",
"database.port": "5432",
"database.user": "debezium",
"database.password": "secret",
"database.dbname": "myapp",
"database.server.name": "myapp",
"plugin.name": "pgoutput",
"table.include.list": "public.users,public.orders",
"topic.prefix": "cdc",
"transforms": "route",
"transforms.route.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"snapshot.mode": "initial"
}
}
# Consume CDC events from Kafka
from confluent_kafka import Consumer
consumer = Consumer({'bootstrap.servers': 'kafka:9092', 'group.id': 'cdc-consumer'})
consumer.subscribe(['cdc.public.orders'])
for msg in consumer:
event = json.loads(msg.value())
op = event['payload']['op'] # 'c'=create, 'u'=update, 'd'=delete, 'r'=read(snapshot)
before = event['payload']['before']
after = event['payload']['after']
if op == 'u' and after['status'] == 'completed':
trigger_fulfillment(after['id'])
MySQL Replication with GTID
-- primary my.cnf
-- server-id=1, log_bin=ON, gtid_mode=ON, enforce_gtid_consistency=ON, binlog_format=ROW
-- replica
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='primary',
SOURCE_USER='replication_user',
SOURCE_PASSWORD='secret',
SOURCE_AUTO_POSITION=1,
SOURCE_SSL=1;
START REPLICA;
-- Monitor
SHOW REPLICA STATUS\G
-- Key fields: Seconds_Behind_Source, Replica_SQL_Running, Replica_IO_Running
-- Promote replica (planned failover)
STOP REPLICA;
RESET REPLICA ALL;
-- Point app to new primary
Multi-Master with CockroachDB / Galera
-- CockroachDB: distributed SQL, multi-active, geo-partitioning
-- No config needed — all nodes are equal primaries
-- Use RETURNING NOTHING for fire-and-forget writes
-- Follow-the-workload: pin rows to region
ALTER TABLE users ADD COLUMN region crdb_internal_region NOT NULL DEFAULT 'us-east1';
ALTER TABLE users SET LOCALITY REGIONAL BY ROW; -- row-level geo partitioning
-- Galera (MySQL multi-master)
-- wsrep_provider, wsrep_cluster_address, wsrep_node_address in my.cnf
-- Writes replicated synchronously to all nodes (SST for new nodes)
-- Avoid large transactions (> 128MB) — they block cluster
Replication Lag Handling
# Application-level: sticky reads after write
class DBSession:
def __init__(self, primary_url, replica_url):
self.primary = create_engine(primary_url)
self.replica = create_engine(replica_url)
self._wrote_at = None
def write(self, *args, **kwargs):
result = self.primary.execute(*args, **kwargs)
self._wrote_at = time.time()
return result
def read(self, *args, **kwargs):
# Read from primary for 2s after write (replication window)
if self._wrote_at and time.time() - self._wrote_at < 2.0:
return self.primary.execute(*args, **kwargs)
return self.replica.execute(*args, **kwargs)
Monitoring Checklist
- Replication lag alert: > 30s triggers page
- Replication slot size monitored (unbounded growth fills disk)
- Failover tested in staging (automated with Patroni/ProxySQL)
- Read/write split verified (writes never hit replica)
- GTID/LSN tracked for point-in-time recovery
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most databases sql skills give in ~1.1k tokens
Counted across 589 of the 662 authors here whose files we hold, read 2026-08-07
- Use parameterized queriesin 37 of 589, across 34 files
- Use timestamptz for timestampsin 30 of 589, across 14 files
- Index foreign keysin 29 of 589, across 18 files
- Create indexes concurrentlyin 29 of 589, across 24 files
- Use numeric type for moneyin 25 of 589, across 8 files
- Use cursor pagination instead of offsetin 24 of 589, across 17 files
- Select only required columnsin 24 of 589, across 20 files
- Add indexes manually on foreign key columnsin 22 of 589, across 12 files
- Normalize to third normal formin 19 of 589, across 10 files
- Configure connection poolingin 19 of 589, across 17 files
- Put equality columns before range columns in indexesin 18 of 589, across 10 files
- Read individual rule files for detailed explanationsin 18 of 589, across 4 files
Said here and by no other author read
- set wal level to logical for postgresql
- create publication on primary database
- create subscription on replica database
- configure debezium connector with kafka connect
- enable gtid mode for mysql replication
- avoid large transactions in multi master clusters
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.