Bereichspartitionierung nach Zeit
Lernen Sie, wie Sie große Tabellen nach Zeitbereichen partitionieren, damit aktuelle Daten schnell verfügbar bleiben und alte Daten effizient archiviert werden können.
Bereichspartitionierung nach Zeit ist eine kostenlose Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Advanced PostgreSQL: Indexing, Partitioning, Replication-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
Häufig gestellte Fragen
Ist die Lektion „Bereichspartitionierung nach Zeit“ kostenlos?
Ja — der vollständige Text von „Bereichspartitionierung nach Zeit“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Bereichspartitionierung nach Zeit“?
Lernen Sie, wie Sie große Tabellen nach Zeitbereichen partitionieren, damit aktuelle Daten schnell verfügbar bleiben und alte Daten effizient archiviert werden können. Du übst Advanced PostgreSQL: Indexing, Partitioning, Replication mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Advanced PostgreSQL: Indexing, Partitioning, Replication zu starten?
Keine Vorkenntnisse erforderlich. Advanced PostgreSQL: Indexing, Partitioning, Replication auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Bereichspartitionierung nach Zeit“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion Code schreiben und ausführen?
Ja. Jede Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Hash-Partitionierung zur Verteilung
- Techniken zur Unterpartitionierung
- Partitionierte Tabellen verwalten
- Bereichspartitionierung nach Zeit