When to Use
- Database health checks
- Connection verification
- Performance monitoring
- Backup status verification
Prerequisites
- Azure CLI for Azure databases
- psql for PostgreSQL operations
- Appropriate database credentials
Commands
Azure PostgreSQL
# List PostgreSQL servers
az postgres flexible-server list -o table
# Show server details
az postgres flexible-server show --name <server> --resource-group <rg>
# Check firewall rules
az postgres flexible-server firewall-rule list --name <server> --resource-group <rg>
# Check backup retention
az postgres flexible-server show --name <server> --resource-group <rg> --query "backup"
Connection Testing
# Test PostgreSQL connection
psql "host=<host> dbname=<db> user=<user> sslmode=require" -c "SELECT version();"
# Check active connections
psql -c "SELECT count(*) FROM pg_stat_activity WHERE state = 'active';"
Health Monitoring
# Check database size
psql -c "SELECT pg_size_pretty(pg_database_size(current_database()));"
# Check table sizes
psql -c "SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename))
FROM pg_tables ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC LIMIT 10;"
Best Practices
- Use private endpoints for database connectivity
- Enable SSL/TLS for all connections
- Configure automated backups
- Monitor connection pool usage
- Set up alerts for high CPU/memory
Output Format
- Command executed
- Database status summary
- Any issues detected
- Recommendations
Integration with Agents
Used by: @terraform, @sre, @test