Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:25:49+00:00 2026-06-10T06:25:49+00:00

I have written a Python script that takes a 1.5 G XML file, parses

  • 0

I have written a Python script that takes a 1.5 G XML file, parses out data and feeds it to a database using copy_from. It invokes the following function every 1000 parsed nodes. There are about 170k nodes in all which update about 300k rows or more. It starts out quite fast and then gets progressively slower as time goes on. Any ideas on why this is happening and what I can do to fix it?

Here is the function where I feed the data to the db.

 def db_update(val_str, tbl, cols):

    conn = psycopg2.connect("dbname=<mydb> user=postgres password=<mypw>")
    cur = conn.cursor()
    output = cStringIO.StringIO()
    output.write(val_str)
    output.seek(0)
    cur.copy_from(output, tbl, sep='\t', columns=(cols))
    conn.commit()

I haven’t included the xml parsing as I don’t think that’s an issue. Without the db the parser executes in under 2 minutes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:25:50+00:00Added an answer on June 10, 2026 at 6:25 am

    There are several things that can slow inserts as tables grow:

    • Triggers that have to do more work as the DB grows
    • Indexes, which get more expensive to update as they grow

    Disable any non-critical triggers, or if that isn’t possible re-design them to run in constant time.

    Drop indexes, then create them after the data has been loaded. If you need any indexes for the actual INSERTs or UPDATEs you’ll need to keep them an wear the cost.

    If you’re doing lots of UPDATEs, consider VACUUMing the table periodically, or setting autovacuum to run very aggressively. That’ll help Pg re-use space rather than more expensively allocating new space from the file system, and will help avoid table bloat.

    You’ll also save time by not re-connecting for each block of work. Maintain a connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that parses an XML file that contains part information
I have a mechanize script written in python that fills out a web form
I have written a CGI script that creates an image dynamically using GET data.
I have written a Python script that will generate a series of graphs and
I have written a Python script for merging many data files in a few
I have written up a python script that allows a user to input a
I have written a python script (my very first) that accepts input of a
I have written a Python script that checks a certain e-mail address and passes
I have written a Python script that currently is designed to handle traditional CGI
I have written a short python script that opens Google music in web view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.