1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
4
<title>Appropriate Uses For SQLite</title>
5
<style type="text/css">
8
font-family: Verdana, sans-serif;
13
a:visited { color: #734559 }
15
.logo { position:absolute; margin:3px; }
31
.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
32
.toolbar a:visited { color: white; }
33
.toolbar a:hover { color: #044a64; background: white; }
35
.content { margin: 5%; }
36
.content dt { font-weight:bold; }
37
.content dd { margin-bottom: 25px; margin-left:20%; }
38
.content ul { padding:0px; padding-left: 15px; margin:0px; }
41
.se { background: url(images/se.gif) 100% 100% no-repeat #044a64}
42
.sw { background: url(images/sw.gif) 0% 100% no-repeat }
43
.ne { background: url(images/ne.gif) 100% 0% no-repeat }
44
.nw { background: url(images/nw.gif) 0% 0% no-repeat }
46
/* Things for "fancyformat" documents start here. */
47
.fancy img+p {font-style:italic}
48
.fancy .codeblock i { color: darkblue; }
49
.fancy h1,.fancy h2,.fancy h3,.fancy h4 {font-weight:normal;color:#044a64}
50
.fancy h2 { margin-left: 10px }
51
.fancy h3 { margin-left: 20px }
52
.fancy h4 { margin-left: 30px }
53
.fancy th {white-space:nowrap;text-align:left;border-bottom:solid 1px #444}
54
.fancy th, .fancy td {padding: 0.2em 1ex; vertical-align:top}
55
.fancy #toc a { color: darkblue ; text-decoration: none }
56
.fancy .todo { color: #AA3333 ; font-style : italic }
57
.fancy .todo:before { content: 'TODO:' }
58
.fancy p.todo { border: solid #AA3333 1px; padding: 1ex }
59
.fancy img { display:block; }
60
.fancy :link:hover, .fancy :visited:hover { background: wheat }
61
.fancy p,.fancy ul,.fancy ol { margin: 1em 5ex }
62
.fancy li p { margin: 1em 0 }
63
/* End of "fancyformat" specific rules. */
69
<div><!-- container div to satisfy validator -->
72
<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite Logo"
74
<div><!-- IE hack to prevent disappearing logo--></div>
75
<div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div>
77
<table width=100% style="clear:both"><tr><td>
78
<div class="se"><div class="sw"><div class="ne"><div class="nw">
79
<table width=100% style="padding:0;margin:0;cell-spacing:0"><tr>
82
<a href="about.html">About</a>
83
<a href="sitemap.html">Sitemap</a>
84
<a href="docs.html">Documentation</a>
85
<a href="download.html">Download</a>
86
<a href="copyright.html">License</a>
87
<a href="news.html">News</a>
88
<a href="support.html">Support</a>
91
gMsg = "Search SQLite Docs..."
92
function entersearch() {
93
var q = document.getElementById("q");
94
if( q.value == gMsg ) { q.value = "" }
95
q.style.color = "black"
96
q.style.fontStyle = "normal"
98
function leavesearch() {
99
var q = document.getElementById("q");
100
if( q.value == "" ) {
102
q.style.color = "#044a64"
103
q.style.fontStyle = "italic"
108
<div style="padding:0 1em 0px 0;white-space:nowrap">
109
<form name=f method="GET" action="http://www.sqlite.org/search">
110
<input id=q name=q type=text
111
onfocus="entersearch()" onblur="leavesearch()" style="width:24ex;padding:1px 1ex; border:solid white 1px; font-size:0.9em ; font-style:italic;color:#044a64;" value="Search SQLite Docs...">
112
<input type=submit value="Go" style="border:solid white 1px;background-color:#044a64;color:white;font-size:0.9em;padding:0 1ex">
116
</div></div></div></div>
118
<div class=startsearch></div>
122
<h2>Appropriate Uses For SQLite</h2>
125
SQLite is different from most other SQL database engines in that its
126
primary design goal is to be simple:
130
<li>Simple to administer</li>
131
<li>Simple to operate</li>
132
<li>Simple to embed in a larger program</li>
133
<li>Simple to maintain and customize</li>
137
Many people like SQLite because it is small and fast. But those
138
qualities are just happy accidents.
139
Users also find that SQLite is very reliable. Reliability is
140
a consequence of simplicity. With less complication, there is
141
less to go wrong. So, yes, SQLite is small, fast, and reliable,
142
but first and foremost, SQLite strives to be simple.
146
Simplicity in a database engine can be either a strength or a
147
weakness, depending on what you are trying to do. In order to
148
achieve simplicity, SQLite has had to sacrifice other characteristics
149
that some people find useful, such as high concurrency, fine-grained
150
access control, a rich set of built-in functions, stored procedures,
151
esoteric SQL language features, XML and/or Java extensions,
152
tera- or peta-byte scalability, and so forth. If you need some of these
153
features and do not mind the added complexity that they
154
bring, then SQLite is probably not the database for you.
155
SQLite is not intended to be an enterprise database engine. It is
156
not designed to compete with Oracle or PostgreSQL.
160
The basic rule of thumb for when it is appropriate to use SQLite is
161
this: Use SQLite in situations where simplicity of administration,
162
implementation, and maintenance are more important than the countless
163
complex features that enterprise database engines provide.
164
As it turns out, situations where simplicity is the better choice
165
are more common than many people realize.
169
Another way to look at SQLite is this: SQLite is not designed
170
to replace <a href="http://www.oracle.com/database/index.html">Oracle</a>.
171
It is designed to replace <a href="http://man.he.net/man3/fopen">fopen()</a>.
174
<h2>Situations Where SQLite Works Well</h2>
178
<a name="appfileformat"></a>
180
<li><p><b>Application File Format</b></p>
183
SQLite has been used with great success as the on-disk file format
184
for desktop applications such as financial analysis tools, CAD
185
packages, record keeping programs, and so forth. The traditional
186
File/Open operation does an sqlite3_open() and executes a
187
BEGIN TRANSACTION to get exclusive access to the content. File/Save
188
does a COMMIT followed by another BEGIN TRANSACTION. The use
189
of transactions guarantees that updates to the application file are atomic,
190
durable, isolated, and consistent.
194
Temporary triggers can be added to the database to record all
195
changes into a (temporary) undo/redo log table. These changes can then
196
be played back when the user presses the Undo and Redo buttons. Using
197
this technique, an unlimited depth undo/redo implementation can be written
198
in surprisingly little code.
202
<li><p><b>Embedded devices and applications</b></p>
204
<p>Because an SQLite database requires little or no administration,
205
SQLite is a good choice for devices or services that must work
206
unattended and without human support. SQLite is a good fit for
207
use in cellphones, PDAs, set-top boxes, and/or appliances. It also
208
works well as an embedded database in downloadable consumer applications.
212
<li><p><b>Websites</b></p>
214
<p>SQLite usually will work great as the database engine for low to
215
medium traffic websites (which is to say, 99.9% of all websites).
216
The amount of web traffic that SQLite can handle depends, of course,
217
on how heavily the website uses its database. Generally
218
speaking, any site that gets fewer than 100K hits/day should work
220
The 100K hits/day figure is a conservative estimate, not a
222
SQLite has been demonstrated to work with 10 times that amount
226
<li><p><b>Replacement for <i>ad hoc</i> disk files</b></p>
229
<a href="http://man.he.net/man3/fopen">fopen()</a>,
230
<a href="http://man.he.net/man3/fread">fread()</a>, and
231
<a href="http://man.he.net/man3/fwrite">fwrite()</a> to create and
232
manage files of data in home-grown formats. SQLite works
233
particularly well as a
234
replacement for these <i>ad hoc</i> data files.</p>
237
<li><p><b>Internal or temporary databases</b></p>
240
For programs that have a lot of data that must be sifted and sorted
241
in diverse ways, it is often easier and quicker to load the data into
242
an in-memory SQLite database and use queries with joins and ORDER BY
243
clauses to extract the data in the form and order needed rather than
244
to try to code the same operations manually.
245
Using an SQL database internally in this way also gives the program
246
greater flexibility since new columns and indices can be added without
247
having to recode every query.
251
<li><p><b>Command-line dataset analysis tool</b></p>
254
Experienced SQL users can employ
255
the command-line <b>sqlite</b> program to analyze miscellaneous
256
datasets. Raw data can be imported from CSV files, then that
257
data can be sliced and diced to generate a myriad of summary
258
reports. Possible uses include website log analysis, sports
259
statistics analysis, compilation of programming metrics, and
260
analysis of experimental results.
264
You can also do the same thing with an enterprise client/server
265
database, of course. The advantages to using SQLite in this situation
266
are that SQLite is much easier to set up and the resulting database
267
is a single file that you can store on a floppy disk or flash-memory stick
268
or email to a colleague.
272
<li><p><b>Stand-in for an enterprise database during demos or testing</b></p>
275
If you are writing a client application for an enterprise database engine,
276
it makes sense to use a generic database backend that allows you to connect
277
to many different kinds of SQL database engines. It makes even better
279
go ahead and include SQLite in the mix of supported databases and to statically
280
link the SQLite engine in with the client. That way the client program
281
can be used standalone with an SQLite data file for testing or for
286
<li><p><b>Database Pedagogy</b></p>
289
Because it is simple to setup and use (installation is trivial: just
290
copy the <b>sqlite</b> or <b>sqlite.exe</b> executable to the target machine
291
and run it) SQLite makes a good database engine for use in teaching SQL.
292
Students can easily create as many databases as they like and can
293
email databases to the instructor for comments or grading. For more
294
advanced students who are interested in studying how an RDBMS is
295
implemented, the modular and well-commented and documented SQLite code
296
can serve as a good basis. This is not to say that SQLite is an accurate
297
model of how other database engines are implemented, but rather a student who
298
understands how SQLite works can more quickly comprehend the operational
299
principles of other systems.
303
<li><p><b>Experimental SQL language extensions</b></p>
305
<p>The simple, modular design of SQLite makes it a good platform for
306
prototyping new, experimental database language features or ideas.
313
<h2>Situations Where Another RDBMS May Work Better</h2>
316
<li><p><b>Client/Server Applications</b><p>
318
<p>If you have many client programs accessing a common database
319
over a network, you should consider using a client/server database
320
engine instead of SQLite. SQLite will work over a network filesystem,
321
but because of the latency associated with most network filesystems,
322
performance will not be great. Also, the file locking logic of
323
many network filesystems implementation contains bugs (on both Unix
324
and Windows). If file locking does not work like it should,
325
it might be possible for two or more client programs to modify the
326
same part of the same database at the same time, resulting in
327
database corruption. Because this problem results from bugs in
328
the underlying filesystem implementation, there is nothing SQLite
329
can do to prevent it.</p>
331
<p>A good rule of thumb is that you should avoid using SQLite
332
in situations where the same database will be accessed simultaneously
333
from many computers over a network filesystem.</p>
336
<li><p><b>High-volume Websites</b></p>
338
<p>SQLite will normally work fine as the database backend to a website.
339
But if you website is so busy that you are thinking of splitting the
340
database component off onto a separate machine, then you should
341
definitely consider using an enterprise-class client/server database
342
engine instead of SQLite.</p>
345
<li><p><b>Very large datasets</b></p>
347
<p>With the default page size of 1024 bytes, an SQLite database is
348
limited in size to 2 terabytes (2<sup><small>41</small></sup> bytes).
349
And even if it could handle larger databases, SQLite stores the entire
350
database in a single disk file and many filesystems limit the maximum
351
size of files to something less than this. So if you are contemplating
352
databases of this magnitude, you would do well to consider using a
353
client/server database engine that spreads its content across multiple
354
disk files, and perhaps across multiple volumes.
358
<li><p><b>High Concurrency</b></p>
361
SQLite uses reader/writer locks on the entire database file. That means
362
if any process is reading from any part of the database, all other
363
processes are prevented from writing any other part of the database.
364
Similarly, if any one process is writing to the database,
365
all other processes are prevented from reading any other part of the
367
For many situations, this is not a problem. Each application
368
does its database work quickly and moves on, and no lock lasts for more
369
than a few dozen milliseconds. But there are some applications that require
370
more concurrency, and those applications may need to seek a different