Partitioning की Basics
Partitioning एक huge table को छोटे physical pieces में split करता है जिन्हें PostgreSQL एक table की तरह treat करता है।
In this page:
Syntax
CREATE TABLE parent_table (
id bigint,
created date
) PARTITION BY RANGE (created);
CREATE TABLE partition_name PARTITION OF parent_table
FOR VALUES FROM ('start') TO ('end');
Partitioning Basics
Declarative partitioning के साथ आप PARTITION BY RANGE, LIST, या HASH इस्तेमाल करके एक parent table बनाते हैं और फिर child partitions जो slices hold करती हैं, जैसे प्रति month एक।
Partition key पर filter करने वाली queries सिर्फ relevant partitions को touch करती हैं (partition pruning), और old data को एक partition instantly drop करके remove किया जा सकता है।
Note:
एक partition drop करना लाखों rows delete करने से कहीं ज़्यादा तेज़ है।
उदाहरण: Partitioning basics
shop=# CREATE TABLE measurements (
shop(# id bigint GENERATED ALWAYS AS IDENTITY,
shop(# taken_at date NOT NULL,
shop(# value numeric
shop(# ) PARTITION BY RANGE (taken_at);
shop=# CREATE TABLE measurements_2024_01 PARTITION OF measurements FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
shop=# CREATE TABLE measurements_2024_02 PARTITION OF measurements FOR VALUES FROM ('2024-02-01') TO ('2024-03-01');
shop=# DROP TABLE measurements_2024_01; -- removes a whole month instantly
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- छोटी tables partition करना
- एक ऐसा partition key चुनना जिस पर queries filter न करें
- बहुत सारी tiny partitions बनाना
चैप्टर सारांश
- RANGE, LIST, या HASH से Declarative partitioning
- Partition pruning irrelevant partitions skip करता है
- Old partitions instantly drop करें
- बहुत बड़ी tables के लिए best
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: