0Pricing
PostgreSQL Performance & Query Optimization · 강의

MVCC 및 VACUUM 이해

다중 버전 동시성 제어(MVCC)와 테이블 비대화를 방지하는 VACUUM의 중요한 역할을 살펴봅니다.

MVCC 및 VACUUM 이해은(는) CoddyKit의 무료 PostgreSQL Performance & Query Optimization 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 PostgreSQL Performance & Query Optimization 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Meet MVCC: Concurrency's Friend

Welcome to understanding PostgreSQL's core! Today, we dive into Multi-Version Concurrency Control (MVCC). It's a fancy term for a simple, powerful idea.

MVCC is how PostgreSQL allows many users or applications to access and modify data at the same time without interfering with each other. Think of it as a traffic controller for your database.

Why MVCC Matters for Speed

Imagine a database without MVCC. If one user is reading a row, another user trying to update that same row would have to wait. This is called locking, and too much of it can make your database painfully slow.

MVCC solves this by ensuring that readers don't block writers, and writers don't block readers. Everyone gets their own consistent view of the data.

Rows Have Many Lives

The magic of MVCC lies in how it handles changes. When you UPDATE or DELETE a row in PostgreSQL, the database doesn't immediately overwrite or remove the original data.

Instead, it creates a new version of the row (for updates) or simply marks the existing row as 'deleted' without physically removing it. The old version remains, temporarily.

Seeing the Right Data

How does PostgreSQL know which version of a row to show you? Each transaction gets a unique ID. When a row is created, it gets an xmin (creation transaction ID). When it's 'deleted', it gets an xmax (deletion transaction ID).

  • Your transaction only sees rows committed *before* it started.
  • It ignores rows deleted *after* it started.

This ensures you always see a consistent snapshot of the data.

The Aftermath of an UPDATE

Let's see a simple example of how an UPDATE creates new row versions:

First, we create a table and insert a product:

CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100),
  price DECIMAL(10, 2)
);

INSERT INTO products (name, price) VALUES ('Laptop', 1200.00);

Updates Create Dead Tuples

Now, when we update the price, PostgreSQL doesn't change the existing row. Instead, it marks the old row version as 'dead' and inserts a brand new row version with the updated price.

The old version is now a 'dead tuple' – it's no longer visible to new transactions but still occupies disk space.

UPDATE products SET price = 1250.00 WHERE id = 1;

The Hidden Mess: Table Bloat

Over time, with many UPDATEs and DELETEs, tables can accumulate a lot of these 'dead tuples'. This leads to table bloat.

Table bloat means your database files are larger than they need to be, consuming more disk space and potentially slowing down queries because more data needs to be read from disk.

Enter VACUUM!

This is where the VACUUM command comes in! Its primary job is to clean up these dead tuples. It's like a janitor for your database, tidying up the old, unused versions of data.

VACUUM marks the space occupied by dead tuples as reusable, making it available for new data to be inserted into the table. This prevents continuous table growth and improves performance.

How VACUUM Cleans Up

When you run VACUUM, PostgreSQL scans the table, identifies dead tuples, and adds their locations to a 'free space map'. This doesn't immediately shrink the table file on disk, but it ensures that future INSERTs or UPDATEs can reuse that space.

Here's how you'd run a basic VACUUM:

-- Clean up the 'products' table
VACUUM products;

MVCC & VACUUM Check

Let's test your understanding of MVCC and VACUUM's roles.

MVCC & VACUUM: Key Takeaways

You've just learned about two critical PostgreSQL concepts!

  • MVCC enables high concurrency by allowing multiple versions of data.
  • UPDATEs and DELETEs create dead tuples.
  • Table bloat occurs when these dead tuples accumulate, wasting space.
  • The VACUUM command cleans up dead tuples, making their space reusable and preventing bloat.

Understanding these is key to maintaining a healthy and performant PostgreSQL database!

자주 묻는 질문

“MVCC 및 VACUUM 이해” 강의는 무료인가요?

네 — “MVCC 및 VACUUM 이해” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 PostgreSQL Performance & Query Optimization 강의 전체를 잠금 해제할 수 있습니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.

“MVCC 및 VACUUM 이해”에서 뭘 배우나요?

다중 버전 동시성 제어(MVCC)와 테이블 비대화를 방지하는 VACUUM의 중요한 역할을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 PostgreSQL Performance & Query Optimization을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

PostgreSQL Performance & Query Optimization을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 PostgreSQL Performance & Query Optimization은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“MVCC 및 VACUUM 이해” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 PostgreSQL Performance & Query Optimization 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 PostgreSQL Performance & Query Optimization 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. MVCC 및 VACUUM 이해
  2. 자동 진공 구성 및 튜닝
  3. 트랜잭션 격리 수준의 영향
  4. 트랜잭션 ID 순환 방지
← PostgreSQL Performance & Query Optimization(으)로 돌아가기