Recuperar espaço livre (shrink / vacuum / compact)
Oracle
ALTER TABLE customer ENABLE ROW MOVEMENT;
ALTER TABLE customer SHRINK SPACE;SHRINK reduz o high water mark (HWM). Para reduzir também os í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 obtém um AccessExclusiveLock e reescreve a tabela; não execute em horários de pico. Alternativa: pg_repack.
MySQL
OPTIMIZE TABLE customer;No InnoDB, reconstrói a tabela e devolve o espaço data_free; demora bastante em tabelas grandes.
SQL Server
-- Generally NOT RECOMMENDED (causes fragmentation). If really needed:
DBCC SHRINKFILE (N'MyDB_data', 1024); -- target 1024 MBReduzir um arquivo de dados causa fragmentação de índices; faça REBUILD dos índices depois. Para o log, faça um backup antes.
MongoDB
db.runCommand({ compact: "customer" })No WiredTiger, tenta devolver o espaço livre ao sistema operacional (nem sempre é possível). No 4.4+ não bloqueia leituras/escritas, apenas certas operações DDL na mesma coleção; como gera IO intenso, executá-lo em um secondary e em uma janela de manutenção é mais seguro.
Redis
MEMORY PURGE
# Tries to return jemalloc fragmentation to the OSA configuração activedefrag yes faz desfragmentação automática online; MEMORY DOCTOR dá recomendações.