Schedule icon
Commands icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon

Report Unused Postgres Indexes

Find indexes with zero scans and alert Slack so write-taxing dead indexes get dropped.

Categories
DataInfrastructureinfrastructure

Every index costs write throughput forever, even ones nobody reads. This blueprint queries pg_stat_user_indexes for zero-scan secondary indexes and posts the list to Slack weekly.

How it works

  1. find_unused (io.kestra.plugin.scripts.shell.Commands on the Python image) connects to Postgres and emits the zero-scan index names via the ::{"outputs": ...}:: protocol.
  2. unused_found (io.kestra.plugin.core.flow.If) branches to alert_unused or log_clean.
  3. The errors block alerts on failure.
  4. Trigger: a disabled weekly Schedule.

What you get

  • The exact unused index names in Slack.
  • A standing cleanup nudge instead of a forensic session.

Who it's for

  • Teams whose schema accreted indexes from three refactors ago.
  • Write-heavy workloads where every index matters.

Why orchestrate this with Kestra

The stats view answers the question; the flow makes it a scheduled review with history and alerts. The next step (DROP script, ticket, add to a quarterly runbook) is one task away.

Prerequisites

  • Docker available on the Kestra Worker.
  • Network reachability to the database and a read-only role.
  • A Slack webhook.

Secrets

  • SLACK_WEBHOOK_URL: webhook for findings and failure alerts.
  • PG_PASSWORD: database password.

Quick start

  1. Add the Slack webhook and PG_PASSWORD secrets.
  2. Set jdbc_url.
  3. Run once and read unused_indexes.
  4. Enable the weekly schedule.

How to extend

  • Emit size per index with pg_relation_size.
  • Compare week-over-week via KV.
  • Generate the DROP INDEX script as an artifact.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.