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

การจำลองแบบซิงโครนัสเทียบกับอะซิงโครนัส

ทำความเข้าใจข้อแลกเปลี่ยนระหว่างความคงทนของข้อมูลกับเวลาแฝงในการจำลองแบบทางกายภาพชนิดซิงโครนัสและอะซิงโครนัสของ PostgreSQL

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

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

Two Modes of Streaming

Physical streaming replication can run in two modes: asynchronous (the default) and synchronous. They differ in when the primary considers a commit complete.

Asynchronous Replication

In async mode the primary commits as soon as the WAL is flushed locally. It does not wait for the standby. This is fast but a crash can lose the most recent commits not yet shipped.

Synchronous Replication

In sync mode the primary waits until at least one standby confirms it received (or applied) the WAL before reporting commit success. This guarantees zero data loss for confirmed commits at the cost of extra latency.

Configuring Sync Standbys

Name your standbys with application_name and list them in synchronous_standby_names on the primary.

-- on the primary, in postgresql.conf
synchronous_standby_names = 'standby1, standby2';

Quorum-based Sync

You can require any N of several standbys to confirm, balancing durability and availability.

synchronous_standby_names = 'ANY 1 (standby1, standby2)';

synchronous_commit Levels

The synchronous_commit setting controls how far a commit must travel:

  • off / local — local only
  • remote_write — standby received WAL
  • on — standby flushed WAL to disk
  • remote_apply — standby applied WAL (visible on replica)

Per-transaction Control

This setting can be changed per transaction, letting unimportant writes go fast while critical writes wait for confirmation.

SET synchronous_commit = 'remote_apply';
INSERT INTO payments (amount) VALUES (100);

Availability Risk of Sync

If the only synchronous standby goes down, commits on the primary will block until a standby returns. Always pair sync replication with multiple candidates or quorum settings.

Checking Replication State

Inspect the live state from the primary using pg_stat_replication.

SELECT application_name, state, sync_state
FROM pg_stat_replication;

Choosing a Mode

Use async for throughput and geographically distant replicas. Use sync when losing even one committed transaction is unacceptable, such as financial ledgers.

Latency Reality

Synchronous commit latency is roughly the network round-trip to the standby plus its fsync time. Keeping sync standbys on a low-latency link is essential.

Quick Check

What is the key trade-off of synchronous replication?

Recap

You compared asynchronous and synchronous replication, configured synchronous_standby_names and synchronous_commit levels, and learned the durability-vs-latency-vs-availability trade-offs.

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

บทเรียน “การจำลองแบบซิงโครนัสเทียบกับอะซิงโครนัส” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “การจำลองแบบซิงโครนัสเทียบกับอะซิงโครนัส”

ทำความเข้าใจข้อแลกเปลี่ยนระหว่างความคงทนของข้อมูลกับเวลาแฝงในการจำลองแบบทางกายภาพชนิดซิงโครนัสและอะซิงโครนัสของ PostgreSQL คุณปฏิบัติ 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. การจำลองข้อมูลทางกายภาพ (แบบสตรีม)
  3. การตั้งค่าเซิร์ฟเวอร์สำรอง
  4. การจำลองแบบซิงโครนัสเทียบกับอะซิงโครนัส
← กลับไปที่ Advanced PostgreSQL: Indexing, Partitioning, Replication