Thuta Learning
ရှာဖွေရန်
AdvancedData & Databasesbeginner

Table Partitioning

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Table Partitioning concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ SQL/command ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် အသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Partitioning က logical table တစ်ခုကို physical pieces များခွဲပါတယ်။ Query performance သာမက old data ကို partition detach/drop လုပ်ခြင်းအတွက်အသုံးဝင်ပါတယ်။ Table သေးသေးကို partition လုပ်ရင် planning/operations complexity ပိုလာနိုင်ပြီး partition key၊ unique constraints နှင့် missing future partitions ကိုကြိုစီမံရပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Audit events ကို month-by-month `created_at` range partition လုပ်မယ်။ Query တွင် partition key condition ပါမှ pruning ရနိုင်ပြီး `EXPLAIN` နဲ့စစ်ပါ။ Default partition သို့ automated partition creation strategy ကို production runbook ထဲထည့်ရပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

sql
CREATE TABLE app.audit_events (
  event_id bigint GENERATED ALWAYS AS IDENTITY,
  created_at timestamptz NOT NULL,
  event_type text NOT NULL,
  payload jsonb NOT NULL,
  PRIMARY KEY (created_at, event_id)
) PARTITION BY RANGE (created_at);

CREATE TABLE app.audit_events_2026_08
PARTITION OF app.audit_events
FOR VALUES FROM ('2026-08-01') TO ('2026-09-01');

EXPLAIN SELECT * FROM app.audit_events
WHERE created_at >= '2026-08-10' AND created_at < '2026-08-11';
You should see
August partition တစ်ခုနှင့် pruning စစ်နိုင်သော query plan ရမည်။

၅ မိနစ် စမ်းကြည့်

September partition ထပ်ဖန်တီးပြီး boundary timestamp များ ဘယ် partition ဝင်သလဲစမ်းပါ။

သတိလေးတစ်ချက်

Partition မရှိသည့် date ရောက်လာရင် insert fail နိုင်ပါတယ်။ Calendar-based automation နဲ့ alert လိုပါတယ်။

PostgreSQL — Table PartitioningPostgreSQL Global Development Group

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Partition မရှိသည့် date ရောက်လာရင် insert fail နိုင်ပါတယ်။ Calendar-based automation နဲ့ alert လိုပါတယ်။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

September partition ထပ်ဖန်တီးပြီး boundary timestamp များ ဘယ် partition ဝင်သလဲစမ်းပါ။

You'll know it worked when: August partition တစ်ခုနှင့် pruning စစ်နိုင်သော query plan ရမည်။

Table Partitioning | Thuta Learning