Why this matters
Reduces round trips and lock contention; improves throughput.
Use executemany/bulk operations and commit in sensible batches for large writes.
Reduces round trips and lock contention; improves throughput.
Side-by-side examples engineers can pattern-match during review.
for row in rows:
conn.execute('INSERT ...', row)
conn.commit()conn.executemany('INSERT ...', rows)
conn.commit() # or commit every N rows for very large setsfor r in rows: insert(r)executemany('INSERT ...', rows)From the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.