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 3501624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:52:57+00:00 2026-05-18T12:52:57+00:00

I have a python program in an embedded system that needs to write to

  • 0

I have a python program in an embedded system that needs to write to an sqlite database. This database is mission critical and thus needs to be fully synchronous. The problem is that the database commits take a LONG time (3-30 seconds) for a single insert. The insert is wrapped in a transaction, but there’s really no way to separate these inserts into multiple transactions.

I’ve been searching for any way to make the database commit take a shorter amount of time but I’m sort of lost.

I’ve tried setting pragma journal_mode=persistance, and that seemed to help but only a small amount. Now I’m thinking it could be sqlite being starved of i/o time.

Is there a way to increase JUST the process priority of sqlite3? I don’t want to increase the python priority itself because we’re doing logging, config updates, and other file i/o, but I want to force sqlite to take as much i/o time as possible.

I’m open to other suggestions to speed commit time up as well.

This is what I’m doing in my insert:

    cur = None
            try:
                logging.info('Inserting into : ' + table + ':' + str(m))
                sql = "INSERT INTO " + table + "("
                bind = " VALUES("
                list = [];
                for k, v in m.items():
                    if(v != None):
                        sql += k + ","
                        bind += "?,"
                        list.append(v)
                sql = str(sql).rstrip(',') + ")"
                bind = str(bind).rstrip(',') + ")"

                cur = conn.cursor()
                cur.execute("PRAGMA journal_mode=PERSIST")
                logging.info(sql + bind)
                cur.execute(sql + bind, list) # It's definitely this that takes the most time. Yes I've profiled.
                conn.commit()
                id = cur.lastrowid
                return id
            except Exception as e:
                raise e
            finally:
                if cur != None:
                    cur.close()
  • 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-05-18T12:52:58+00:00Added an answer on May 18, 2026 at 12:52 pm

    Have you tried 3.7’s WAL?

    Historically, SQLite has been very slow at handling safe writes (eg. without changing to synchronous=off). It wrote the entire transaction to a journal, flushed it to disk, then copied the whole thing back over the original file, with many blocking syncs happening in between, serializing the whole thing.

    SQLite 3.7’s write-ahead logging (WAL) should largely fix this problem; it avoids the redundant write, which is expensive for large transactions, and significantly reduces the number of required FS syncs.

    See: http://www.sqlite.org/wal.html

    • 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 needs to execute an external program, but for
I have embedded a Python interpreter in a C program. Suppose the C program
I have a Python program that uses the threading module. Once every second, my
I have a Python script that calls an executable program with various arguments (in
I have a Python program that runs a cell model continuously. when I press
I have a Python program that consists of several modules. The main module creates
I have a python program that is essentailly made up of turtle graphics, and
I have a Python program for Linux almost looks like this one : import
I have a Python program that spawns many threads, runs 4 at a time,
I have a python program, which runs on the CPython implementation, and inside it

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.