التقسيم حسب النطاق الزمني
تعلّم كيفية تقسيم الجداول الكبيرة حسب النطاقات الزمنية للحفاظ على سرعة الوصول إلى البيانات الحديثة وأرشفة البيانات القديمة بكفاءة.
التقسيم حسب النطاق الزمني درس مجاني في Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Advanced PostgreSQL: Indexing, Partitioning, Replication، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Range Partitioning
Range partitioning splits a table into chunks based on a continuous value, most often a date or timestamp.
It is the most common strategy for time-series data such as logs, events, and orders, because old data can be dropped or archived as a whole partition.
Declaring a Range-Partitioned Table
You declare partitioning with PARTITION BY RANGE on the parent table.
CREATE TABLE events (
id bigserial,
created_at timestamptz NOT NULL,
payload jsonb
) PARTITION BY RANGE (created_at);Creating Monthly Partitions
Each child partition covers a half-open interval: the lower bound is inclusive and the upper bound is exclusive.
CREATE TABLE events_2024_01 PARTITION OF events
FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
CREATE TABLE events_2024_02 PARTITION OF events
FOR VALUES FROM ('2024-02-01') TO ('2024-03-01');Half-Open Intervals
The exclusive upper bound prevents gaps and overlaps. A row at exactly 2024-02-01 00:00:00 lands in events_2024_02, never in January.
This makes consecutive partitions perfectly contiguous.
Inserting Routes Automatically
You insert into the parent table. PostgreSQL routes each row to the correct partition based on the range key.
INSERT INTO events (created_at, payload)
VALUES ('2024-01-15', '{"type":"login"}');
-- lands in events_2024_01A DEFAULT Partition
A DEFAULT partition catches any row that does not match a defined range, avoiding insert errors.
CREATE TABLE events_default PARTITION OF events DEFAULT;Indexes on Partitions
An index created on the parent is automatically propagated to all current and future partitions.
CREATE INDEX ON events (created_at);Dropping Old Data Instantly
The killer feature: deleting old data is just DROP TABLE on a partition. No row-by-row DELETE, no bloat, no vacuum pressure.
DROP TABLE events_2024_01;Querying with Pruning
When the planner sees a range predicate on the partition key it can skip entire partitions. This is called partition pruning.
SELECT count(*) FROM events
WHERE created_at >= '2024-02-10'
AND created_at < '2024-02-20';
-- only events_2024_02 is scannedAutomating Partition Creation
Tools like pg_partman create future partitions ahead of time on a schedule, so you never insert into the default partition by accident.
- Define a retention window
- Pre-create N future partitions
- Detach or drop expired ones
Choosing the Range Width
Pick a width that keeps each partition in the tens of millions of rows. Too many tiny partitions hurt planning time; too few huge ones lose pruning benefits.
Quick Check
Why is dropping an old partition better than a bulk DELETE?
Recap
You learned range partitioning by time: declare with PARTITION BY RANGE, create half-open child intervals, rely on automatic routing and pruning, and archive by dropping whole partitions. Automation tools like pg_partman keep the partition set healthy.
الأسئلة الشائعة
هل درس «التقسيم حسب النطاق الزمني» مجاني؟
نعم — نص درس «التقسيم حسب النطاق الزمني» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «التقسيم حسب النطاق الزمني»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Advanced PostgreSQL: Indexing, Partitioning, Replication هذا؟
نعم. كل درس في Advanced PostgreSQL: Indexing, Partitioning, Replication يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- التقسيم بالتجزئة للتوزيع
- تقنيات التقسيم الفرعي
- إدارة الجداول المقسّمة
- التقسيم حسب النطاق الزمني