New to Kestra?
Use blueprints to kickstart your first workflows.
Monitor Postgres dead tuples and autovacuum lag with Kestra. Query pg_stat_user_tables, identify table bloat, and alert DBAs via Slack.
In PostgreSQL, updates and deletes generate dead tuples that consume disk space and degrade sequential scans until autovacuum reclaims them. Under heavy write workloads, long-running transactions, or conservative autovacuum configurations, dead tuples accumulate rapidly—bloating tables and indexes, exhausting disk capacity, and polluting the database buffer cache.
This blueprint queries PostgreSQL's native pg_stat_user_tables catalog to detect tables where dead tuple counts and ratios breach operational thresholds. It exports structured metrics into execution outputs, evaluates severity, and alerts DBAs and on-call engineers on Slack with targeted remediation guidance.
inspect_table_bloat (io.kestra.plugin.jdbc.postgresql.Query) connects to the target PostgreSQL database and inspects pg_stat_user_tables with fetchType: FETCH. It filters for tables where dead tuple counts and bloat ratios exceed inputs.dead_tuple_threshold and inputs.dead_ratio_threshold_percent.emit_audit_metrics (io.kestra.plugin.core.output.OutputValues) exports diagnostic variables (bloated_table_count, database_scanned, host_scanned, scanned_at) into execution outputs for auditability.evaluate_bloat_severity (io.kestra.plugin.core.flow.If) checks whether any bloated tables were found:notify_dba_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches a formatted Slack notification listing the offending tables, dead tuple counts, bloat percentages, and last autovacuum timestamps.log_healthy_status (io.kestra.plugin.core.log.Log) logs that all user tables are within acceptable thresholds.alert_on_failure in the errors block dispatches a Slack alert if database connection fails or credentials expire.Monitoring PostgreSQL health through ad-hoc bash scripts or unmonitored crontabs is fragile: crons lack execution logs, failure retries, and centralized secret management. Kestra provides native JDBC integration with declarative configuration, built-in credential isolation via secrets, dual schedule and webhook triggers, and automated notification routing when thresholds are crossed.
POSTGRES_USER: Database username with read access to pg_stat_user_tables.POSTGRES_PASSWORD: Database password for authentication.SLACK_WEBHOOK_URL: Slack Incoming Webhook destination URL.WEBHOOK_KEY: Secret authentication key for the manual webhook trigger.POSTGRES_USER, POSTGRES_PASSWORD, SLACK_WEBHOOK_URL, and WEBHOOK_KEY to your Kestra namespace secrets.postgres_host, postgres_port, and database_name inputs to match your database environment.scheduled_sentinel trigger to run audits automatically during off-peak hours.VACUUM ANALYZE task for low-risk tables during scheduled maintenance windows.