DBAtlas · Atlas de operaciones de bases de datos

Recuperar espacio libre (shrink / vacuum / compact)

Oracle

ALTER TABLE customer ENABLE ROW MOVEMENT;
ALTER TABLE customer SHRINK SPACE;

SHRINK reduce el high water mark (HWM). Para reducir también los índices, use SHRINK SPACE CASCADE.

PostgreSQL

-- Online, light locking (does not return space to the OS):
VACUUM (VERBOSE, ANALYZE) customer;
-- Return space to the OS (locks the table!):
-- VACUUM FULL customer;

VACUUM FULL adquiere un AccessExclusiveLock y reescribe la tabla; no lo ejecute en horas pico. Alternativa: pg_repack.

MySQL

OPTIMIZE TABLE customer;

En InnoDB reconstruye la tabla y libera el espacio data_free; tarda mucho en tablas grandes.

SQL Server

-- Generally NOT RECOMMENDED (causes fragmentation). If really needed:
DBCC SHRINKFILE (N'MyDB_data', 1024);  -- target 1024 MB

Reducir un archivo de datos provoca fragmentación de índices; haga REBUILD de los índices después. Para el log, haga primero un backup.

MongoDB

db.runCommand({ compact: "customer" })

En WiredTiger intenta devolver el espacio libre al sistema operativo (no siempre es posible). En 4.4+ no bloquea lecturas/escrituras, solo ciertas operaciones DDL sobre la misma colección; como genera mucha E/S, es más seguro ejecutarlo en un secondary y en una ventana de mantenimiento.

Redis

MEMORY PURGE
# Tries to return jemalloc fragmentation to the OS

La opción activedefrag yes realiza la desfragmentación automática en línea; MEMORY DOCTOR ofrece recomendaciones.

Abrir en DBAtlas →