0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · レッスン

同期レプリケーションと非同期レプリケーション

PostgreSQLの物理レプリケーションにおける、同期レプリケーションと非同期レプリケーションの耐久性とレイテンシのトレードオフを理解します。

「同期レプリケーションと非同期レプリケーション」はCoddyKit上の無料Advanced PostgreSQL: Indexing, Partitioning, Replicationレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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.

よくある質問

「同期レプリケーションと非同期レプリケーション」レッスンは無料ですか?

はい。「同期レプリケーションと非同期レプリケーション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Advanced PostgreSQL: Indexing, Partitioning, Replicationコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Advanced PostgreSQL: Indexing, Partitioning, Replicationコースには全4レッスンが含まれています。

「同期レプリケーションと非同期レプリケーション」で何を学びますか?

PostgreSQLの物理レプリケーションにおける、同期レプリケーションと非同期レプリケーションの耐久性とレイテンシのトレードオフを理解します。 ブラウザで直接実行するハンズオンコードでAdvanced PostgreSQL: Indexing, Partitioning, Replicationを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Advanced PostgreSQL: Indexing, Partitioning, Replicationを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAdvanced PostgreSQL: Indexing, Partitioning, Replicationは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン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に戻る