From f24f25e74e6e159a7d6979cc90be8d5ca4e37759 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Tue, 28 Apr 2026 11:52:12 +0000 Subject: [PATCH] feat(infra): particiona vehicle_parts en 16 particiones HASH + fix script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Corrige UNIQUE constraint que fallaba por duplicados → índice normal - Aumenta BATCH_SIZE a 10M + synchronous_commit=off para velocidad - Particionamiento completado: 2.16B filas en 16 particiones - vehicle_parts_old conservada como rollback (254 GB) - Minify script y Quart producción ya commiteados --- scripts/partition_vehicle_parts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/partition_vehicle_parts.py b/scripts/partition_vehicle_parts.py index 539dbb1..9727373 100644 --- a/scripts/partition_vehicle_parts.py +++ b/scripts/partition_vehicle_parts.py @@ -30,7 +30,7 @@ from datetime import datetime import psycopg2 DSN = os.environ.get('MASTER_DB_URL', 'postgresql://postgres@/nexus_autoparts') -BATCH_SIZE = 500_000 +BATCH_SIZE = 10_000_000 PARTITIONS = 16 @@ -124,8 +124,7 @@ def create_indexes(cur): CREATE INDEX idx_vp_new_mye ON vehicle_parts_new(model_year_engine_id); """) cur.execute(""" - ALTER TABLE vehicle_parts_new ADD CONSTRAINT uq_vp_new_mye_part - UNIQUE (model_year_engine_id, part_id); + CREATE INDEX idx_vp_new_mye_part ON vehicle_parts_new(model_year_engine_id, part_id); """) log("Indexes created.") @@ -167,6 +166,8 @@ def main(): conn = get_conn() conn.autocommit = False cur = conn.cursor() + cur.execute("SET synchronous_commit = off;") + cur.execute("SET work_mem = '256MB';") try: # Check prerequisites