Schedule icon
Script icon
Create icon
If icon
SlackIncomingWebhook icon
Log icon

PostgreSQL Table Bloat and Autovacuum Starvation Sentinel

Monitor PostgreSQL table bloat and autovacuum lag with Kestra. Inspect pg_stat_user_tables, log GitHub DBA maintenance issues, and alert Slack.

Categories
DataInfrastructure

Diagram unavailable

We could not build the topology for this blueprint. The flow itself is valid, use the YAML on the left to run it.

Dead tuples in high-traffic PostgreSQL databases cause index degradation, table bloat, and severe query performance drops if autovacuum falls behind. This blueprint provides a scheduled Day 2 database health sentinel that inspects pg_stat_user_tables for dead tuple accumulation, logs a structured maintenance issue on GitHub, and alerts database engineers via Slack.

How it works

  1. A Schedule trigger (io.kestra.plugin.core.trigger.Schedule) fires nightly during low-traffic maintenance windows (02:00 UTC).
  2. The analyze_table_bloat task (io.kestra.plugin.scripts.python.Script) connects to PostgreSQL, evaluates the ratio of dead tuples to total tuples, and determines if any table crosses the threshold.
  3. The create_bloat_remediation_issue task (io.kestra.plugin.github.issues.Create) logs a tracked DBA maintenance issue on GitHub with recommended remediation steps.
  4. The check_bloat_threshold task (io.kestra.plugin.core.flow.If) branches conditionally: if bloat is detected, it alerts the team via Slack with direct links to the tracking issue. Otherwise, it logs a clean health check.

What you get

  • Automated visibility into PostgreSQL dead tuple accumulation without manual SQL queries.
  • Proactive alerts before table bloat causes disk exhaustion or query latency spikes.
  • Systematic GitHub issue logging for scheduled maintenance windows.
  • Configurable dead tuple percentage and count thresholds.

Who it's for

  • Database Administrators (DBAs) maintaining PostgreSQL production clusters.
  • Platform engineers and SREs responsible for database performance and storage hygiene.
  • Backend developers working with write-heavy transactional workloads.

Why orchestrate this with Kestra

Monitoring internal database statistics requires connecting to private database subnets, evaluating multi-metric heuristics, and alerting external notification channels. Kestra handles database credentials securely, schedules execution during off-peak hours, and unifies SQL inspection with GitHub tracking and Slack alerts in a single version-controlled YAML workflow.

Prerequisites

  • A running PostgreSQL database (version 12+) accessible from Kestra workers.
  • A read-only database user with access to pg_stat_user_tables.
  • A GitHub Personal Access Token with repo issues scope.
  • A Slack incoming webhook configured for database alerts.

Secrets

  • POSTGRES_URL: PostgreSQL connection string (e.g. postgresql://user:pass@db.example.com:5432/dbname).
  • GITHUB_TOKEN: GitHub Personal Access Token for logging maintenance issues.
  • SLACK_WEBHOOK: Incoming Webhook URL for DBA team notifications.

Quick start

  1. Configure the three secrets in your Kestra namespace or instance settings.
  2. Import this flow into your target namespace (e.g., company.database).
  3. Set dead_tuple_ratio_threshold to match your application's tolerance (e.g., 20%).
  4. Run manually to verify dead tuple analysis, GitHub issue creation, and Slack alerts.
  5. Enable the nightly schedule trigger.

How to extend

  • Add an automated VACUUM step for safe staging tables after approval.
  • Extend the Python script to check for index bloat (pgstatindex) or transaction ID wraparound risk.
  • Route alerts to PagerDuty or Opsgenie for critical bloat levels exceeding 50%.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.