0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · บทเรียน

การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล

ใช้การถอดรหัสเชิงตรรกะเพื่อสตรีมการเปลี่ยนแปลงระดับแถวออกจาก PostgreSQL สำหรับไปป์ไลน์ CDC และระบบที่ขับเคลื่อนด้วยเหตุการณ์

การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล เป็นบทเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Advanced PostgreSQL: Indexing, Partitioning, Replication และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What Is Logical Decoding

Logical decoding turns the write-ahead log into a readable stream of logical row changes. It is the foundation of both logical replication and external Change Data Capture (CDC).

Output Plugins

A plugin decides the format of the change stream. Built-in pgoutput powers logical replication; test_decoding emits human-readable text; tools like Debezium use their own.

Prerequisite: wal_level

Logical decoding needs wal_level = logical. Changing it requires a restart.

-- postgresql.conf
wal_level = logical

Creating a Logical Slot

A logical replication slot tracks how far a consumer has read and prevents WAL needed by it from being removed.

SELECT pg_create_logical_replication_slot(
  'cdc_slot', 'test_decoding');

Peeking at Changes

pg_logical_slot_peek_changes shows pending changes without advancing the slot, useful for inspection.

SELECT * FROM pg_logical_slot_peek_changes(
  'cdc_slot', NULL, NULL);

Consuming Changes

pg_logical_slot_get_changes reads and advances the slot, so those changes will not be returned again.

SELECT * FROM pg_logical_slot_get_changes(
  'cdc_slot', NULL, NULL);

Example Change Output

With test_decoding an INSERT appears as readable text describing the table and new column values, wrapped between BEGIN and COMMIT markers.

BEGIN 712
table public.users: INSERT: id[int]:1 name[text]:'Ada'
COMMIT 712

Slots Hold WAL

An inactive slot keeps WAL forever, which can fill the disk. Monitor and drop unused slots.

SELECT slot_name, active FROM pg_replication_slots;
SELECT pg_drop_replication_slot('cdc_slot');

CDC Pipelines

External CDC connectors stream from a slot into systems like Kafka, search indexes, or data warehouses, enabling near-real-time downstream updates.

At-least-once Delivery

Consumers must track the last confirmed LSN and handle possible re-delivery after a crash. Design downstream writes to be idempotent.

Replica Identity for CDC

To capture the full before image on updates and deletes, set REPLICA IDENTITY FULL on tables without a usable primary key.

ALTER TABLE orders REPLICA IDENTITY FULL;

Quick Check

Why must logical replication slots be monitored?

Recap

You learned logical decoding: set wal_level=logical, create a logical slot with an output plugin, peek or consume changes, and feed CDC pipelines. Monitor slots, design idempotent consumers, and set replica identity for full change images.

คำถามที่พบบ่อย

บทเรียน “การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Advanced PostgreSQL: Indexing, Partitioning, Replication มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล”

ใช้การถอดรหัสเชิงตรรกะเพื่อสตรีมการเปลี่ยนแปลงระดับแถวออกจาก PostgreSQL สำหรับไปป์ไลน์ CDC และระบบที่ขับเคลื่อนด้วยเหตุการณ์ คุณปฏิบัติ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การจำลองข้อมูลแบบต่อเนื่อง
  2. การจำลองข้อมูลแบบหลายหลัก (BDR)
  3. สล็อตการจำลองข้อมูลและการจัดการ WAL
  4. การถอดรหัสเชิงตรรกะและการบันทึกการเปลี่ยนแปลงข้อมูล
← กลับไปที่ Advanced PostgreSQL: Indexing, Partitioning, Replication