I am a data scientist. I use a bunch of datasets that are mostly read only and infrequently used I found that the simplicity and flexibility of sqlite is a lot better for me than using something like postgresql.
I think it was SQLite's author who was saying that there is a misunderstanding about his lib. It is not a competitor to DBs like MySQL or postgres, it is a competitor to open(...) and file IO.
SQLite is not a database, it is a lib to do SQL requests to a local file.
DBs handle concurrency and this is their main feature and their main problem. SQLite does not handle it and does not care. And neither should you if you only have one user at the time.
This is a great call-out and fits with how I understand SQLite. It's a wrapper over a file that just so happens to be a SQL interface. Glad to hear it's not far off from the intent of the lib!
SQLite allows multiple processes safely write to the database (provided file locking works properly) and it provides atomic transactions using journaling, allowing for process crash resilience, so it's pretty much a database - not just "a lib to do SQL requests to a local file". What it lacks is the ability to be a distributed database. Backups, synchronization and failovers are on you
Q: Can multiple applications or multiple instances of the same application access a single database file at the same time?
A: Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.
SQLite uses reader/writer locks to control access to the database.
...
However, client/server database engines (such as PostgreSQL, MySQL, or Oracle) usually support a higher level of concurrency and allow multiple processes to be writing to the same database at the same time. This is possible in a client/server database because there is always a single well-controlled server process available to coordinate access. If your application has a need for a lot of concurrency, then you should consider using a client/server database. But experience suggests that most applications need much less concurrency than their designers imagine.
They also have WAL-mode, which allows really fast operation when there's many concurrent readers and writers. Orders of magnitude faster than fopen() with manual locking.
I do believe that is the case and for a long time I was naively trying to use postgresql for one of my large datasets, it was a pain to setup and almost every time I was going to use it postgres had updated and nothing was working properly, it was also a pain to backup and restore.
I finally resolved to just use sqlite and break the database up in different files depending on years and that basically solved all my problems.
What problems did you face setting up PSQL? I run it in a few production systems with a basic setup and has no problem running some few thousand concurrent users.
It was mostly because I used only sporadic, so I forgot about all the psql commands when I was back to it and I didn't do the proper maintanaince. I use arch so by the time I went back to postgres arch had updated it and it was imcompatible with my dataset, I had to then downgrade postgres and/or dump and restore it.
It was my fault, I did things I shouldn't have done. But it was because I wasn't in it to have a proper database server all I really wanted was a database to do sporadic select queries.
Firefox uses the same approach. They make hundreds/thousands of slqlite databases in the user's directory. Every site's persistent data is stored in an sqlite database. They have separate databases for cookies, bookmarks, preferences, navigation history, form history, etc.
Pretty much my goto unless I know something will have a-lot of concurrent users. Works really well for a sales-estimation app I’ve made for work since I don’t have the bother of dealing with IT just put the file on a shared drive and alls good. Also works great for data logging for industrial applications, used in a few SCADA projects.
Simple we have like 3 engineers, normally only one is estimating at a time 😂 GO and my setup makes it fairly trivial to migrate the DB to something like postgres if it becomes an issue.
DuckDB is insanely good. To me, they've ticked all the checkboxes for what makes a piece of software great. Self-contained, smart design choices, great language bindings, and zero fluff.
A lot of it feels like magic, and part of that magic is in the fact there's no bloat and no added complexity to the stack. I actually have had legitimate use cases for extremely wide tables (bioinformatics at scale, you have like 60k genes in rows and an arbitrarily large number of datasets and samples in columns) and DuckDB chews through it like a champ. And no need to think about your indexing strategy! Well, I guess almost no need—it does support explicit indexing—but for the vast majority of cases it "just works."
They also hit 1.0 recently, I can't name a reason not to use it.
So really it's just column store instead of row store. So if you're doing aggregates over lots of data DuckDB will win but if you're trying to pluck individual rows (like finding a customer record) you'll find that SQLite wins.
So is it good to have both available in your enterprise? I can imagine plenty of scenarios where I would want the two pretty interchanging depending on what queries I'm throwing at it?
I'm sure the response will be, "they can both do that thing but one works better for the other scenario than the other one"
So my question is: Is this beyond simple configuration inside the program itself?
I feel like I'm not asking the right question(s) but hopefully you can parse what I'm trying to ask
SQL database workloads are often divided in two categories, OLTP and OLAP.
OLTP:
Online Transactional Processing.
Fast atomic changes of records, for example INSERT/UPDATE/MERGE the value for specific primary keys.
This is the main orientation of traditional databases like MySQL, PostgreSQL and SQLite.
They are mainly designed for single machine and rely on indexes for optimization.
This is the typical design adapted to handling a payment service transactions.
OLAP:
Online Analytical Processing.
Long running queries performing aggregations over a large number of rows, for example COUNT GROUP BY.
This is the typical use case for data analytics. For example: how many new paying users today?
This the main orientation of distributed SQL databases, historically the Hadoop ecosystem, now all kinds of cloud SQL like Amazon Redshift and Google BigQuery and more.
Optimization is generally more complex, there's Hive style partitioning, clustering/bucketing, columnar file formats and other details specific to the tools. That's an important part of the job of data engineers.
Until DuckDB, having a proper OLAP database meant using those distributed tools that are either hard to deploy like Hadoop or expensive like cloud SQL, similarly to the situation for small OLTP workloads before SQLite when you had to bother with deploying a proper database to use SQL.
Now DuckDB provides you a great in-process solution for OLAP workloads. It is not distributed, but it has the other optimizations that were made for OLAP, so if your need is not huge, it should work. Additionally, a single machine processing power has increased a lot since when Hadoop was designed 15 years ago, so workloads that used to require Hadoop at this time can probably run fine on DuckDB on a beefy VM for a fraction of the complexity of Hadoop. This last point is described in this DuckDB blog: https://motherduck.com/blog/big-data-is-dead/.
P.S.: Since Hadoop, there's continuous work to close the gap between OLTP and OLAP. OLAP solutions are getting more OLTP features like transaction isolation (Apache Hive ACID) and UPDATE/MERGE capacities (Apache Iceberg). There are also databases providing both engines at the same time. I guess than in the future, you will not have to bother with this choice anymore and the database automatic optimizer will make the smart choices for you like it already does for SQL execution plans.
255
u/Apoema Sep 10 '24 edited Sep 10 '24
I am a data scientist. I use a bunch of datasets that are mostly read only and infrequently used I found that the simplicity and flexibility of sqlite is a lot better for me than using something like postgresql.