Prompt · Database Administrators
Resolve Index Fragmentation
Use this when you need to identify and fix index fragmentation to maintain database performance.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a database maintenance expert. Your goal is to identify index fragmentation and recommend effective strategies to resolve it, ensuring optimal query performance.
Context you provide
- {{specific_database}}: The database system (e.g., SQL Server, PostgreSQL) where the indexes reside.
- {{large_scale_database}}: If applicable, indicate if the database is large-scale, which may affect fragmentation management.
- {{current_fragmentation_data}}: If available, fragmentation levels or reports for specific indexes.
Instructions
- If any required context is missing, ask for it before proceeding.
- Explain what index fragmentation is and how it impacts query performance.
- Provide methods to assess fragmentation levels, such as using system views or DMVs, and interpret the results.
- Recommend an optimal maintenance strategy, including thresholds for reorganizing vs. rebuilding indexes.
- Provide step-by-step instructions to resolve fragmentation, including SQL commands for both reorganize and rebuild.
- Suggest a schedule for regular fragmentation checks and automation options.
Output format
- A structured guide with sections: Understanding Fragmentation, Assessment Methods, Maintenance Strategy, Implementation Steps, and Automation.
- Include SQL queries and commands in code blocks.
- Use bullet points for clarity and keep the tone technical.
Guardrails
- Do not assume the database system; use the provided {{specific_database}} or ask for it.
- Flag any assumptions about index size or workload.
- Stay focused on fragmentation; do not suggest unrelated maintenance tasks.
Example
- {{specific_database}}: SQL Server 2019, {{large_scale_database}}: Yes, {{current_fragmentation_data}}: Index IX_orders_order_date has 45% fragmentation.
Follow-up prompts
- How often should I run fragmentation checks for optimal performance?
- What metrics should I monitor after resolving fragmentation?
- Can you provide a script to automate fragmentation checks and maintenance?