News for hackers. Stuff that matters.
Re:We’re pretty happy with SQLite and not urgently intereste... by StavrosK on Sunday June 19, 2016 @06:40PM (#11935062)
What are the limitations? I love SQLite, and have vaguely heard that it has issues with concurrency, but what, exactly? I use it on production for www.tithess.gr and it seems to be working beautifully, no concurrency problems whatsoever there.

What problems should I be expecting in a multi-access scenario? I've never had that question answered adequately.

Re:We’re pretty happy with SQLite and not urgently intereste... by zackelan on Sunday June 19, 2016 @06:54PM (#11935124)
Only one process can have a SQLite database file open for writes at a time. Multiple processes/threads can read, however.

That's about it. I'm hesitant to describe it as an "issue" with concurrency because that has connotations that it's a problem with SQLite that the authors should address. Rather, it's part of the simplicity that is a key design feature of SQLite.

As SQLite's own documentation[0] says, it doesn't compete with client/server databases like Oracle/Postgres/MySQL - it competes with fopen() (edit: not a system call, see below), hand-maintained serialization/pickling formats, etc.

0: https://www.sqlite.org/whentouse.html

Re:We’re pretty happy with SQLite and not urgently intereste... by asveikau on Sunday June 19, 2016 @07:59PM (#11935369)
> it competes with the fopen() system call

Nitpick: fopen() is not a syscall, it's part of stdio which is in libc (in user mode). The nearest POSIX syscall equivalent is open(2), but stdio does things like buffering and formatting in user mode on top. It's also more portable to non-Unix because stdio is in the C language spec.

I had heard this phrase before as simply "it competes with fopen()".

Re:We’re pretty happy with SQLite and not urgently intereste... by petercooper on Sunday June 19, 2016 @06:50PM (#11935108)
Andrew has already spoken to the single writer matter. Another issue is it's not very easy to scale horizontally at all. You could shard, but you're not going to be doing replication very easily (although a project does exist to provide replicated SQLite - https://github.com/rqlite/rqlite - but then you might as well finally use Postgres or whatever).

My attitude to this is if my project can be working well and turning a profit within SQLite's limitations, we can worry about migrating to a different stack later on. The same reason I use Ruby for almost everything initially too.

Re:We’re pretty happy with SQLite and not urgently intereste... by c-smile on Sunday June 19, 2016 @08:13PM (#11935406)
Consider multi-user wordpress site for example. You can have one SQLite DB per user - there is simply no information to share between users. If so you can split all your users between multiple backend machines and do per user request routing - like one machine serving users from A to F. SQLlite has cheap DB loading sequence so you can open/close it for each page request. That would be perfect horizontal scaling as all your users will not fight for single DB access.
Re:We’re pretty happy with SQLite and not urgently intereste... by mewm on Sunday June 19, 2016 @08:24PM (#11935436)
well, you kinda just move the problem to another layer. You'll face same horizontal scaling issues once you need to scale on each user.
Re:We’re pretty happy with SQLite and not urgently intereste... by c-smile on Sunday June 19, 2016 @09:06PM (#11935548)
Or just remove one [DB] layer completely. Such databases can be stored directly on machines executing http requests. And if you need to rebuild DB structure you don't need to stop the world - do them one by one.

Of course, all this depends on amount of data you need to store for each user and informational structure of the app.

Re:We’re pretty happy with SQLite and not urgently intereste... by andrewguenther on Sunday June 19, 2016 @06:45PM (#11935084)
You cannot have multiple writers to a SQLite database. Only a single file descriptor may be open with 'write' access. As long as you can get the performance you need out of a single writer, then you're good!
Re:We’re pretty happy with SQLite and not urgently intereste... by SQLite on Sunday June 19, 2016 @09:52PM (#11935655)
Clarification: You can have multiple connections (aka file descriptors) open on the same database file for writing at the same time. But only one can be actively writing at a time. SQLite uses file locking to serialize writes. Multiple writers can exist concurrently, they merely have to take turns writing.
Re:We’re pretty happy with SQLite and not urgently intereste... by marktangotango on Sunday June 19, 2016 @09:35PM (#11935612)
WAL allows multiple readers and writers:

https://www.sqlite.org/isolation.html

Re:We’re pretty happy with SQLite and not urgently intereste... by c-smile on Sunday June 19, 2016 @09:20PM (#11935580)
Yes, but in some cases it could be faster to work in sole- writer mode. It is kind of cooperative multitasking demonstrating by Node.js.
Re:We’re pretty happy with SQLite and not urgently intereste... by keeperofdakeys on Sunday June 19, 2016 @11:53PM (#11935960)
I thought sqlite didn't allow any readers while a write was in progress, but apparently that is no longer the case https://www.sqlite.org/wal.html
Re:We’re pretty happy with SQLite and not urgently intereste... by Svenstaro on Sunday June 19, 2016 @07:14PM (#11935195)
It only supports a subset of ALTER TABLE and the work around for the limitations is very annoying: https://www.sqlite.org/lang_altertable.html
Re:We’re pretty happy with SQLite and not urgently intereste... by tedmiston on Sunday June 19, 2016 @09:09PM (#11935556)
I've run into this issue before with Django's automatically generated migrations breaking in SQLite. As a workaround, I rm my local test db or make the change myself.
Re:We’re pretty happy with SQLite and not urgently intereste... by zmmmmm on Sunday June 19, 2016 @08:29PM (#11935449)
The worst thing that I experienced was actually the lack of basic support for routine schema alterations that you find in other DMBS's. I don't have time to recall exactly but relatively mundane things like altering the names or data types of columns required basically dropping and rebuilding the columns / tables from scratch. It really made the ongoing maintenance quite painful compared to other DBMS's.
Re:We’re pretty happy with SQLite and not urgently intereste... by omarforgotpwd on Sunday June 19, 2016 @06:52PM (#11935117)
Your entire database is in one file, so you can only write from one process at a time. You can read from multiple processes at a time though.
Re:We’re pretty happy with SQLite and not urgently intereste... by viraptor on Sunday June 19, 2016 @07:41PM (#11935310)
From other limitations there can be the aspect of security. If you have a more complex application / set of applications you may want to use different database users for different purposes. Maybe some audit / append-only tables as well.

With sqlite whoever controls the app can do whatever they want with the database file.