I create a SQLite file like this:

sqlite3 output.db < myinserts.sql

Unfortunately it takes hours, so I want to speed it up by using the following PRAGMAs:

PRAGMA synchronous=OFF
PRAGMA count_changes=OFF
PRAGMA journal_mode=MEMORY
PRAGMA temp_store=MEMORY

QUESTION: How to set them on the command line?
It is for a script so I don't want interactive mode, I want to do all in a single command line.

2 Answers 2


You may echo you PRAGMA then prepend them to you sql using cat

echo "PRAGMA synchronous=OFF;PRAGMA journal_mode=OFF;PRAGMA temp_store=MEMORY;" | cat - myinserts.sql | sqlite3 output.db

For other ways to prepend to a file in memory, see https://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/


I have not found an easy way to specify these on command line, but a workaround can be to put these lines at the beginning of the SQL input:

echo "PRAGMA synchronous=OFF;PRAGMA count_changes=OFF;PRAGMA journal_mode=MEMORY;PRAGMA temp_store=MEMORY" \
  > tmp.sql
cat myinserts.sql >> tmp.sql
sqlite3 output.db < tmp.sql
rm tmp.sql

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .