SQLite in Production - Master Course

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

  • @gavranhas
    @gavranhas6 күн бұрын

    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

    5 күн бұрын

    Exactly! It just works. I am happy you like it :) I'll soon make a new video about advanced SQLite settings. So stay tuned ;)

  • @thomasborg4442
    @thomasborg4442Ай бұрын

    I love simplicity. Simplicity makes me sane in this crazy complicated framework upon framework world

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    I feel ya mate. This is one way to implement that :)

  • @steffengroenandersen
    @steffengroenandersenАй бұрын

    4:05 - Champagne problem - love that expression!

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thanks! Just learned it like a few weeks ago. You learn every day

  • @kavuthaaaaaaaaa
    @kavuthaaaaaaaaaАй бұрын

    Nice!!

  • @kristinakristina6426
    @kristinakristina6426Ай бұрын

    thanks for the great video👍

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thank you!

  • @steffengroenandersen
    @steffengroenandersenАй бұрын

    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

    Ай бұрын

    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

    Ай бұрын

    @@MartinBaun I am already watching more videos about setting up and using SQLlite! :)

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    @@steffengroenandersen Awesome, just write if you have any issues :)

  • @ahmedkhalaf6682
    @ahmedkhalaf6682Ай бұрын

    That's Great My friend

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thank you friend, always happy to educate :)

  • @PinnedBeats
    @PinnedBeatsАй бұрын

    Love such a compact course

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thank you friend!

  • @AnastasiiaSyrykh
    @AnastasiiaSyrykhАй бұрын

    💪💪

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thank you!

  • @juliababiiugc
    @juliababiiugcАй бұрын

    🔥

  • @MartinBaun

    @MartinBaun

    Ай бұрын

    Thanks!

  • @jsantos1220
    @jsantos1220Ай бұрын

    It would be amazing to see a video setting up the cron job for the backups man, nice job

  • @bororobo3805

    @bororobo3805

    Ай бұрын

    I think a bash script is fine, maybe with compression and some sorry of everything encryption

  • @Qwonk
    @Qwonk4 күн бұрын

    But it’s more fun to create some unmaintanable monstrosity

  • @MartinBaun

    @MartinBaun

    3 күн бұрын

    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?