Patroni Configuration Management
After this lesson, you will be able to:
- Manage Patroni configuration dynamically.
- Use
patronictl edit-config. - Understand DCS-stored configuration.
- Perform zero-downtime config changes.
- Validate and rollback configurations.
1. Configuration Layers
1.1. Configuration hierarchy
1.2. Configuration scope
2. View Current Configuration
2.1. Show DCS configuration
2.2. Get specific parameter
2.3. Compare with local config
3. Dynamic Configuration Changes
3.1. Edit configuration interactively
3.2. Automatic vs manual restart
3.3. Check pending restart
3.4. Trigger restart
4. Configuration Templates
4.1. Set configuration via command line
4.2. Save and restore configs
4.3. Version control
5. Common Configuration Tasks
5.1. Increase max_connections
Note: Requires restart if decreasing, reload if increasing within limits.
5.2. Enable query logging
Note: No restart required (dynamic parameter).
5.3. Adjust memory settings
5.4. Tune checkpoint behavior
Note: Dynamic or reload, no restart needed.
5.5. Enable pg_stat_statements
6. Validation and Testing
6.1. Check parameter values
6.2. Validate configuration
6.3. Test configuration change
7. Rollback Procedures
7.1. Immediate rollback
7.2. Emergency recovery
8. Advanced Configuration
8.1. Per-database parameters
Note: These override cluster-wide settings.
8.2. Conditional configuration
8.3. Custom callbacks
9. Configuration Best Practices
✅ DO
- Use DCS for runtime changes: Consistent across cluster.
- Version control configs: Track changes in git.
- Test in staging first: Validate before production.
- Document changes: Why, what, when.
- Backup before changes: Easy rollback.
- Monitor after changes: Watch for issues.
- Schedule restarts: During maintenance window.
- Use patronictl edit-config: Not manual etcd changes.
- Validate parameters: Check
pg_settings. - Review regularly: Quarterly config audits.
❌ DON'T
- Don't edit postgresql.conf: Use patronictl instead.
- Don't change etcd directly: Use Patroni tools.
- Don't skip backups: Always save before changes.
- Don't apply untested changes: Test first.
- Don't ignore pending restart: May not apply correctly.
- Don't change wal_level lightly: Requires full restart.
- Don't forget about replicas: Changes apply cluster-wide.
10. Configuration Monitoring
10.1. Track configuration drift
10.2. Alert on config changes
10.3. Audit log for config changes
11. Lab Exercises
Lab 1: Dynamic configuration change
Tasks:
- View current configuration.
- Edit configuration to increase
max_connections. - Apply changes without restart.
- Verify new setting.
- Save configuration backup.
Lab 2: Configuration requiring restart
Tasks:
- Change
shared_buffersparameter. - Observe pending restart flag.
- Perform rolling restart.
- Verify change applied.
- Test with
pg_settingsquery.
Lab 3: Rollback configuration
Tasks:
- Backup current config.
- Make intentional bad change.
- Observe cluster behavior.
- Rollback to backup.
- Document recovery steps.
Lab 4: Configuration automation
Tasks:
- Create shell script to apply config.
- Implement validation checks.
- Add backup/rollback logic.
- Test script on cluster.
- Add to cron for scheduled changes.
12. Summary
Configuration Management Flow
Key Commands
Parameter Types
| Type | Action | Examples |
|---|---|---|
| Dynamic | Immediate | work_mem, effective_cache_size |
| Reload | SIGHUP | max_connections (up), log_statement |
| Restart | Full restart | shared_buffers (down), wal_level |
Next Steps
Lesson 24 will cover Upgrade Strategies:
- PostgreSQL major version upgrades
- Patroni version upgrades
- Zero-downtime upgrade procedures
- Rollback strategies
- Testing and validation