## Playbook for setting up logical replication between pg instance and RDS

## On the source DB

### Audit and confirm the following settings are set:
```bash
max_slot_wal_keep_size = 1000GB
max_wal_size = 25GB
checkpoint_timeout = 10min
wal_level = logical
max_wal_senders = 10
```

Commands to set above settings:
```
ALTER SYSTEM SET max_slot_wal_keep_size = '1000GB';
ALTER SYSTEM SET max_wal_size = '25GB';
ALTER SYSTEM SET checkpoint_timeout = '10min';
ALTER SYSTEM SET wal_level = 'logical';
ALTER SYSTEM SET max_wal_senders = 10;
```

## Reload config
`select pg_reload_conf();`


### Execute logical_replication2.sh
`./logical_replication.sh`

## Render questions:
- Metrics are missing in our DD (i.e wal_size)
- what happened last week?
- DB grew 100GB in a week, can we find the source of that growth?


#### Misc/Helpful commands to monitor progress:
```
ALTER SUBSCRIPTION render_db_subscription DISABLE;
DROP SUBSCRIPTION render_db_subscription;

DROP PUBLICATION rds_db_publication;

// On the source, to check replication lag:
select (pg_current_wal_lsn() - replay_lsn) as lsn_lag, application_name from pg_stat_replication;
```
