Ess Ramzi Avatar
ESS RAMZI AI AUTOMATION & SYSTEMS ARCHITECT
SURFACE // 0.0M
← RETURN TO ALL LOGS
Database | Resilience | High Availability | Linux
Oct 26, 2026 • 5 min read

High-Availability PostgreSQL Streaming Replication on Linux

Learn how to configure high-availability PostgreSQL streaming replication on Linux for disaster recovery and data consistency.

Architecture Overview

PostgreSQL streaming replication is a feature that allows multiple PostgreSQL servers to replicate data in real-time, ensuring high availability and disaster recovery. This architecture overview will cover the basic components and setup required for high-availability PostgreSQL streaming replication on Linux.

Components

  • Primary Server: The primary server is the main PostgreSQL server that accepts writes and replicates data to the standby servers.
  • Standby Server: The standby server is a read-only PostgreSQL server that replicates data from the primary server.
  • Replication Server: The replication server is responsible for managing the replication process between the primary and standby servers.

Requirements

  • PostgreSQL 10 or later: Streaming replication is supported in PostgreSQL 10 and later versions.
  • Linux Distribution: This guide assumes a Linux distribution such as Ubuntu or CentOS.
  • Network Connectivity: The primary and standby servers must have network connectivity to establish the replication connection.

Implementation & Commands

To set up high-availability PostgreSQL streaming replication on Linux, follow these steps:

Step 1: Install PostgreSQL

sudo apt-get update
sudo apt-get install postgresql-13

Step 2: Create the Primary Server

Create a new PostgreSQL database cluster on the primary server:

sudo pg_createcluster 13 main

Step 3: Configure the Primary Server

Configure the primary server to accept writes and replicate data to the standby servers:

sudo psql -U postgres -c "ALTER SYSTEM SET wal_level = 'hot-standby';"
sudo psql -U postgres -c "ALTER SYSTEM SET max_wal_senders = 10;"

Step 4: Create the Standby Server

Create a new PostgreSQL database cluster on the standby server:

sudo pg_createcluster 13 main

Step 5: Configure the Standby Server

Configure the standby server to replicate data from the primary server:

sudo psql -U postgres -c "ALTER SYSTEM SET wal_level = 'hot-standby';"
sudo psql -U postgres -c "ALTER SYSTEM SET max_wal_senders = 10;"

Step 6: Establish Replication

Establish the replication connection between the primary and standby servers:

sudo pg_ctl promote -D /var/lib/postgresql/13/main

Step 7: Verify Replication

Verify that the replication is working correctly by checking the replication status:

sudo psql -U postgres -c "SELECT * FROM pg_stat_replication;"

Production Edge Cases & Safeguards

  • Network Connectivity: Ensure that the primary and standby servers have network connectivity to establish the replication connection.
  • Disk Space: Ensure that the primary and standby servers have sufficient disk space to store the replicated data.
  • Replication Lag: Monitor the replication lag to ensure that it remains within acceptable limits.

Conclusion

High-availability PostgreSQL streaming replication on Linux is a powerful feature that ensures disaster recovery and data consistency. By following the steps outlined in this guide, you can set up a high-availability PostgreSQL streaming replication environment on Linux.

إعداد الاسترداد العالي للبيانات باستخدام PostgreSQL على Linux

نظرة عامة على التصميم

يعد الاسترداد العالي للبيانات في PostgreSQL ميزة تسمح بترشيح البيانات بين عدد من خوادم PostgreSQL في الوقت الفعلي، مما يضمن الاستقرار العالي والاسترداد في حالة الكوارث. هذا نظرة عامة على مكونات وخطوات الإعداد المطلوبة لاسترداد البيانات العالي الاستقرار في PostgreSQL على Linux.

المكونات

  • الخادم الرئي��ي: هو الخادم الرئيسي ل PostgreSQL الذي يقبل الكتابة ويرشح البيانات إلى الخوادم العصية.
  • الخادم العصي: هو خادم PostgreSQL غير قابل للكتابة يرشح البيانات من الخادم الرئيسي.
  • الخادم المزود للترشيح: هو الخادم المسؤول عن إدارة عملية الترشيح بين الخادم الرئيسي والخادم العصي.

المتطلبات

  • PostgreSQL 10 أو أحدث: يُستخدم الترشيح في PostgreSQL 10 أو أحدث.
  • توزيع Linux: يُستخدم هذا المثال توزيع Linux مثل Ubuntu أو CentOS.
  • الوصلة بالشبكة: يجب أن يكون الخادم الرئيسي والخادم العصي متصلين بالشبكة ل establishment الوصل بينهما.

تنفيذ وتحكم الأوامر

لإعداد الاسترداد العالي للبيانات باستخدام PostgreSQL على Linux، اتبع الخطوات التالية:

خطوة 1: تثبيت PostgreSQL

sudo apt-get update
sudo apt-get install postgresql-13

خطوة 2: إنشاء الخادم الرئيسي

إنشاء مجموعة بيانات جديدة ل PostgreSQL على الخادم الرئيس��:

sudo pg_createcluster 13 main

خطوة 3: ضبط الخادم الرئيسي

ضبط الخادم الرئيسي لتقبل الكتابة ويرشح البيانات إلى الخوادم العصية:

sudo psql -U postgres -c "ALTER SYSTEM SET wal_level = 'hot-standby';"
sudo psql -U postgres -c "ALTER SYSTEM SET max_wal_senders = 10;"

خطوة 4: إنشاء الخادم العصي

إنشاء مجموعة بيانات جديدة ل PostgreSQL على الخادم العصي:

sudo pg_createcluster 13 main

خطوة 5: ضبط الخادم العصي

ضبط الخادم العصي ليرشح البيانات من الخادم الرئيسي:

sudo psql -U postgres -c "ALTER SYSTEM SET wal_level = 'hot-standby';"
sudo psql -U postgres -c "ALTER SYSTEM SET max_wal_senders = 10;"

خطوة 6: establishment الوصل

establishment الوصل بين الخادم الرئيسي والخادم العصي:

sudo pg_ctl promote -D /var/lib/postgresql/13/main

خطوة 7: التحقق من الترشيح

التحقق من أن الترشيح يعمل بشكل صحيح من خلال التحقق من حالة الترشيح:

sudo psql -U postgres -c "SELECT * FROM pg_stat_replication;"

الحالات الحادة في بيئة الإنتاج والمحافظات

  • الوصلة بالشبكة: تأكد من أن الخادم الرئيسي والخادم العصي متصلين بالشبكة ل establishment الوصل بينهما.
  • مساحة القرص: تأكد من أن الخادم الرئيسي والخادم العصي لديهما مساحة القرص الكافية لتخزين البيانات المرسلة.
  • التأخير في الترشيح: مراقبة التأخير في الترشيح لضمان بقاءه ضمن الحدود المقبولة.

الخاتمة

يعد الاسترداد العالي للبيانات باستخدام PostgreSQL على Linux ميزة قوية تضمن الاسترداد في حالة الكوارث وثبات البيانات. من خلال اتباع الخطوات المذكورة في هذا المقال، يمكنك إعداد بيئة الاسترداد العالي للبيانات باستخدام PostgreSQL على Linux.

#PostgreSQL #Streaming Replication #High Availability #Linux #Disaster Recovery
MORE FIELD NOTES →