DocumentationpgBalancer Documentation
CLI Management (bctl)
Install and Configure bctl
bctl is the unified CLI tool that replaces multiple pcp_* commands:
Install bctl
# bctl is included with pgBalancer
# After installing pgbalancer, bctl is in /usr/local/bin
# Verify installation
which bctl
bctl --version
# Configuration file location
~/.config/pgbalancer/bctl.confCheck Cluster Status
View overall cluster status and health:
Overall Status
# Show cluster status (table format - default)
bctl status
# JSON format for scripting
bctl status --format json | jqHealth Check
# Quick health check
bctl health
# Exit code 0 = healthy, non-zero = unhealthy
# Useful in monitoring scripts
if bctl health --quiet; then
echo "Cluster is healthy"
else
echo "Cluster has issues!"
bctl health --verbose
fiNode Management
Manage backend nodes using bctl:
List Nodes
# List all backend nodes (table format)
bctl nodes list
# Get detailed info about node 0
bctl nodes info 0Node Operations
# Detach node for maintenance
bctl nodes detach 2
# Attach node back
bctl nodes attach 2
# Promote standby to primary
bctl nodes promote 1 --forcePool Management
Monitor and manage connection pools:
View Pool Processes
# List all pool processes
bctl pool processesPool Statistics
# Get pool statistics
bctl pool statsWatchdog Management
Monitor watchdog status and coordination:
Watchdog Status
# View watchdog status
bctl watchdog statusConfiguration and Logs
View configuration and logs:
View Configuration
# Show current configuration
bctl config show
# Get specific parameter
bctl config get pool_modeView Logs
# Tail pgBalancer logs
bctl logs --follow
# Filter by level
bctl logs --level error --tail 50
# Search logs
bctl logs --grep "failover" --tail 100Command Reference
| Command | Description | Example |
|---|---|---|
| status | Show cluster status | bctl status |
| health | Quick health check | bctl health |
| nodes list | List all nodes | bctl nodes list |
| nodes info | Get node details | bctl nodes info 0 |
| nodes detach | Detach node | bctl nodes detach 2 |
| nodes attach | Attach node | bctl nodes attach 2 |
| nodes promote | Promote to primary | bctl nodes promote 1 |
| pool processes | List pool processes | bctl pool processes |
| pool stats | Pool statistics | bctl pool stats |
| watchdog status | Watchdog status | bctl watchdog status |
| config show | Show configuration | bctl config show |
| logs | View logs | bctl logs --follow |
Automation Scripts
Health Check Script
#!/bin/bash
# Monitor cluster health
if ! bctl health --quiet; then
echo "⚠️ Cluster unhealthy!"
# Get node status
bctl nodes list --format json | jq -r '.nodes[] | select(.status=="down") | "Node \(.node_id) DOWN: \(.hostname)"'
# Send alert
curl -X POST https://alerts.example.com/webhook \
-d '{"text": "pgBalancer cluster has issues"}'
exit 1
fi
echo "✓ Cluster healthy"
exit 0Pool Utilization Alert
#!/bin/bash
# Alert on high pool utilization
UTILIZATION=$(bctl pool stats --format json | jq -r '.utilization_percent')
if (( ${UTILIZATION%.*} > 90 )); then
echo "⚠️ High pool utilization: $UTILIZATION%"
# Send alert
fiBest Practices
✓ DO
- • Use
--format jsonfor scripting and automation - • Use
--format tablefor human-readable output - • Check exit codes in scripts (
bctl health --quiet) - • Use
--verbosefor troubleshooting - • Set environment variables for default host/port
✗ DON'T
- • Don't parse table format output in scripts (use JSON)
- • Don't run
promotewithout understanding impact - • Don't detach nodes during peak traffic
- • Don't ignore error messages and exit codes