How I Boosted SQL Data Loading Speed by 10x with the COPY Command
by Harshil Ghataliya · 10/5/2026
When I first started working on a data loading and ETL project, everything looked simple extract the data, transform it, and load it into the SQL database. But as the data size grew from a few thousand records to millions of rows, my loading speed slowed to a crawl. What once took seconds was now taking hours. I tried two approaches: Normal inserts with ORM (like SQLAlchemy or Django ORM) Bulk upload methods provided by the ORM And while these methods were fine for smaller datasets, they were not scalable for large data loads. That’s when I discovered the COPY command a game changer for large-scale data loading. 🚀 The Game Changer: PostgreSQL COPY Command The COPY command is designed specifically for high-performance bulk data ingestion. Instead of inserting row by row, COPY streams an entire file (like CSV) directly into the database table bypassing much of the overhead and achieving incredible speed. Example: Loading a CSV with COPY Here’s a minimal Python example using psycopg2: import psycopg2 conn = psycopg2.connect("dbname=mydb user=user password=password host=localhost port=5432") cur = conn.cursor() with open("data.csv", "r") as f: cur.copy_expert("COPY users (id, name) FROM STDIN WITH CSV HEADER", f) conn.commit() cur.close() conn.close() ⏱ Performance Comparison Here’s how my pipeline times changed after switching to COPY: Press enter or click to view image in full size That’s almost a 10x speed boost with just a few lines of code change. 💡 Key Takeaways Row-by-row inserts don’t scale for large datasets. COPY is built for speed it can handle millions of rows in minutes. For ETL pipelines, analytics, or AI systems, COPY should be your go-to for bulk ingestion. Final Words What I learned is simple: Sometimes the fastest solution isn’t more Python code — it’s using the database the way it was designed. If your ETL pipeline is struggling with slow loads, give the COPY command a try you’ll be amazed at how much time you can save.
by Harshil Ghataliya
