feat(infra): particiona vehicle_parts en 16 particiones HASH + fix script
- 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
This commit is contained in:
@@ -30,7 +30,7 @@ from datetime import datetime
|
|||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
DSN = os.environ.get('MASTER_DB_URL', 'postgresql://postgres@/nexus_autoparts')
|
DSN = os.environ.get('MASTER_DB_URL', 'postgresql://postgres@/nexus_autoparts')
|
||||||
BATCH_SIZE = 500_000
|
BATCH_SIZE = 10_000_000
|
||||||
PARTITIONS = 16
|
PARTITIONS = 16
|
||||||
|
|
||||||
|
|
||||||
@@ -124,8 +124,7 @@ def create_indexes(cur):
|
|||||||
CREATE INDEX idx_vp_new_mye ON vehicle_parts_new(model_year_engine_id);
|
CREATE INDEX idx_vp_new_mye ON vehicle_parts_new(model_year_engine_id);
|
||||||
""")
|
""")
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
ALTER TABLE vehicle_parts_new ADD CONSTRAINT uq_vp_new_mye_part
|
CREATE INDEX idx_vp_new_mye_part ON vehicle_parts_new(model_year_engine_id, part_id);
|
||||||
UNIQUE (model_year_engine_id, part_id);
|
|
||||||
""")
|
""")
|
||||||
log("Indexes created.")
|
log("Indexes created.")
|
||||||
|
|
||||||
@@ -167,6 +166,8 @@ def main():
|
|||||||
conn = get_conn()
|
conn = get_conn()
|
||||||
conn.autocommit = False
|
conn.autocommit = False
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
cur.execute("SET synchronous_commit = off;")
|
||||||
|
cur.execute("SET work_mem = '256MB';")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Check prerequisites
|
# Check prerequisites
|
||||||
|
|||||||
Reference in New Issue
Block a user