SQLite in Production - Master Course

  Рет қаралды 3,467

Martin Baun

Martin Baun

Күн бұрын

SQLite is Enough video here: • SQLite is enough
------
SQLite is perfect for production of most websites
And here I’ll show how to run SQLite in production
It is short video
as there are not much to learn
with sqlite
We’ll also see why it is possible
and why you want to do so
Let’s get to it
Why?
Why would you use SQLite in production?
In short:
Simple and easy
That makes it robust
Extremely fast as there’s no server
If you’re not convinced
then checkout my video called “SQLite is enough”
You can find that in the description
Configuration
SQLite is a so called zero-configuration database
and that’s mostly true
Now, I’d like to highlight 3 configurations that you should probably do
1. journal mode
You probably want to configure SQLite to use
the journal mode WAL = Write Ahead Log
You do this by
PRAGMA journal_mode = wal;
and you only need to do this once
What this does is it sacrifices a little bit of atomicity for a shit tonnes performance.
I always put this on.
I also heard there’s a new wal2
but I have no experience with this
But you should probably take a look at that
2. Foreigns keys
In Sqlite3 the foreign keys are not enforced by default
You can do this by using
PRAGMA foreign_keys = ON;
This have a small effect on performance,
but you should probably do it.
Now I haven’t done it,
and I already shot myself in the foot a few times because of
I will do that in the next project
3. Strict table
Sqlite forgives you if you do weird shit
Such as inserting string into a int
Now that’s usually not a good idea
and since version 3.37
you can now make a table strict by adding prepending “strict” when creating a table
CREATE TABLE Goleko(age INTEGER) STRICT;
Now I haven’t done this as well
and again
I shot myself in the foot a few times
So I’ll probably do this in my next projects
Intersting opportunities as files
Your sqlite database is just a file
and it gives interesting opportunities to play around
Let’s say you make a system that have have organizations
Then you could have a database for each organization.
Futuremore, you could distribute those databases to an region
Making it easier to be GDPR compliant and improve latency for the users
You can also very easily just copy the prod db to testing environments
Indices / indexes
Indexes are some of the most important things in databases
not only in traditional databases,
but also in sqlite.
So, if your database is slow
checkout how to do indexes
as they will greatly improve performance
Performance consideration
You don’t need to worry that much about performance of SQLite databases
For most cases,
if you put write ahead logging on it is good enough
However, if you’re in a write heavy environment you might need to do
connection pooling as writes are serialized.
Now, this is the champagne problem,
and so be happy when you are gifted that problem
Example PocketBase uses SQLite and boast a 10k connection on just a 4 euro Hetnzer machine
That’s enough for 95% of the websites out there.
So don’t worry about it until it becomes a problem
Backup Cavets
Backing up a sqlite database is extremely simple.
Now, you can just copy the file of the database
but in some rare cases that might corrupt some data
It is better to run the
.dump
you can do this by having a cronjob just doing
`sqlite3 yourdatabase.db “.dump" mybackup.sql`
There’s also newer solution such as litestream
but again I like to be conservative
and dumping works well.

Пікірлер: 32
@thomasborg4442
@thomasborg4442 2 ай бұрын
I love simplicity. Simplicity makes me sane in this crazy complicated framework upon framework world
@MartinBaun
@MartinBaun 2 ай бұрын
I feel ya mate. This is one way to implement that :)
@gavranhas
@gavranhas 11 күн бұрын
I'm using it in production right now in a Rails app and it is just working. Fine. Your master course has covered everything that is need to have SQLite working in production. And that is it. Simple. Robust. Stable. Cheap. OpenSource. Battle-tested.
@MartinBaun
@MartinBaun 10 күн бұрын
Exactly! It just works. I am happy you like it :) I'll soon make a new video about advanced SQLite settings. So stay tuned ;)
@steffengroenandersen
@steffengroenandersen 2 ай бұрын
4:05 - Champagne problem - love that expression!
@MartinBaun
@MartinBaun 2 ай бұрын
Thanks! Just learned it like a few weeks ago. You learn every day
@steffengroenandersen
@steffengroenandersen 2 ай бұрын
Interesting topic! I still remember that you recommended SQLite to me before going abroad. I just had a class focusing on SQLite in Node and your comments definitely made me pay more attention! :)
@MartinBaun
@MartinBaun 2 ай бұрын
Awesome! It is so easy and for most things you wont need any fancy things. Just keep it simple. Focus on your product and enjoy life :)
@steffengroenandersen
@steffengroenandersen 2 ай бұрын
@@MartinBaun I am already watching more videos about setting up and using SQLlite! :)
@MartinBaun
@MartinBaun 2 ай бұрын
@@steffengroenandersen Awesome, just write if you have any issues :)
@kavuthaaaaaaaaa
@kavuthaaaaaaaaa 2 ай бұрын
Nice!!
@ahmedkhalaf6682
@ahmedkhalaf6682 2 ай бұрын
That's Great My friend
@MartinBaun
@MartinBaun 2 ай бұрын
Thank you friend, always happy to educate :)
@kristinakristina6426
@kristinakristina6426 2 ай бұрын
thanks for the great video👍
@MartinBaun
@MartinBaun 2 ай бұрын
Thank you!
@AnastasiiaSyrykh
@AnastasiiaSyrykh 2 ай бұрын
💪💪
@MartinBaun
@MartinBaun 2 ай бұрын
Thank you!
@juliababiiugc
@juliababiiugc 2 ай бұрын
🔥
@MartinBaun
@MartinBaun 2 ай бұрын
Thanks!
@PinnedBeats
@PinnedBeats 2 ай бұрын
Love such a compact course
@MartinBaun
@MartinBaun 2 ай бұрын
Thank you friend!
@jsantos1220
@jsantos1220 2 ай бұрын
It would be amazing to see a video setting up the cron job for the backups man, nice job
@bororobo3805
@bororobo3805 2 ай бұрын
I think a bash script is fine, maybe with compression and some sorry of everything encryption
@Qwonk
@Qwonk 9 күн бұрын
But it’s more fun to create some unmaintanable monstrosity
@MartinBaun
@MartinBaun 9 күн бұрын
I think it is as well, and I think it is more productive. What I do when I code something new is to treat it as a prototype and just play around. It becomes a mess. Then I spend a few iterations cleaning it up to a suitable level. So you get your fun, it's productive and you get more maintainable code in the end
@otisrancko
@otisrancko Ай бұрын
Also LibSQL by Turso!!!
@MartinBaun
@MartinBaun Ай бұрын
Tell me more Otis :) Why would you choose this over SQLite
@otisrancko
@otisrancko Ай бұрын
@@MartinBaun It builds upon the SQLite technology so we get benefits of both worlds...🤔
@MartinBaun
@MartinBaun Ай бұрын
@@otisrancko I read that but what are the benefits of old-school sqlite?
@otisrancko
@otisrancko Ай бұрын
@@MartinBaun Having a server on top of the sqlite instance and easy replication to other regions are the benefits and alot more...
@MartinBaun
@MartinBaun Ай бұрын
@@otisrancko ah yeah, but aren't we just recreating psql then? why not just use PSQL then?
DjangoCon Europe 2023 | Use SQLite in production
29:45
DjangoCon Europe
Рет қаралды 8 М.
Is SQLite ready for production workloads?
2:01
Changelog
Рет қаралды 2,6 М.
Каха ограбил банк
01:00
К-Media
Рет қаралды 10 МЛН
David Crawshaw   SQLite and Go
32:03
Go Northwest
Рет қаралды 35 М.
15 futuristic databases you’ve never heard of
8:42
Fireship
Рет қаралды 650 М.
SQLite Uses ByteCode (And For Good Reason)
19:07
ThePrimeTime
Рет қаралды 83 М.
Why I Quit the Scrum Alliance
7:58
The Passionate Programmer
Рет қаралды 9 М.
We Don't Need Migrations Anymore
6:21
Theo - t3․gg
Рет қаралды 57 М.
SQLite for beginners: JSON
6:44
Mycelial
Рет қаралды 6 М.
Why Great Developers DON'T Create Content (and a lesson to learn)
6:56
Cloudflare is DEAD - use this instead
4:50
Martin Baun
Рет қаралды 2,3 М.
Syncing SQLite and Postgres?
24:14
Underjord
Рет қаралды 8 М.