Schedule icon
Assert icon
Queries icon
Write icon
If icon
Pause icon
SlackIncomingWebhook icon

Recover PostgreSQL DEFAULT Partition Rows with Approved Attachment

Recover stranded PostgreSQL DEFAULT rows with a dry-run plan, human approval, atomic movement and attachment, retries, and verified results.

Categories
DataInfrastructure

Recover a missed monthly partition when its rows already occupy DEFAULT and block ordinary partition creation.

How it works

  1. A disabled daily UTC schedule always dry-runs. Inspect a root RANGE table with one DATE key.
  2. Save a count and SHA-256 plan; source values stay in PostgreSQL.
  3. Apply pauses for approval (default reject; two-hour expiry). Under exclusive parent/DEFAULT locks, recheck fingerprints, move rows, compare full row multisets and attach in one transaction.
  4. Independently verify bounds and empty source month. Existing exact attachments and empty candidate sets are no-ops.

What you get

  • Plan: {{ outputs.save_plan.uri }}; outcome, including failures/rejections: {{ outputs.save_result.uri }}.
  • Recovery counts: {{ outputs.recover.outputs[0].row }} when applied.
  • SQL failure rolls back movement and creation. Temporary snapshots are session-local. Post-commit verification failure alerts without undoing recovery.

Who it's for

DBAs repairing small DEFAULT backlogs in a maintenance window.

Why orchestrate this with Kestra

Separate inspection, saved evidence, durable approval, atomic SQL, independent verification and failure alerts replace an unaudited manual repair.

Prerequisites

PostgreSQL 16+, JDBC plugin, family ownership, schema CREATE and database TEMP permission. Only logged plain leaves; no RLS, foreign keys, table triggers, rules, generated or identity columns. Exclusive locks block parent/DEFAULT access. DEFAULT scans and index builds can be expensive even below the row limit. Applications use the parent; direct-leaf grants are not copied.

Secrets

  • POSTGRES_USERNAME: database owner role.
  • POSTGRES_PASSWORD: its password.
  • SLACK_WEBHOOK_URL: failure-alert destination.

Quick start

  1. Configure secrets and JDBC connectivity; import without catalog extend metadata.
  2. Inputs: jdbc_url STRING defaults to jdbc:postgresql://postgres:5432/partition_demo; table_schema/parent_table STRING default public/events (lowercase identifiers, 63/48 chars); month_start DATE defaults 2026-10-01, first day only.
  3. Run dry_run BOOL=true. Review the plan for derived <parent>_pYYYYMM.
  4. Set false, approve, inspect the outcome and query tableoid through the parent. max_rows INT=10000 (1–100000); lock_timeout_ms INT=2000 (100–10000); statement_timeout_seconds INT=60 (5–300). kestra_url STRING=http://localhost:8080 builds alert links.
  5. Select the audit month before enabling the schedule; it never applies automatically.

How to extend

Add timestamp handling only with explicit timezone bounds. Large backlogs need a dedicated migration. Changed fingerprints require a fresh plan and approval.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.