النسخ المتماثل المتزامن مقابل غير المتزامن
افهم المفاضلات بين المتانة ووقت الاستجابة في النسخ المتماثل الفيزيائي المتزامن وغير المتزامن في PostgreSQL.
النسخ المتماثل المتزامن مقابل غير المتزامن درس مجاني في Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 onlyremote_write— standby received WALon— standby flushed WAL to diskremote_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/7) وفتح باقي دورة Advanced PostgreSQL: Indexing, Partitioning, Replication، انتقل إلى CoddyKit PRO. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
ماذا ستتعلم في «النسخ المتماثل المتزامن مقابل غير المتزامن»؟
افهم المفاضلات بين المتانة ووقت الاستجابة في النسخ المتماثل الفيزيائي المتزامن وغير المتزامن في PostgreSQL. تتمرن على Advanced PostgreSQL: Indexing, Partitioning, Replication مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- فهم مفاهيم النسخ المتماثل
- النسخ المتماثل الفعلي (بث البيانات)
- إعداد خادم احتياطي
- النسخ المتماثل المتزامن مقابل غير المتزامن