← Back to PostgreSQL Course | Chapter 9: Indexes & Performance | Lesson 5 of 7

VACUUM का उपयोग

VACUUM updates और deletes से बची dead rows clean करता है ताकि space reuse हो सके।

In this page:

  1. VACUUM
Syntax
sql
VACUUM table_name;
VACUUM ANALYZE table_name;

VACUUM

PostgreSQL का MVCC old row versions तब तक रखता है जब तक कोई transaction इन्हें चाहता हो, और VACUUM इन dead tuples को remove करता है और visibility information update करता है।

Autovacuum इसे automatically चलाता है। VACUUM (ANALYZE) statistics भी refresh करता है, और VACUUM FULL OS को space वापस देने के लिए table फिर से लिखता है लेकिन एक exclusive lock लेता है।

Note: autovacuum enabled रखें और busy tables के लिए इसे tune करें।

उदाहरण: VACUUM

bash
shop=# VACUUM (VERBOSE, ANALYZE) orders;
INFO:  vacuuming "public.orders"
INFO:  table "orders": removed 12034 dead row versions in 310 pages
shop=# SELECT relname, n_live_tup, n_dead_tup, last_autovacuum FROM pg_stat_user_tables WHERE relname = 'orders';
 relname | n_live_tup | n_dead_tup |        last_autovacuum
---------+------------+------------+-------------------------------
 orders  |     250000 |          0 | 2024-03-15 09:12:44.51+00

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. autovacuum disable करना
  2. busy tables पर VACUUM FULL चलाना
  3. Long-running transactions cleanup block करते हुए
चैप्टर सारांश
  • VACUUM dead rows remove करता है
  • Autovacuum इसे automatically करता है
  • ANALYZE statistics refresh करता है
  • VACUUM FULL table lock करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.