ضبط المنشورات
تعلّم تعريف المنشورات على خادم رئيسي لتحديد الجداول والعمليات التي ينبغي نسخها.
ضبط المنشورات درس مجاني في Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Advanced PostgreSQL: Indexing, Partitioning, Replication، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
What are Publications?
Welcome! In PostgreSQL logical replication, a publication is like a channel on the master server that broadcasts data changes.
It defines what data (which tables) and which operations (INSERTs, UPDATEs, DELETEs, TRUNCATEs) should be replicated to subscribing servers.
Think of it as setting up a TV station: you decide which shows to broadcast and when.
Basic Publication Setup
Creating a publication is straightforward using the CREATE PUBLICATION command. Let's start with the simplest form.
This creates a publication that doesn't publish any tables yet, but it's ready to be configured.
CREATE PUBLICATION my_first_pub;Publishing All Tables
If you want to replicate all tables in your current database (and any new ones created later), you can use the FOR ALL TABLES clause.
This is handy for replicating an entire database schema.
CREATE PUBLICATION all_db_changes FOR ALL TABLES;Publishing Specific Tables
Often, you only need to replicate a subset of tables. You can specify these tables directly using the FOR TABLE clause.
This publication will only broadcast changes from the users and products tables.
CREATE PUBLICATION sales_data_pub FOR TABLE users, products;Dynamic vs. Static
There's a key difference between FOR ALL TABLES and listing tables with FOR TABLE:
FOR ALL TABLES: Dynamically includes all current and future tables in the database.FOR TABLE table1, table2: Statically lists specific tables. New tables must be added manually.
Choose based on your replication needs!
Replicating Specific Operations
Publications can be configured to replicate only certain types of data modifications. By default, INSERT, UPDATE, DELETE, and TRUNCATE are replicated.
You can use the WITH (publish = '...') clause to select specific operations. Here, we only replicate INSERT statements.
CREATE PUBLICATION new_orders_only FOR TABLE orders WITH (publish = 'insert');Combining Operations
To replicate multiple, but not all, operation types, you can list them separated by commas within the publish option.
This publication will replicate INSERT, UPDATE, and DELETE operations, but not TRUNCATE.
CREATE PUBLICATION user_activity FOR TABLE user_logs WITH (publish = 'insert, update, delete');Listing Publications
Want to see what publications are active on your server? PostgreSQL stores this information in its system catalogs.
You can query the pg_publication view to get details about each publication, including what operations it publishes.
SELECT pubname, puballtables, pubinsert, pubupdate, pubdelete, pubtruncate FROM pg_publication;Managing Publications
You can modify an existing publication to add or remove tables, or even drop it entirely if it's no longer needed.
ALTER PUBLICATION ADD TABLE: Add tables.ALTER PUBLICATION DROP TABLE: Remove tables.DROP PUBLICATION: Delete a publication.
ALTER PUBLICATION sales_data_pub ADD TABLE accounts;
ALTER PUBLICATION sales_data_pub DROP TABLE products;
DROP PUBLICATION sales_data_pub;Publication Configuration Quiz
Which of the following statements correctly configure a publication in PostgreSQL?
Recap: Configuring Publications
Great job! You've learned how to define publications in PostgreSQL.
- Publications broadcast data changes for logical replication.
- Use
CREATE PUBLICATIONto define them. - You can publish
FOR ALL TABLESorFOR TABLE specific_tables. - The
WITH (publish = '...')clause lets you select specific operations (insert, update, delete, truncate). - You can manage them with
ALTER PUBLICATIONandDROP PUBLICATION.
Next, we'll learn how to set up subscriptions to receive these changes!
الأسئلة الشائعة
هل درس «ضبط المنشورات» مجاني؟
نعم — نص درس «ضبط المنشورات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Advanced PostgreSQL: Indexing, Partitioning, Replication، انتقل إلى CoddyKit PRO. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
ماذا ستتعلم في «ضبط المنشورات»؟
تعلّم تعريف المنشورات على خادم رئيسي لتحديد الجداول والعمليات التي ينبغي نسخها. تتمرن على Advanced PostgreSQL: Indexing, Partitioning, Replication مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Advanced PostgreSQL: Indexing, Partitioning, Replication؟
لا تُشترط خبرة سابقة. Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «ضبط المنشورات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Advanced PostgreSQL: Indexing, Partitioning, Replication هذا؟
نعم. كل درس في Advanced PostgreSQL: Indexing, Partitioning, Replication يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.