Scheduled Database Maintenance Job Design Prompt
Design a scheduled database maintenance job — vacuum/analyze, reindex, partition rotation, and stats refresh — that runs in low-traffic windows with lock-aware throttling and a safe abort, instead of a cron line that blocks production at peak.
- Target user
- DBAs and platform engineers automating routine database upkeep
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior database and automation engineer who has had a "harmless" nightly reindex take an exclusive lock and stall the application for everyone awake at the wrong time zone. I will provide: - The database engine and version (Postgres, MySQL, etc.) and rough table sizes - The maintenance tasks needed (vacuum/analyze, reindex, partition create/drop, stats refresh, archival) - The traffic pattern and the available low-traffic window - Replication topology and any constraints (no long transactions, replica lag limits) Your job: 1. **Task inventory and locks** — for each task, state the lock it takes, whether an online/concurrent variant exists (`REINDEX CONCURRENTLY`, `pt-online-schema-change`), and the safe order to run them. 2. **Window and scheduling** — pick the maintenance window, the scheduler (systemd timer / cron / orchestrator), and a max-runtime cap so the job cannot bleed into peak hours. 3. **Throttling and lag guards** — define how the job checks replica lag and active-query load before and during the run, and pauses or aborts if it would harm production. 4. **Idempotency and resume** — make each task safe to re-run and able to resume mid-list, so a job killed at the runtime cap picks up where it left off next window. 5. **Partition lifecycle** — if applicable, define create-ahead and drop/archive-behind rules, with a guard that never drops a partition still holding required data. 6. **Failure handling** — define what happens on a failed or timed-out task: skip-and-alert vs halt, and how partial completion is recorded. 7. **Observability** — list the metrics and logs (duration per task, rows processed, lag during run, aborts) to alert on a job that ran long or stopped firing. Output as: a task table (task | lock | online variant | order), the scheduler/window config, the lag/abort guard logic, and the failure/alerting plan. Require that any task taking a blocking lock prefer its online variant, run only inside the window with a hard runtime cap, and abort cleanly on replica-lag or load thresholds with a documented way to skip a problem table.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Automation Client-Side Rate Limiter Token Bucket Design Prompt
Design a client-side rate limiter for automation that calls external APIs, using a token-bucket to stay under provider quotas, absorb bursts, and coordinate limits across concurrent workers without tripping 429s.
-
Cross-Region Automation Failover Orchestration Design Prompt
Design the orchestration that fails automation control planes and scheduled jobs over to a secondary region, avoiding split-brain double-execution while guaranteeing critical jobs still run during a regional outage.
-
Event Ordering and Sequencing Guarantee Design Prompt
Design an event-driven automation flow that preserves the ordering guarantees the domain actually needs, choosing partition keys, sequencing, and out-of-order handling so state-changing events apply in the correct order.
-
Event Schema Versioning and Contract Evolution Design Prompt
Design a versioning and compatibility strategy for automation event payloads so producers can evolve schemas without breaking existing consumers, with explicit rules for additive, breaking, and deprecation changes.
More Automation prompts & error guides
Browse every Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.