Enhance database performance diagnostics: Add detailed logging for unused primary key index and implement error handling for query statistics retrieval. Additionally, automate ANALYZE execution for affected tables after index creation to ensure PostgreSQL optimizes query performance. This improves clarity on index usage and enhances overall database performance management.
This commit is contained in:
@@ -86,8 +86,19 @@ async function main() {
|
||||
});
|
||||
console.log('');
|
||||
|
||||
// Erklärung: Warum knowledge_pkey ungenutzt ist
|
||||
const pkUnused = allIndexes.find(i => i.indexname === 'knowledge_pkey' && (i.idx_scan == null || parseInt(i.idx_scan) === 0));
|
||||
if (pkUnused) {
|
||||
console.log('💡 Warum knowledge_pkey (0 Scans) ungenutzt ist:');
|
||||
console.log(' Alle Zugriffe filtern nach (character_id, product_id), nie nach id.');
|
||||
console.log(' Der PK-Index wird nur für Eindeutigkeit/Referenzen genutzt, nicht für Lookups.');
|
||||
console.log(' idx_knowledge_character_product deckt die tatsächlichen Queries ab.\n');
|
||||
}
|
||||
|
||||
// Prüfe ob Queries mit id (Primary Key) gemacht werden
|
||||
const [idUsage] = await sequelize.query(`
|
||||
let idUsage = [];
|
||||
try {
|
||||
const [rows] = await sequelize.query(`
|
||||
SELECT
|
||||
query,
|
||||
calls,
|
||||
@@ -99,6 +110,10 @@ async function main() {
|
||||
ORDER BY calls DESC
|
||||
LIMIT 5;
|
||||
`);
|
||||
idUsage = rows;
|
||||
} catch (e) {
|
||||
console.log(' ℹ️ pg_stat_statements nicht verfügbar – keine Query-Statistik.\n');
|
||||
}
|
||||
|
||||
if (idUsage.length > 0) {
|
||||
console.log('🔍 Queries die knowledge.id verwenden:');
|
||||
|
||||
Reference in New Issue
Block a user