Crear / dividir / eliminar una partición
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;Admite particionamiento RANGE/LIST/HASH. DROP PARTITION elimina todas las filas de esa partición; con UPDATE INDEXES, los índices globales siguen siendo válidos. El particionamiento por intervalos puede añadir particiones automáticamente.
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;PostgreSQL básico no tiene SPLIT/MERGE PARTITION (a fecha de PG17); para dividir, haga DETACH de la partición, cree dos particiones con los nuevos límites, mueva los datos y haga ATTACH. DETACH ... CONCURRENTLY (PG14+) reduce la duración del bloqueo.
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;La columna de particionamiento debe formar parte de toda PRIMARY KEY / clave UNIQUE. Para RANGE, la división/fusión se hace con REORGANIZE PARTITION. DROP PARTITION también elimina las filas (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');Se definen una partition function + scheme y la tabla se crea sobre ese scheme con CREATE TABLE ... ON ps_date(created_at). El filegroup NEXT USED debe establecerse antes de SPLIT. Para retirar datos, muévalos a una tabla de staging con SWITCH PARTITION.
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" } });No hay particionamiento en el sentido clásico. La división horizontal se hace mediante chunks con sharding; para datos temporales, las time-series collections proporcionan bucketing automático.
Redis
# Not applicable: Redis has no table/partition concept; scaling is done with Redis Cluster hash slots (16384).Redis Cluster distribuye las claves entre 16384 hash slots; es una división a nivel de aplicación, no particionamiento de tablas. No existe un comando de partición manual.
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" } } }En Elasticsearch, la división se logra repartiendo un índice en shards y, para series temporales, creando nuevos backing indices con ILM + data streams (rollover). Los índices antiguos se pueden eliminar con ILM.