การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง
ทำความเข้าใจว่า MVCC ทำให้ตารางและดัชนีพองตัวได้อย่างไร วิธีวัดปัญหา และวิธีปรับแต่งการกวาดล้างอัตโนมัติเพื่อรักษาประสิทธิภาพให้สูง
การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง เป็นบทเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
MVCC and Dead Tuples
PostgreSQL uses MVCC: updates and deletes leave behind old row versions called dead tuples. Until they are cleaned up, they occupy space and slow scans. This wasted space is bloat.
What VACUUM Does
VACUUM reclaims dead tuples for reuse and updates visibility information. It usually does not return space to the OS; VACUUM FULL does but rewrites the whole table and takes a strong lock.
Measuring Bloat
Inspect dead tuple counts per table from the statistics view.
SELECT relname, n_live_tup, n_dead_tup,
last_autovacuum
FROM pg_stat_user_tables
ORDER BY n_dead_tup DESC;Autovacuum Basics
Autovacuum runs in the background, triggering when dead tuples exceed a threshold based on table size and the scale factor setting.
-- trigger ~ threshold + scale_factor * n_live_tup
autovacuum_vacuum_scale_factor = 0.2Tuning Hot Tables
For large, frequently updated tables, the default 20% scale factor is too lazy. Lower it per table so vacuum runs more often on less garbage.
ALTER TABLE orders SET (
autovacuum_vacuum_scale_factor = 0.02);Vacuum Throttling
Autovacuum throttles itself with cost limits to avoid I/O storms. On modern hardware you can raise autovacuum_vacuum_cost_limit so vacuum finishes faster.
autovacuum_vacuum_cost_limit = 2000Transaction ID Wraparound
VACUUM also prevents transaction ID wraparound, a catastrophic condition. Aggressive anti-wraparound vacuums are non-negotiable and cannot be skipped.
SELECT datname, age(datfrozenxid)
FROM pg_database ORDER BY 2 DESC;Index Bloat
Indexes bloat too. REINDEX CONCURRENTLY rebuilds an index without blocking writes, restoring its compactness.
REINDEX INDEX CONCURRENTLY orders_pkey;HOT Updates
Heap-Only Tuple updates avoid index churn when no indexed column changes. Leaving some free space via a lower fillfactor helps HOT updates and reduces bloat.
ALTER TABLE orders SET (fillfactor = 90);VACUUM vs ANALYZE
VACUUM reclaims space; ANALYZE refreshes the planner statistics. Autovacuum does both, but after big bulk loads run ANALYZE manually for fresh plans.
ANALYZE orders;A Monitoring Habit
Alert on rising n_dead_tup, growing table size with stable row counts, and high age(datfrozenxid). These early signals let you tune before queries slow down.
Quick Check
A large, hot table keeps growing despite stable row counts. What is the likely cause and fix?
Recap
You learned to diagnose bloat from MVCC dead tuples, measure it with pg_stat_user_tables, tune autovacuum per table, guard against ID wraparound, and use REINDEX CONCURRENTLY and fillfactor to keep performance high.
เรียนรู้ Advanced PostgreSQL: Indexing, Partitioning, Replication ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 11
- บทเรียน
- 44
คำถามที่พบบ่อย
บทเรียน “การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง”
ทำความเข้าใจว่า MVCC ทำให้ตารางและดัชนีพองตัวได้อย่างไร วิธีวัดปัญหา และวิธีปรับแต่งการกวาดล้างอัตโนมัติเพื่อรักษาประสิทธิภาพให้สูง คุณปฏิบัติ Advanced PostgreSQL: Indexing, Partitioning, Replication ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Advanced PostgreSQL: Indexing, Partitioning, Replication บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication นี้ได้ไหม
ได้ บทเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การปรับแต่งประสิทธิภาพแบบองค์รวม
- การตรวจสอบและการแจ้งเตือนขั้นสูง
- แนวโน้มในอนาคตของ PostgreSQL
- การวินิจฉัยข้อมูลพองตัวและกลยุทธ์การกวาดล้าง