DBAtlas · Atlas für Datenbankbetrieb

Partition anlegen / teilen / löschen

Oracle

-- Add a RANGE partition
ALTER TABLE sales ADD PARTITION p2026 VALUES LESS THAN (TO_DATE('2027-01-01','YYYY-MM-DD'));

-- Split an existing partition
ALTER TABLE sales SPLIT PARTITION pmax AT (TO_DATE('2027-01-01','YYYY-MM-DD')) INTO (PARTITION p2026, PARTITION pmax);

-- Drop a partition
ALTER TABLE sales DROP PARTITION p2020 UPDATE INDEXES;

Unterstützt RANGE/LIST/HASH-Partitionierung. DROP PARTITION löscht alle Zeilen dieser Partition; mit UPDATE INDEXES bleiben globale Indizes gültig. Interval-Partitionierung kann Partitionen automatisch hinzufügen.

PostgreSQL

-- Declarative partitioning: parent table
CREATE TABLE sales (id bigint, created_at date, amount numeric) PARTITION BY RANGE (created_at);

-- Add a new partition
CREATE TABLE sales_2026 PARTITION OF sales FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');

-- Attach a standalone (existing) table as a partition
CREATE TABLE sales_2027 (LIKE sales INCLUDING ALL);
ALTER TABLE sales ATTACH PARTITION sales_2027 FOR VALUES FROM ('2027-01-01') TO ('2028-01-01');

-- Detach a partition (the table is not dropped; it remains a standalone table)
ALTER TABLE sales DETACH PARTITION sales_2026;

Core-PostgreSQL hat kein SPLIT/MERGE PARTITION (Stand PG17); zum Teilen die Partition per DETACH lösen, zwei Partitionen mit den neuen Grenzen anlegen, die Daten verschieben und per ATTACH einhängen. DETACH ... CONCURRENTLY (PG14+) verkürzt die Sperrdauer.

MySQL

-- Partitioned table
CREATE TABLE sales (id BIGINT, created_at DATE) PARTITION BY RANGE (YEAR(created_at)) (
  PARTITION p2024 VALUES LESS THAN (2025),
  PARTITION p2025 VALUES LESS THAN (2026),
  PARTITION pmax VALUES LESS THAN MAXVALUE
);

-- Add / split / drop a partition
ALTER TABLE sales REORGANIZE PARTITION pmax INTO (
  PARTITION p2026 VALUES LESS THAN (2027),
  PARTITION pmax VALUES LESS THAN MAXVALUE
);
ALTER TABLE sales DROP PARTITION p2024;

Die Partitionierungsspalte muss Teil jedes PRIMARY KEY / UNIQUE-Keys sein. Bei RANGE erfolgt Teilen/Zusammenführen mit REORGANIZE PARTITION. DROP PARTITION löscht auch die Zeilen (RANGE/LIST).

SQL Server

-- 1) Partition function and scheme
CREATE PARTITION FUNCTION pf_date (date) AS RANGE RIGHT FOR VALUES ('2025-01-01','2026-01-01');
CREATE PARTITION SCHEME ps_date AS PARTITION pf_date ALL TO ([PRIMARY]);

-- 2) Add a new boundary (split)
ALTER PARTITION SCHEME ps_date NEXT USED [PRIMARY];
ALTER PARTITION FUNCTION pf_date() SPLIT RANGE ('2027-01-01');

-- 3) Remove a boundary (merge)
ALTER PARTITION FUNCTION pf_date() MERGE RANGE ('2025-01-01');

Es werden eine Partition Function + ein Partition Scheme definiert, und die Tabelle wird mit CREATE TABLE ... ON ps_date(created_at) auf diesem Scheme angelegt. Vor SPLIT muss die NEXT USED-Filegroup gesetzt sein. Zum Entfernen von Daten diese mit SWITCH PARTITION in eine Staging-Tabelle auslagern.

MongoDB

// MongoDB uses sharding instead of table partitioning
sh.shardCollection("db.sales", { created_at: 1 });

// Native time-series collection for time series
db.createCollection("measurements", { timeseries: { timeField: "ts", granularity: "hours" } });

Partitionierung im klassischen Sinn gibt es nicht. Horizontale Aufteilung erfolgt beim Sharding über Chunks; für zeitbasierte Daten bieten Time-Series-Collections automatisches Bucketing.

Redis

# Not applicable: Redis has no table/partition concept; scaling is done with Redis Cluster hash slots (16384).

Redis Cluster verteilt Keys auf 16384 Hash-Slots; das ist Aufteilung auf Anwendungsebene, keine Tabellenpartitionierung. Einen manuellen Partitionsbefehl gibt es nicht.

Elasticsearch

# Time-based automatic splitting (rollover) with an ILM policy + data stream
PUT _ilm/policy/logs-policy
{ "policy": { "phases": { "hot": { "actions": { "rollover": { "max_size": "50gb", "max_age": "30d" } } } } } }

PUT _index_template/logs-tmpl
{ "index_patterns": ["logs*"], "data_stream": {}, "template": { "settings": { "index.lifecycle.name": "logs-policy" } } }

In Elasticsearch erfolgt die Aufteilung, indem ein Index in Shards zerlegt wird, und bei Zeitreihen durch neue Backing Indices mit ILM + Data Streams (Rollover). Alte Indizes lassen sich mit ILM löschen.

In DBAtlas öffnen →