TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

We’re pretty happy with SQLite and not urgently interested in a fancier DBMS

397 pointsby sampsalmost 9 years ago

28 comments

SwellJoealmost 9 years ago
I never stop being impressed at how often people will jump to odd, unsupportable, conclusions like, &quot;using MySQL will make this thing faster&quot;.<p>I&#x27;ve seen it so many times over the years regarding users and email configurations. I can&#x27;t count the number of times I&#x27;ve dropped into someone&#x27;s badly behaving mail configuration and found they had MySQL hosting the users, and explained it was for &quot;performance&quot; reasons. Somehow they didn&#x27;t grasp that &#x2F;etc&#x2F;passwd fits entirely in memory, and the map files Postfix uses for various lookups and stuff are already a database (just one specifically designed for the task at hand) and also fit entirely in memory. Putting that MySQL layer in there is <i>disastrous</i> if performance matters; it is orders of magnitude slower for any case I&#x27;ve seen...still plenty fast for most cases, but it&#x27;s ridiculous that this idea gets cargo-culted around that if you store your mail users in MySQL your mail server will be faster.<p>A little knowledge is a dangerous thing, is what I&#x27;m trying to say, and people who know MySQL is &quot;fast&quot; may not know enough to know that it&#x27;s not the right tool for the job in a lot of cases...and is probably <i>slower</i> for many use cases. I&#x27;m pretty confident this is one of those cases. SQLite is wicked fast on small data sets, and being smaller means more of it will fit in memory; I can&#x27;t think of any way MySQL could be a more performant choice for this workload.<p>Also, I don&#x27;t even want to try to imagine shipping an installable desktop application for non-technical users that relies on MySQL!
评论 #11935430 未加载
评论 #11936279 未加载
评论 #11935702 未加载
评论 #11935940 未加载
评论 #11935872 未加载
评论 #11936920 未加载
评论 #11936532 未加载
评论 #11936487 未加载
Annataralmost 9 years ago
Wow, the article is such a fresh breath of air, primarily because the author demonstrates common sense.<p>He (they?) picked SQLite for all the correct reasons:<p>- best tool for the job for their situation;<p>- write-light and read-heavy;<p>- zero configuration;<p>- easy to embed;<p>- understanding that optimizing queries by far gives the best performance in the shortest amount of time.<p>As an aside, I&#x27;m currently using SQLite for Bacula and Postfix, and it&#x27;s a joy to use; the only drawback I found so far is lack of REGEXP REPLACE in the SQL dialect which the database supports (must be loaded with .load &#x2F;path&#x2F;to&#x2F;lib&#x2F;libpcre.so, but it is not part of the language). I used the Oracle RDBMS for my PowerDNS deployments, but in retrospect, the way PowerDNS works, SQLite would have been an even better match. All in all, it is great to read that someone picked it for all the correct reasons, rather than some fashion trend, as is often the case in computer industry.
chjjalmost 9 years ago
Premature optimization is evil, but <i>preemptive</i> optimization is necessary unless you want to paint yourself into a corner. I realized this after implementing a bitcoin full node.<p>In my bitcoin implementation, as an experiment, I tried storing the blockchain in sqlite, postgres, and leveldb. I gathered up a bunch of data from the first ~200k blocks of the blockchain and benchmarked all three databases. I queried for something like 30,000 utxos out of a set of a couple million. What took 300-400ms in leveldb took 1.6 seconds in postgres (on the repl. in my actual node it would have taken longer due to deserialization of the utxos). What took 1.6 seconds in postgres took over <i>30 seconds</i> in SQlite.<p>Now, you can tell me I did the benchmarks wrong, and &quot;oh, if you just did this it would be faster!&quot;, but 30+ seconds is slower to an absolutely insane level. Needless to say, I went the key-value store route, but I was still astounded at how slow sqlite was once it got a few million records in the database.<p>I actually like sqlite, but when you know you&#x27;re going to be dealing with 70gb of data and over 10 million records, preemptive optimization is the key. If I were the author, I would consider switching to postgres if there are over 500k-1m records to be expected. That being said, if they&#x27;re partial to sqlite, SQLightning (<a href="https:&#x2F;&#x2F;github.com&#x2F;LMDB&#x2F;sqlightning" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;LMDB&#x2F;sqlightning</a>) looks pretty interesting (SQLite with an LMDB backend).<p>edit: To clarify, these weren&#x27;t particularly scientific benchmarks. This was me timing a very specific query to get an idea of the level of data management I was up against. Don&#x27;t take my word for it.
评论 #11935421 未加载
评论 #11935460 未加载
评论 #11935464 未加载
评论 #11935419 未加载
评论 #11935510 未加载
int_19halmost 9 years ago
While we&#x27;re speaking of SQLite; one thing that has little exposure that could probably use more is that it now ships with Windows as a system DLL:<p><a href="https:&#x2F;&#x2F;engineering.microsoft.com&#x2F;2015&#x2F;10&#x2F;29&#x2F;sqlite-in-windows-10&#x2F;" rel="nofollow">https:&#x2F;&#x2F;engineering.microsoft.com&#x2F;2015&#x2F;10&#x2F;29&#x2F;sqlite-in-windo...</a><p>Between that, and packages readily available on most Linux and BSD distros out there (and, in most cases, installed by default), it&#x27;s well on its way to become a de facto standard system API for relational storage.
评论 #11936787 未加载
c-smilealmost 9 years ago
If to speak about desktop applications then any embedded DB will be unbeatable.<p>So I am speaking about embeddable DBs here.<p>Konstantin Knizhnik have implemented impressive set of various embedded DBs: <a href="http:&#x2F;&#x2F;garret.ru&#x2F;databases.html" rel="nofollow">http:&#x2F;&#x2F;garret.ru&#x2F;databases.html</a><p>Like his POST++ has direct mapping to C++ classes so if you use C++ then you don&#x27;t need any ORM.<p>In my Sciter[1] Engine I am using his DyBase library [3] as a bult-in persistence for Sciter&#x27;s script [2] (JavaScript++).<p>With the DyBase in script you have features similar to MongoDB (noSQL free-form DB) but without any need for ORM and DAL - you can declare some root object as be persistable and access those data trees as if they are JavaScript objects. The engine pumps objects from DB into memory when they are needed:<p><pre><code> var storage = Storage.open(...); var dataRoot = storage.root; &#x2F;&#x2F; all things inside are persitable dataRoot.topics = []; &#x2F;&#x2F; flat persistable list dataRoot.topics.push({ foo:1, bar:2 }); &#x2F;&#x2F; storing object &#x2F;* create indexed collection with string keys, keys can be unique or not *&#x2F; dataRoot.titles = storage.createIndex(#string); </code></pre> DyBase has Python bindings too.<p>[1] <a href="http:&#x2F;&#x2F;sciter.com" rel="nofollow">http:&#x2F;&#x2F;sciter.com</a> - multiplatform HTML&#x2F;CSS UI Engine for Desktop and Mobile Application<p>[2] TIScript - <a href="http:&#x2F;&#x2F;www.codeproject.com&#x2F;Articles&#x2F;33662&#x2F;TIScript-Language-A-Gentle-Extension-of-JavaScript" rel="nofollow">http:&#x2F;&#x2F;www.codeproject.com&#x2F;Articles&#x2F;33662&#x2F;TIScript-Language-...</a><p>[3] DyBase - <a href="http:&#x2F;&#x2F;www.garret.ru&#x2F;dybase.html" rel="nofollow">http:&#x2F;&#x2F;www.garret.ru&#x2F;dybase.html</a>
niftichalmost 9 years ago
I was unfamiliar with this project and assumed it was a hosted service at first. Not so, this is a local application, so an embedded database makes sense.<p>It took until the very last paragraph for the blog post to make that point.
评论 #11934996 未加载
评论 #11935001 未加载
评论 #11935038 未加载
评论 #11937844 未加载
Fenericalmost 9 years ago
SQLite also does remarkably well with recovering from all manner of power loss &#x2F; crashes &#x2F; worst case scenarios. We created a &quot;power loss&quot; rig just to test this facility for one particular system. Really SQLite&#x27;s biggest weakness is concurrency, and if your app needs that in any serious amount you probably ought to look elsewhere. If you&#x27;re just dealing with occasional concurrency though SQLite shouldn&#x27;t be dismissed out-of-hand.
评论 #11935068 未加载
评论 #11935043 未加载
评论 #11935779 未加载
omarforgotpwdalmost 9 years ago
For any database that isn&#x27;t huge, a library embedded into your application is going to be faster than anything that has to communicate with a server over a socket connection. Though both execute SQL queries, SQLite is completely different than relational database servers and appropriate many places where running a full RDBMS is not. For example, you can&#x27;t run MySQL or Postgres on the iPhone, but you can use SQLite.
评论 #11935980 未加载
chillacyalmost 9 years ago
&gt; we’re read-heavy and write-light<p>&gt; we have almost no indices, no principled denormalization<p>Sounds like an easy win. People are probably suggesting a database switch because they&#x27;re finding issues with the current speed, but they&#x27;re not using their current database to its full potential yet.
评论 #11935016 未加载
评论 #11935638 未加载
评论 #11935398 未加载
jwattealmost 9 years ago
Sqlite is fine for small scale systems. It is not a &quot;web scale&quot; database, but not every web site is &quot;web scale.&quot; SQLite does have performance limits, and will break at certain load, but until that, it&#x27;s okay. For single user databases, like desktop applications, SQLite is awesome! What the others bring to the table is concurrent sever performanc, user management, and such. There&#x27;s nothing surprising about this, right?
cyberferretalmost 9 years ago
I&#x27;m a long time user and lover of SQLite, since way back when. Use it in a lot of our projects (web and Win32) that require local databases for logging etc.<p>Sure for larger or concurrent user access to a db, we use other databases, but nothing beats the &#x27;zero footprint&#x27; install of SQLite. I even enjoyed the fact that earlier versions of SQLite forced me to think optimise my queries due to the lack of nested SELECTs.<p>SQLite still kind of reminds me of my early days in MySQL. I was recently trying to downgrade MySQL 5.7 to 5.6 after a slew of issues, which forced me to reminisce about how simple things used to be when MySQL was a lot like SQLite still is now...
评论 #11935180 未加载
nickysielickialmost 9 years ago
Beet is an awesome program, you should really check it out if you still are among the minority of people who actually have a music collection and don&#x27;t rent access from spotify&#x2F;itunes&#x2F;etc.<p>I&#x27;m glad to see this post; one of the reasons that I like beet so much is that everything is self-contained.
pskisfalmost 9 years ago
You&#x27;re doing it right for your application! MySQL or PostgreSQL would most probably be slower and introduce a lot more overhead as they are client&#x2F;server oriented systems. Don&#x27;t listen to those armchair architects!
oppositelockalmost 9 years ago
I don&#x27;t get the point of this article. SQLite is fine, especially in an embedded database, but once you have concurrent access, it starts to suffer because it has very coarse grained locks, so a &quot;real&quot; database is better for a distributed single-DB design. It&#x27;s more about using the right tool for the job, and the author seems to be talking himself out of some kind of guilt for SQLite being the right tool for him.
评论 #11935541 未加载
jedbergalmost 9 years ago
I can&#x27;t blame them. I&#x27;ve been a huge fan of SQLite for years. Anytime I need storage it&#x27;s my default choice unless there is a specific reason to use something else.<p>Another nice advantage of it is if you are distributing something that requires a small dataset[0][1]. If I give you both the code and the data already imported into a sqlite database, then you can use the code right away, or you can dump the data to a different database very easily.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;jedberg&#x2F;wordgen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jedberg&#x2F;wordgen</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;jedberg&#x2F;Postcodes" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jedberg&#x2F;Postcodes</a>
zapharalmost 9 years ago
What people actually seriously suggest that a desktop application needs more than sqlite offers in the way of databases?<p>Desktop apps are like the sweet spot for sqlite. It&#x27;s practically made for them.
qwertyuiop924almost 9 years ago
Suggesting you add a server dependancy to your desktop app as a solution to a problem that isn&#x27;t there is pretty braindead.
tedmistonalmost 9 years ago
I have used SQLite for similar use cases, but occasionally it&#x27;s led to a corrupted db. I had a cron task writing to it once a day, but an issue with the scheduler led to 2 tasks one day with the latter one finishing before the former.<p>Of course I can add locking or something in my code, but I&#x27;d prefer to handle at a lower level — for example, have SQLite take the latest write without corrupting. I&#x27;m hoping someone has solved this problem with SQLite elegantly.
评论 #11935088 未加载
评论 #11936684 未加载
franciscopalmost 9 years ago
I didn&#x27;t know beet, but it looks exactly like what I&#x27;ve been wanting for years.
partycoderalmost 9 years ago
Even a file can be convenient. It&#x27;s all about how you integrate it into the system.
kefka_palmost 9 years ago
Some people are unfamiliar with the phrase &quot;right tool for the job&quot;.<p>As the developers behind the project, I&#x27;d have to think the authors are in the best position to make the determination about which tool is appropriate.
评论 #11935826 未加载
therealdrag0almost 9 years ago
For everyone loving SQLite, you should consider donating to them. I remember a post this last year about the maintainers working on it full time, but making much less than most of us probably do.
ww520almost 9 years ago
I wish HTML5 storage standardized on Sqlite. The inconsistent story on HTML5 storage across browsers is kind of sad.
评论 #11935755 未加载
评论 #11935617 未加载
chmikealmost 9 years ago
SQLite is Ok, but write access must be synchronized. I used it for my Flask (Python) application and was forced to switch to PostgreSQL because of synchronization problems. I would prefer sticking with SQLite which was simpler to manage.<p>The author doesn&#x27;t say a word about synchronization when writing to SQLite.
评论 #11937347 未加载
Ultimattalmost 9 years ago
The bigger news here is they arent using an ORM to make moving between databases trivial.
knownalmost 9 years ago
Firefox uses SQLite
_pgmfalmost 9 years ago
Classic HN bait.<p>You don&#x27;t even need to read the comments to know what people will say:<p>&quot;SQLite is a great fit for this type of application. It&#x27;s a replacement for fopen people. fopen.&quot;<p>&quot;What about ALTER TABLE?&quot;<p>&quot;It&#x27;s just a toy database, it doesn&#x27;t even support concurrent writers&quot;<p>----- &quot;WAL mode&quot;<p>&quot;Hey, golang, rqlite&quot;<p>----- &quot;Whoa I wrote something similar for a ...&quot;<p>----- &quot;Why would you use this? Just use postgres&quot;<p>&quot;SQLite is the best database ever&quot;<p>&quot;SQLite is the worst database ever&quot;
coleiferalmost 9 years ago
I have written several &quot;Use Sqlite!&quot; posts that have made the rounds on hackernews... reading this watered down post, which is devoid of any new, surprising or usable info, it strikes me that repping SQLite has achieved meme status.<p>If you want tangible info you can actually use, read sqlites documentation. There&#x27;s a wealth of information there.<p>Here are some of posts, for the Python crowd:<p><a href="http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;five-reasons-you-should-use-sqlite-in-2016&#x2F;" rel="nofollow">http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;five-reasons-you-should-use-sq...</a><p><a href="http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;using-the-sqlite-json1-and-fts5-extensions-with-python&#x2F;" rel="nofollow">http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;using-the-sqlite-json1-and-fts...</a><p><a href="http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;my-list-of-python-and-sqlite-resources&#x2F;" rel="nofollow">http:&#x2F;&#x2F;charlesleifer.com&#x2F;blog&#x2F;my-list-of-python-and-sqlite-r...</a>