The Real Fullstack

The Transaction That Never Ended

Autovacuum is on. Why has the orders table grown to seven times its real size?

مهندس أول9 دقيقةمختبر تصحيح الأخطاءمختبر الأداء
postgresqlspring-bootvacuumhikaricp

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Read pg_stat_activity and the vacuum logs, name the root cause, and keep transactions short — with a safety net.السياق · أهداف التعلّم ▾

Larkspur's invoice job is annotated @Transactional: it opens a transaction, loads orders, then calls a slow PDF service for hours. Meanwhile the orders table bloats to 210 GB, queries read six times more pages and the pool slowly runs out of connections.

المهمة: Read pg_stat_activity and the vacuum logs, name the root cause, and keep transactions short — with a safety net.

أهداف التعلّم

  • Understand how an open transaction pins old row versions (MVCC).
  • Keep slow external work outside database transactions.
  • Use idle_in_transaction_session_timeout as a safety net.
المحاكاةمحاكاة
invoice jobHikariCP poolPostgreSQL
تشغيل المحاكاة
// read inside a short transaction, do slow external work outside itList<Order> orders = tx.execute(s -> orderRepo.findToInvoice(month));   // millisecondsfor (Order o : orders) {  byte[] pdf = pdfService.render(o);                                    // minutes — no transaction open  tx.executeWithoutResult(s -> invoiceRepo.save(o.id(), pdf));}

تبسيط

Three symptoms with deterministic fixes. Long-running analytics queries on replicas can cause similar effects via hot_standby_feedback. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

تحديات ذات صلة

المراجع